示例#1
0
        private void btnAddFile_Click(object sender, EventArgs e)
        {
            if (this.cmdProduct.SelectedValue == null)
            {
                MessageBox.Show("产品名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.cmdProduct.Focus();
                return;
            }
            if (dtVersionFile == null)
            {
                VersionFileManager versionMan = new VersionFileManager();
                dtVersionFile = versionMan.GetList("1=2");
                DataColumn col = new DataColumn("bCheck", typeof(bool));
                dtVersionFile.Columns.Add(col);
                this.dgvVERSIONFILE.DataSource = dtVersionFile;
            }
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = this.txt_ProductFolder.Text;
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string  fileName = openFileDialog.FileName;
                DataRow newRow   = dtVersionFile.NewRow();
                newRow["bCheck"]       = 1;
                newRow["OBJ_NO"]       = Guid.NewGuid().ToString();
                newRow["PRODUCT_CODE"] = this.cmdProduct.SelectedValue.ToString();
                newRow["FILE_NAME"]    = openFileDialog.SafeFileName;
                newRow["FILE_PATH"]    = fileName.Replace(this.txt_ProductFolder.Text, "");
                newRow["FILE_DATA"]    = getFileByte(fileName);
                dtVersionFile.Rows.Add(newRow);
            }
        }
示例#2
0
 private void btnUpLoad_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.dgvVERSIONFILE.DataSource == null || this.dgvVERSIONFILE.RowCount == 0)
         {
             return;
         }
         if (this.txt_REMARK.Text.Trim().Length == 0)
         {
             MessageBox.Show("升级说明不允许为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.txt_REMARK.Focus();
             return;
         }
         DataRow[] rows = dtVersionFile.Select("bCheck = 1");
         if (rows.Length == 0)
         {
             MessageBox.Show("没有选择上传的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (MessageBox.Show(string.Format(string.Format("确定要上传【{0}】个升级文件,版本信息【{1}】", rows.Length, this.txt_ProductVersion.Text)), "询问",
                             MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
         {
             return;
         }
         ProductManager     pMan     = new ProductManager();
         int                iVersion = pMan.GetVersion(this.cmdProduct.SelectedValue.ToString()) + 1;
         VersionFileManager vfMan    = new VersionFileManager();
         foreach (DataRow row in rows)
         {
             row["FILE_VERSION"]  = iVersion;
             row["FILE_VERSION2"] = txt_ProductVersion.Text.Trim();
             row["REMARK"]        = txt_REMARK.Text.Trim();
             vfMan.UpFile(row);
         }
         MessageBox.Show(string.Format("成功上传升级文件【{0}】个!", rows.Length), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("上传升级文件失败!" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#3
0
        /// <summary>
        /// 加载升级文件清单
        /// </summary>
        private void LoadProductFile()
        {
            if (dtVersionFile != null)
            {
                dtVersionFile.Clear();
            }
            else
            {
                VersionFileManager versionMan = new VersionFileManager();
                dtVersionFile = versionMan.GetList("1=2");
                DataColumn col = new DataColumn("bCheck", typeof(bool));
                dtVersionFile.Columns.Add(col);
                this.dgvVERSIONFILE.DataSource = dtVersionFile;
            }
            string folder = txt_ProductFolder.Text.Trim();

            if (folder.Trim().Length == 0)
            {
                return;
            }
            ProductFileManager pfMan = new ProductFileManager();
            DataTable          dtPF  = pfMan.GetProductFileList(this.cmdProduct.SelectedValue.ToString());

            foreach (DataRow row in dtPF.Rows)
            {
                //[OBJ_NO],[PRODUCT_CODE],[FILE_VERSION],[FILE_VERSION2],[FILE_NAME],[FILE_PATH],[FILE_DATA],[OBJ_DATE],[REMARK]
                string fileName = folder + @"\" + row["PRODUCT_FILENAME"].ToString();
                if (File.Exists(fileName))
                {
                    DataRow newRow = dtVersionFile.NewRow();
                    newRow["bCheck"]       = 1;
                    newRow["OBJ_NO"]       = Guid.NewGuid().ToString();
                    newRow["PRODUCT_CODE"] = this.cmdProduct.SelectedValue.ToString();
                    string   product_Filename = row["PRODUCT_FILENAME"].ToString();
                    string[] names            = product_Filename.Split('\\');
                    newRow["FILE_NAME"] = names[names.Length - 1];
                    newRow["FILE_PATH"] = @"\" + product_Filename;
                    newRow["FILE_DATA"] = getFileByte(fileName);
                    dtVersionFile.Rows.Add(newRow);
                }
            }
        }
示例#4
0
        /// <summary>
        /// 升级程序
        /// </summary>
        void DoUpgrade()
        {
            this.progressBar1.Value = 0;
            this.txtMsg.Clear();

            this.AppendMessage("初始化升级信息...");
            if (this.CheckLicense() == false)
            {
                this.AppendMessage("初始化升级程序出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("初始化升级程序出错,请联系管理员.");
                }
                return;
            }
            if (PublicFunction.IsAppOnRunning() == true)
            {
                this.AppendMessage("升级程序运行中,请不要重复运行.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级程序运行中,请不要重复运行.");
                }
                this.Close();
            }

            UpdateXmlDataContract myInfo = this.ReadLocalInformation();

            if (string.IsNullOrEmpty(myInfo.ProductCode))
            {
                this.AppendMessage("加载升级信息出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("加载升级信息出错,请联系管理员.");
                }
                return;
            }

            if (!string.IsNullOrEmpty(PublicSetting.ProductCodeExt) && myInfo.ProductCode != PublicSetting.ProductCodeExt)
            {
                this.Close();
            }

            this.SetProgressValue(5);
            this.AppendMessage("读取升级列表中...");

            ProductManager productMan = new ProductManager();
            DataTable      dtProduct  = productMan.GetProduct(myInfo.ProductCode);

            //myInfo.ServerVersion = productMan.GetVersion(myInfo.ProductCode);
            myInfo.ServerVersion     = Convert.ToInt32(dtProduct.Rows[0]["PRODUCT_VERSION"]);
            myInfo.ServerVersionText = dtProduct.Rows[0]["PRODUCT_VERSION2"].ToString();
            if (myInfo.ServerVersion == myInfo.LocalVersion)
            {
                this.SetProgressValue(100);
                this.AppendMessage("当前已是最新版本.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("当前已是最新版本.");
                    }
                    return;
                }
                else
                {
                    this.Close();
                    return;
                }
            }

            //删除运行中的进程
            PublicFunction.KillProcess(myInfo.ProcessName);
            if (!string.IsNullOrEmpty(PublicSetting.ProcessNameExt))
            {
                PublicFunction.KillProcess(PublicSetting.ProcessNameExt);
            }

            //开始下载
            this.SetProgressValue(10);
            this.AppendMessage("开始下载升级文件...");
            System.Threading.Thread.Sleep(2000);
            string msg = "";

            VersionFileManager versionFileMan = new VersionFileManager();
            DataTable          dtFileVersion  = versionFileMan.GetDownLoadList(myInfo.LocalVersion);
            string             strRemarks     = string.Empty;
            string             strRemark      = string.Empty;
            List <string>      listRemark     = new List <string>();

            foreach (DataRow row in dtFileVersion.Rows)
            {
                strRemark = row["Remark"].ToString().Trim();
                if (strRemark.Length > 0 && !listRemark.Contains(strRemark))
                {
                    listRemark.Add(strRemark);
                    strRemarks = strRemark.Length == 0 ? strRemark : (strRemarks + Environment.NewLine + strRemark);
                }
            }
            if (strRemarks.Length > 0)
            {
                txtUpdateRemark.Text = strRemarks;
                Application.DoEvents();
            }
            int iCount = dtFileVersion.Rows.Count;

            this.progressBar1.Maximum = iCount;
            for (int i = 0; i < iCount; i++)
            {
                DataRow row = dtFileVersion.Rows[i];
                this.SetProgressValue(i + 1);
                this.AppendMessage("文件下载中..." + row["FILE_NAME"]);//下载文件
                if (this.WriteFile(versionFileMan.GetFile(row["obj_no"].ToString()), row["FILE_PATH"].ToString()) == false)
                {
                    if (msg.Length > 0)
                    {
                        msg += ";文件下载失败->";
                    }
                    msg += row["FILE_NAME"].ToString();
                }
            }

            /*
             * List<VersionFileDataContract> fileList = versionMan.GetDownLoadList(myInfo.ProductCode, myInfo.ServerVersion);
             *
             * for (int i = 0; i < fileList.Count; i++)
             * {
             *  this.SetProgressValue(10 + (i + 1) * 100 / fileList.Count * 9 / 10);
             *  this.AppendMessage("文件下载中..." + fileList[i].FileName);
             *  //下载文件
             *  if (this.WriteFile(versionMan.GetFile(fileList[i]), fileList[i].FileName) == false)
             *  {
             *      if (msg.Length > 0)
             *          msg += ";文件下载失败->";
             *      msg += fileList[i].FileName;
             *  }
             * }
             */
            if (string.IsNullOrEmpty(msg))
            {
                this.AppendMessage("系统升级完成!");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("系统升级完成!");
                    }
                }
                try
                {
                    //升级信息保存到本地
                    this.UpdateUpgradeInformation(myInfo);
                    //System.Diagnostics.Process.Start
                }
                catch (Exception ex)
                { }
            }
            else
            {
                this.AppendMessage("升级失败,参考信息:" + msg);
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级失败,参考信息:" + msg);
                }
            }
        }