private void 新版本_Load(object sender, EventArgs e) { var CurrentVer = new T_UpdateTableAdapter().GetMaxVer(); txtVer.Text = Convert.ToString(CurrentVer); InitTable(); dgvFiles.DataSource = mTable; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //获取连接字符串 Common.SqlConnectionSet.SetConnStr("DBInfo.xml"); if (Common.SqlHelper.TestDB() == 0) { //检查本程序是否有更新 Version sVer = new Version(Convert.ToString(new T_UpdateTableAdapter().GetMaxVer())); Version mVer = Assembly.GetExecutingAssembly().GetName().Version; if (sVer > mVer) { System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "升级.exe"); return; } //更新本程序以外的其它文件 var mFilesTable = new T_UpdateTableAdapter().GetOtherProgramMaxVer(); foreach (DAL.DataSetT_Update.T_UpdateRow mFile in mFilesTable.Rows) { byte[] bFile; string mPath; bFile = mFile.Content; if (string.IsNullOrEmpty(mFile.Dir) == false) { mPath = AppDomain.CurrentDomain.BaseDirectory + mFile.Dir + "\\" + mFile.ProgramName; } else { mPath = AppDomain.CurrentDomain.BaseDirectory + mFile.ProgramName; } if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + mFile.Dir) == false) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + mFile.Dir); } try { using (FileStream fs = new FileStream(mPath, FileMode.Create)) { fs.Write(bFile, 0, bFile.Length); fs.Close(); } } catch (Exception) { } } Application.Run(new LoginForm1()); } else { MessageBox.Show("数据库连接失败!请重新选择数据库源"); Application.Run(new LoginForm1()); } }
private void button1_Click(object sender, EventArgs e) { T_UpdateTableAdapter adapter = new T_UpdateTableAdapter(); OpenFileDialog mDlg = new OpenFileDialog(); mDlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; if (mDlg.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(mDlg.FileName, FileMode.Open); byte[] bFile = new byte[fs.Length]; fs.Read(bFile, 0, (int)fs.Length); adapter.Insert("销售管理", "1.1", "", DateTime.Now, bFile, ""); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { FileVersionInfo FileInfo = FileVersionInfo.GetVersionInfo(Application.StartupPath + "\\销售管理.exe"); //获取文件版本信息 Version mVer = new Version(FileInfo.FileVersion); Version sVer = new Version(new T_UpdateTableAdapter().GetMaxVer()); if (mVer >= sVer) { Process.Start(AppDomain.CurrentDomain.BaseDirectory + "销售管理.exe"); return; } var mFilesTable = new T_UpdateTableAdapter().GetDataByVer(mVer.ToString()); int count = mFilesTable.Rows.Count; pbStatus.Step = 100 / count; foreach (DAL.DataSetUpdate.T_UpdateRow mFile in mFilesTable.Rows) { byte[] bFile; string mPath; bFile = mFile.Content; if (string.IsNullOrEmpty(mFile.Dir) == false) { mPath = AppDomain.CurrentDomain.BaseDirectory + mFile.Dir + "\\" + mFile.ProgramName; } else { mPath = AppDomain.CurrentDomain.BaseDirectory + mFile.ProgramName; } if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + mFile.Dir) == false) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + mFile.Dir); } using (FileStream fs = new FileStream(mPath, FileMode.Create)) { fs.Write(bFile, 0, bFile.Length); fs.Close(); } pbStatus.PerformStep(); } Process.Start(AppDomain.CurrentDomain.BaseDirectory + "销售管理.exe"); Application.Exit(); } catch (Exception ex) { MessageBox.Show(ex.Message); System.Environment.Exit(0); } }
private void button2_Click(object sender, EventArgs e) { T_UpdateTableAdapter adapter = new T_UpdateTableAdapter(); byte[] bFile; string mPath; mPath = AppDomain.CurrentDomain.BaseDirectory + "\\temp\\"; bFile = ((销售管理.DAL.DataSetT_Update.T_UpdateRow)adapter.GetData().Rows[0]).Content; using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\temp\\" + ((销售管理.DAL.DataSetT_Update.T_UpdateRow)adapter.GetData().Rows[0]).Dir, FileMode.Create)) { fs.Write(bFile, 0, bFile.Length); fs.Close(); } }
private void btnUpload_Click(object sender, EventArgs e) { try { int count = 0; //把表格中的文件上传 T_UpdateTableAdapter adapter = new T_UpdateTableAdapter(); if (adapter.Connection.State == ConnectionState.Closed) { adapter.Connection.Open(); } //循环 foreach (DataRow mRow in mTable.Rows) { string fileName, fileUpPath, fileFullPath; fileName = mRow["文件名"].ToString(); fileUpPath = mRow["相对路径"].ToString(); fileFullPath = mRow["文件目录"].ToString(); // if (File.Exists(fileFullPath) == true) //检查文件是够存在 { string filePath = ""; //如果上传文件是本身,复制文件并上传 filePath = fileFullPath.Insert(fileFullPath.LastIndexOf('\\'), "\\upload"); if (Directory.Exists(filePath.Substring(0, filePath.LastIndexOf('\\'))) == false) { Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf('\\'))); } File.Copy(fileFullPath, filePath, true); using (FileStream fs = new FileStream(filePath, FileMode.Open)) //打开文件,将文件写入字节数组 { byte[] bFile = new byte[fs.Length]; fs.Read(bFile, 0, (int)fs.Length); adapter.Insert(fileName, txtVer.Text, fileUpPath, DateTime.Now, bFile, ""); fs.Close(); fs.Dispose(); count++; } } else { MessageBox.Show("文件不存在"); } } if (adapter.Connection.State == ConnectionState.Open) { adapter.Connection.Close(); } if (count > 0) { MessageBox.Show("文件上传成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }