using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MySql.Data.MySqlClient; using System.Diagnostics; using System.Collections; using System.IO; using Microsoft.Win32; using System.Data; using System.Text.RegularExpressions; using System.Web.UI.HtmlControls; using System.Configuration; namespace LYFZ.NationalMarketing { public partial class AddCustomer : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Admin.PublicClass.chkLogin(this); if (!IsPostBack) { if (Request.QueryString["Name"] != null) { this.Panel1.Visible = true; this.txtname.ReadOnly = true; this.txtlianxi.ReadOnly = true; this.Button1.Text = "更 新"; this.txtname.Text = Request.QueryString["Name"].ToString(); this.txtdizhi.Text = Request.QueryString["Address"].ToString(); this.txtlianxi.Text = Request.QueryString["Contacts"].ToString(); this.txtdianhua.Value = Request.QueryString["Phone"].ToString(); this.txtstart.Value = Request.QueryString["EffectiveTime"].ToString(); this.txtbeizhu.Text = Request.QueryString["Remark"].ToString(); this.txtqiantai.Text = Request.QueryString["Reception"].ToString(); this.txthoutai.Text = Request.QueryString["Backstage"].ToString(); } } } string StrDB = Admin.PublicClass.myDB.ToString(); string Strsql = Admin.PublicClass.mysqls.ToString(); string Strurl = Admin.PublicClass.myurl.ToString(); /// /// 安装 /// /// /// protected void Button2_Click(object sender, EventArgs e) { string Strming = this.txtdianhua.Value; if (this.txtname.Text == "") { Response.Write(""); return; } if (this.txtdianhua.Value == "") { Response.Write(""); return; } this.anzhuang(); } /// /// 提交 /// /// /// protected void Button1_Click(object sender, EventArgs e) { string Strhh = this.txtdianhua.Value.Trim(); DateTime dt = DateTime.Now; if (this.Button1.Text == "提 交") { if (this.txtlianxi.Text == "") { Response.Write(""); return; } if (this.txtdianhua.Value == "") { Response.Write(""); return; } string cVNumber = System.IO.File.ReadAllText(Server.MapPath("~/WZYXInstall/version.txt")).Split(':')[1]; string qu = "insert into admin(Name,Address,Contacts,Phone,Remark,RegistrationTime,EffectiveTime,Versions,Reception,Backstage,Account,Password) values('" + this.txtname.Text + "','" + this.txtdizhi.Text + "','" + this.txtlianxi.Text + "','" + this.txtdianhua.Value + "','" + this.txtbeizhu.Text + "','" + dt.Date.ToString("yyyy-MM-dd") + "','" + this.txtstart.Value + "','" + cVNumber + "','" + Strurl + "/wzyx" + Strhh + "/index.php?c=home','" + Strurl + "/wzyx" + Strhh + "/admin.php','admin','" + this.txtdianhua.Value + "')"; MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(StrDB); con.Open(); try { MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(qu, con); da.ExecuteNonQuery(); Response.Write(""); // this.Button2_Click(this, e); } catch { Response.Write(""); } finally { con.Clone(); } } else { if (Request.QueryString["id"] != null) { string sqlset = "UPDATE admin SET Name='" + this.txtname.Text + "',Address='" + this.txtdizhi.Text + "',Contacts='" + this.txtlianxi.Text + "',Phone='" + this.txtdianhua.Value + "',Remark='" + this.txtbeizhu.Text + "',EffectiveTime='" + this.txtstart.Value + "' WHERE id=" + Request.QueryString["id"] + ""; MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(StrDB); con.Open(); try { MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(sqlset, con); da.ExecuteNonQuery(); Response.Write(""); } catch { Response.Write(""); } finally { con.Clone(); } } } } public static bool CopyFolder(string strFromPath, string strToPath) { //如果源文件夹不存在,则创建 if (!Directory.Exists(strFromPath)) { return false; } //取得要拷贝的文件夹名 string strFolderName = strFromPath.Substring(strFromPath.LastIndexOf("\\") + 1, strFromPath.Length - strFromPath.LastIndexOf("\\") - 1); //如果目标文件夹中没有源文件夹则在目标文件夹中创建源文件夹 if (!Directory.Exists(strToPath)) { Directory.CreateDirectory(strToPath); } //创建数组保存源文件夹下的文件名 string[] strFiles = Directory.GetFiles(strFromPath); //循环拷贝文件 for (int i = 0; i < strFiles.Length; i++) { //取得拷贝的文件名,只取文件名,地址截掉。 string strFileName = strFiles[i].Substring(strFiles[i].LastIndexOf("\\") + 1, strFiles[i].Length - strFiles[i].LastIndexOf("\\") - 1); //开始拷贝文件,true表示覆盖同名文件 // File.Copy(strFiles[i], strToPath + "\\" + strFolderName + "\\" + strFileName, true); //开始拷贝文件,true表示覆盖同名文件 File.Copy(strFiles[i], strToPath + "\\" + strFileName, true); } //创建DirectoryInfo实例 DirectoryInfo dirInfo = new DirectoryInfo(strFromPath); //取得源文件夹下的所有子文件夹名称 DirectoryInfo[] ZiPath = dirInfo.GetDirectories(); for (int j = 0; j < ZiPath.Length; j++) { //获取所有子文件夹名 string strZiPath = strFromPath + "\\" + ZiPath[j].ToString(); string dirName = System.IO.Path.GetFileName(strZiPath); //把得到的子文件夹当成新的源文件夹,从头开始新一轮的拷贝 CopyFolder(strZiPath, strToPath + "\\" + dirName); } return true; } /// /// 安装 /// public void anzhuang() { string Strming = this.txtdianhua.Value; string qus = "CREATE DATABASE wzyx" + txtdianhua.Value + ""; MySqlConnection con = new MySqlConnection(Strsql); con.Open(); try { MySqlCommand da = new MySqlCommand(qus, con); da.ExecuteNonQuery(); } catch { Response.Write(""); return; } finally { con.Clone(); } string srcPathS = this.Server.MapPath("~/WZYXInstall"); string srcPath = this.Server.MapPath("~/wzyx" + Strming + ""); CopyFolder(srcPathS, srcPath); // string Strlujing = this.Server.MapPath("~/wzyx" + Strming + "/install/lock.php"); // File.Delete(Strlujing); Response.Redirect("" + Strurl + "/wzyx" + Strming + "/install/index.php?act=setconfig&dbpass=root&dbname=wzyx" + Strming + "&adminpass=" + Strming + ""); } } }