예제 #1
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.progressBar1.Visible = false;
            this.progressBar1.Value   = 0;

            if (OnRefreshData != null)
            {
                OnRefreshData(null, null);
            }

            string tips = e.Result as string;

            if (!string.IsNullOrEmpty(tips))
            {
                MessageDxUtil.ShowTips(tips);
                if (tips == "操作成功")
                {
                    this.gridControl1.DataSource = null;
                }
            }
        }
예제 #2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (this.txtPrinter.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请选择或输入打印机名称");
                this.txtPrinter.Focus();
                return;
            }

            //保存配置并返回
            try
            {
                config.AppConfigSet(SaveConfigName, this.txtPrinter.Text);

                this.DefaultPrinterName = this.txtPrinter.Text;
                this.DialogResult       = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageDxUtil.ShowTips(ex.Message);
            }
        }
예제 #3
0
 private void lnkExcel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         string templateFile = this.lnkExcel.Tag.ToString();
         if (string.IsNullOrEmpty(templateFile))
         {
             MessageDxUtil.ShowTips("导入操作未指定模板文件");
             return;
         }
         if (!File.Exists(templateFile))
         {
             MessageDxUtil.ShowTips(templateFile + " 不存在该模板文件!");
             return;
         }
         Process.Start(templateFile);
     }
     catch (Exception)
     {
         MessageDxUtil.ShowWarning("文件打开失败");
     }
 }
예제 #4
0
        private void btnSaveData_Click(object sender, EventArgs e)
        {
            if (worker.IsBusy)
            {
                return;
            }

            if (this.txtFilePath.Text == "")
            {
                MessageDxUtil.ShowTips("请选择指定的Excel文件");
                return;
            }

            if (MessageDxUtil.ShowYesNoAndWarning("该操作将把数据导入到系统数据库中,您确定是否继续?") == DialogResult.Yes)
            {
                if (myDs != null && myDs.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = myDs.Tables[0];
                    this.progressBar1.Visible = true;
                    worker.RunWorkerAsync();
                }
            }
        }
예제 #5
0
        private void btnPrintSetup_Click(object sender, EventArgs e)
        {
            try
            {
                PageSetupDialog psd = new PageSetupDialog();
                psd.Document             = _printdocument;
                psd.PageSettings.Margins = PrinterUnitConvert.Convert(psd.PageSettings.Margins,
                                                                      PrinterUnit.ThousandthsOfAnInch, PrinterUnit.HundredthsOfAMillimeter);

                if (psd.ShowDialog() == DialogResult.OK)
                {
                    _printdocument.Print();
                }
                else
                {
                    psd.PageSettings.Margins = PrinterUnitConvert.Convert(psd.PageSettings.Margins,
                                                                          PrinterUnit.HundredthsOfAMillimeter, PrinterUnit.ThousandthsOfAnInch);
                }
            }
            catch (Exception ex)
            {
                MessageDxUtil.ShowError(ex.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// 保存操作的统一入口
        /// </summary>
        /// <param name="close">关闭窗体</param>
        public virtual void SaveEntity(bool close)
        {
            // 检查输入的有效性
            if (this.CheckInput())
            {
                // 设置鼠标繁忙状态
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    if (this.SaveEntity())
                    {
                        ProcessDataSaved(this.btnOK, new EventArgs());

                        MessageDxUtil.ShowTips("保存成功");
                        if (close)
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            this.ClearScreen();
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.ProcessException(ex);
                }
                finally
                {
                    // 设置鼠标默认状态
                    this.Cursor = Cursors.Default;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 保存图片到服务器
        /// </summary>
        public bool SavePicture(string id)
        {
            this.ID = id;//设置控件的ID值

            if (string.IsNullOrEmpty(id))
            {
                MessageDxUtil.ShowTips("记录ID未指定,无法保存,请先保存数据!");
                return(false);
            }
            if (OnSavePortrait == null)
            {
                MessageDxUtil.ShowTips("控件未指定OnSavePortrait处理事件!");
                return(false);
            }

            if (picPortrait.Image != null)
            {
                try
                {
                    byte[] imageBytes = ImageHelper.ImageToBytes(this.picPortrait.Image);

                    bool sucess = false;
                    if (OnSavePortrait != null)
                    {
                        sucess = OnSavePortrait(this.ID, imageBytes, ImageType);
                    }
                    return(sucess);
                }
                catch (Exception ex)
                {
                    MessageDxUtil.ShowError(ex.Message);
                    LogTextHelper.Error(ex);
                }
            }
            return(false);
        }
예제 #8
0
 /// <summary>
 /// 记录异常
 /// </summary>
 /// <param name="ex"></param>
 public void WriteException(Exception ex)
 {
     // 在本地记录异常
     LogTextHelper.Error(ex);
     MessageDxUtil.ShowError(ex.Message);
 }
예제 #9
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int itemCount  = 0;
            int errorCount = 0;

            if (myDs != null && myDs.Tables[0].Rows.Count > 0)
            {
                //定义步长
                double    step = 50 * (1.0 / myDs.Tables[0].Rows.Count);
                DataTable dt   = myDs.Tables[0];
                int       i    = 1;
                try
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (OnDataSave != null)
                        {
                            #region 保存操作,如果有错误,则记录并处理
                            try
                            {
                                bool success = OnDataSave(dr);
                                if (success)
                                {
                                    itemCount++;
                                }
                            }
                            catch (Exception ex)
                            {
                                errorCount++;
                                LogTextHelper.Error(ex);
                                MessageDxUtil.ShowError(ex.Message);
                            }

                            if (errorCount >= 3)
                            {
                                var format = "记录导入已经连续出错超过[{0}]条,您是否确定退出导入操作?\r\n单击【是】退出导入,单击【否】忽略错误,继续导入下一记录。";
                                format = JsonLanguage.Default.GetString(format);
                                string message = string.Format(format, errorCount);

                                if (MessageDxUtil.ShowYesNoAndWarning(message) == System.Windows.Forms.DialogResult.Yes)
                                {
                                    break;
                                }
                                else
                                {
                                    errorCount = 0;//置零重新计算
                                }
                            }
                            #endregion
                        }

                        int currentStep = Convert.ToInt32(step * i);
                        worker.ReportProgress(currentStep);
                        i++;
                    }

                    if (itemCount == dt.Rows.Count)
                    {
                        e.Result = "操作成功";
                    }
                    else
                    {
                        e.Result = "操作完成,有错误可能未导入全部";
                    }
                }
                catch (Exception ex)
                {
                    e.Result = ex.Message;
                    LogTextHelper.Error(ex);
                    MessageDxUtil.ShowError(ex.ToString());
                }
            }
            else
            {
                e.Result = "请检查数据记录是否存在";
            }
        }
예제 #10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool sucess = SavePicture(this.ID);

            MessageDxUtil.ShowTips(sucess ? "图片保存成功!" : "保存失败!");
        }