123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 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();
- /// <summary>
- /// 安装
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Button2_Click(object sender, EventArgs e)
- {
- string Strming = this.txtdianhua.Value;
- if (this.txtname.Text == "")
- {
- Response.Write("<script>alert('请输入客户名称!');</script>"); return;
- }
- if (this.txtdianhua.Value == "")
- {
- Response.Write("<script>alert('请输入联系电话!');</script>"); return;
- }
- this.anzhuang();
- }
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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("<script>alert('请输入联系人!');</script>"); return;
- }
- if (this.txtdianhua.Value == "")
- {
- Response.Write("<script>alert('请输入联系人电话!');</script>"); 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("<script>alert('添加成功!');document.location='Management.aspx';</script>");
- // this.Button2_Click(this, e);
- }
- catch
- {
- Response.Write("<script>alert('添加失败!');</script>");
- }
- 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("<script>alert('更新成功!');document.location='Management.aspx';</script>");
- }
- catch
- {
- Response.Write("<script>alert('更新失败!');</script>");
- }
- 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;
- }
- /// <summary>
- /// 安装
- /// </summary>
- 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("<script>alert('数据已经安装过,无须再安装!');</script>"); 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 + "");
- }
- }
- }
|