AddCustomer.aspx.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using MySql.Data.MySqlClient;
  9. using System.Diagnostics;
  10. using System.Collections;
  11. using System.IO;
  12. using Microsoft.Win32;
  13. using System.Data;
  14. using System.Text.RegularExpressions;
  15. using System.Web.UI.HtmlControls;
  16. using System.Configuration;
  17. namespace LYFZ.NationalMarketing
  18. {
  19. public partial class AddCustomer : System.Web.UI.Page
  20. {
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. Admin.PublicClass.chkLogin(this);
  24. if (!IsPostBack)
  25. {
  26. if (Request.QueryString["Name"] != null)
  27. {
  28. this.Panel1.Visible = true;
  29. this.txtname.ReadOnly = true;
  30. this.txtlianxi.ReadOnly = true;
  31. this.Button1.Text = "更 新";
  32. this.txtname.Text = Request.QueryString["Name"].ToString();
  33. this.txtdizhi.Text = Request.QueryString["Address"].ToString();
  34. this.txtlianxi.Text = Request.QueryString["Contacts"].ToString();
  35. this.txtdianhua.Value = Request.QueryString["Phone"].ToString();
  36. this.txtstart.Value = Request.QueryString["EffectiveTime"].ToString();
  37. this.txtbeizhu.Text = Request.QueryString["Remark"].ToString();
  38. this.txtqiantai.Text = Request.QueryString["Reception"].ToString();
  39. this.txthoutai.Text = Request.QueryString["Backstage"].ToString();
  40. }
  41. }
  42. }
  43. string StrDB = Admin.PublicClass.myDB.ToString();
  44. string Strsql = Admin.PublicClass.mysqls.ToString();
  45. string Strurl = Admin.PublicClass.myurl.ToString();
  46. /// <summary>
  47. /// 安装
  48. /// </summary>
  49. /// <param name="sender"></param>
  50. /// <param name="e"></param>
  51. protected void Button2_Click(object sender, EventArgs e)
  52. {
  53. string Strming = this.txtdianhua.Value;
  54. if (this.txtname.Text == "")
  55. {
  56. Response.Write("<script>alert('请输入客户名称!');</script>"); return;
  57. }
  58. if (this.txtdianhua.Value == "")
  59. {
  60. Response.Write("<script>alert('请输入联系电话!');</script>"); return;
  61. }
  62. this.anzhuang();
  63. }
  64. /// <summary>
  65. /// 提交
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. protected void Button1_Click(object sender, EventArgs e)
  70. {
  71. string Strhh = this.txtdianhua.Value.Trim();
  72. DateTime dt = DateTime.Now;
  73. if (this.Button1.Text == "提 交")
  74. {
  75. if (this.txtlianxi.Text == "")
  76. {
  77. Response.Write("<script>alert('请输入联系人!');</script>"); return;
  78. }
  79. if (this.txtdianhua.Value == "")
  80. {
  81. Response.Write("<script>alert('请输入联系人电话!');</script>"); return;
  82. }
  83. string cVNumber = System.IO.File.ReadAllText(Server.MapPath("~/WZYXInstall/version.txt")).Split(':')[1];
  84. 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 + "')";
  85. MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(StrDB);
  86. con.Open();
  87. try
  88. {
  89. MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(qu, con);
  90. da.ExecuteNonQuery();
  91. Response.Write("<script>alert('添加成功!');document.location='Management.aspx';</script>");
  92. // this.Button2_Click(this, e);
  93. }
  94. catch
  95. {
  96. Response.Write("<script>alert('添加失败!');</script>");
  97. }
  98. finally
  99. {
  100. con.Clone();
  101. }
  102. }
  103. else
  104. {
  105. if (Request.QueryString["id"] != null)
  106. {
  107. 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"] + "";
  108. MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(StrDB);
  109. con.Open();
  110. try
  111. {
  112. MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(sqlset, con);
  113. da.ExecuteNonQuery();
  114. Response.Write("<script>alert('更新成功!');document.location='Management.aspx';</script>");
  115. }
  116. catch
  117. {
  118. Response.Write("<script>alert('更新失败!');</script>");
  119. }
  120. finally
  121. {
  122. con.Clone();
  123. }
  124. }
  125. }
  126. }
  127. public static bool CopyFolder(string strFromPath, string strToPath)
  128. {
  129. //如果源文件夹不存在,则创建
  130. if (!Directory.Exists(strFromPath))
  131. {
  132. return false;
  133. }
  134. //取得要拷贝的文件夹名
  135. string strFolderName = strFromPath.Substring(strFromPath.LastIndexOf("\\") + 1, strFromPath.Length - strFromPath.LastIndexOf("\\") - 1);
  136. //如果目标文件夹中没有源文件夹则在目标文件夹中创建源文件夹
  137. if (!Directory.Exists(strToPath))
  138. {
  139. Directory.CreateDirectory(strToPath);
  140. }
  141. //创建数组保存源文件夹下的文件名
  142. string[] strFiles = Directory.GetFiles(strFromPath);
  143. //循环拷贝文件
  144. for (int i = 0; i < strFiles.Length; i++)
  145. {
  146. //取得拷贝的文件名,只取文件名,地址截掉。
  147. string strFileName = strFiles[i].Substring(strFiles[i].LastIndexOf("\\") + 1, strFiles[i].Length - strFiles[i].LastIndexOf("\\") - 1);
  148. //开始拷贝文件,true表示覆盖同名文件
  149. // File.Copy(strFiles[i], strToPath + "\\" + strFolderName + "\\" + strFileName, true);
  150. //开始拷贝文件,true表示覆盖同名文件
  151. File.Copy(strFiles[i], strToPath + "\\" + strFileName, true);
  152. }
  153. //创建DirectoryInfo实例
  154. DirectoryInfo dirInfo = new DirectoryInfo(strFromPath);
  155. //取得源文件夹下的所有子文件夹名称
  156. DirectoryInfo[] ZiPath = dirInfo.GetDirectories();
  157. for (int j = 0; j < ZiPath.Length; j++)
  158. {
  159. //获取所有子文件夹名
  160. string strZiPath = strFromPath + "\\" + ZiPath[j].ToString();
  161. string dirName = System.IO.Path.GetFileName(strZiPath);
  162. //把得到的子文件夹当成新的源文件夹,从头开始新一轮的拷贝
  163. CopyFolder(strZiPath, strToPath + "\\" + dirName);
  164. }
  165. return true;
  166. }
  167. /// <summary>
  168. /// 安装
  169. /// </summary>
  170. public void anzhuang()
  171. {
  172. string Strming = this.txtdianhua.Value;
  173. string qus = "CREATE DATABASE wzyx" + txtdianhua.Value + "";
  174. MySqlConnection con = new MySqlConnection(Strsql);
  175. con.Open();
  176. try
  177. {
  178. MySqlCommand da = new MySqlCommand(qus, con);
  179. da.ExecuteNonQuery();
  180. }
  181. catch
  182. { Response.Write("<script>alert('数据已经安装过,无须再安装!');</script>"); return; }
  183. finally
  184. { con.Clone(); }
  185. string srcPathS = this.Server.MapPath("~/WZYXInstall");
  186. string srcPath = this.Server.MapPath("~/wzyx" + Strming + "");
  187. CopyFolder(srcPathS, srcPath);
  188. // string Strlujing = this.Server.MapPath("~/wzyx" + Strming + "/install/lock.php");
  189. // File.Delete(Strlujing);
  190. Response.Redirect("" + Strurl + "/wzyx" + Strming + "/install/index.php?act=setconfig&dbpass=root&dbname=wzyx" + Strming + "&adminpass=" + Strming + "");
  191. }
  192. }
  193. }