コード例 #1
0
 /// <summary>
 /// 打开窗口按钮事件
 /// </summary>
 /// <param name="sender">事件对象</param>
 /// <param name="e">事件参数</param>
 private void t_btn_Open_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (t_pgg_Bill.SelectedItem == null)
         {
             XMessageBox.Warning("未选中一条单据!", this);
             return;
         }
         t_pgg_Bill_MouseDoubleClick(null, null);
     }
     catch (Exception ex)
     {
         XMessageBox.Exception(ex);
     }
 }
コード例 #2
0
        /// <summary>
        /// 加载用户打印设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void PrintSetting_Load(object sender, EventArgs e)
        {
            try
            {
                var fileName = Config.FilePath;

                if (File.Exists(fileName))
                {
                    RawPrintSetting rps = Config.GetRawPrintSettings();
                    if (rps != null)
                    {
                        //打印机
                        foreach (PrinterSettings ps in this.cmbPrinter.Items)
                        {
                            if (ps.PrinterName.Equals(rps.PrinterName, StringComparison.OrdinalIgnoreCase))
                            {
                                ps.DefaultPageSettings.Landscape = rps.LandScape;
                                ps.DefaultPageSettings.Margins   = rps.PageMargins;
                                this.cmbPrinter.SelectedItem     = ps;
                                PrinterSelectChange(this.cmbPrinter, new EventArgs());
                                break;
                            }
                        }
                        //纸张
                        foreach (PaperSize ps in this.cmbPaper.Items)
                        {
                            if (ps.PaperName.Equals(rps.PaperName, StringComparison.OrdinalIgnoreCase))
                            {
                                if (ps.PaperName.Equals("自定义纸张"))
                                {
                                    ps.Height = rps.PaperSize.Height;
                                    ps.Width  = rps.PaperSize.Width;
                                }
                                this.cmbPaper.SelectedItem = ps;
                                PaperSelectChange(this.cmbPaper, new EventArgs());
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                XMessageBox.Warning(string.Format("加载打印设置出错,您需要重新设置并保存"));
            }
        }
コード例 #3
0
        private void btn_print_Click(object sender, EventArgs e)
        {
            IsStop                     = false;
            btn_print.Enabled          = false;
            btn_print.Text             = "正在打印";
            btn_stopPrint.Enabled      = true;
            toolStripStatusLabel1.Text = "开始打印...";

            if (dataGridView1.Rows.Count < 0)
            {
                XMessageBox.Warning("未找到任何数据");
                return;
            }
            try
            {
                Bgw_Print.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text = "错误:" + ex.Message;
            }
        }
コード例 #4
0
        /// <summary>
        /// 复制按钮事件
        /// </summary>
        /// <param name="sender">事件对象</param>
        /// <param name="e">事件参数</param>
        private void t_tsb_Copy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (m_IsModify || PTBQuotation.Quotation_No == "新单")
                {
                    XMessageBox.Warning("当前单据尚未保存,请保存后再操作!", this);
                    return;
                }
                PT_B_Quotation copyModel = new PT_B_Quotation();
                copyModel.Quotation_Id    = Guid.NewGuid().ToString("N");
                copyModel.Quotation_No    = "新单";
                copyModel.Quotation_Date  = PTBQuotation.Quotation_Date;
                copyModel.Follow_Man      = PTBQuotation.Follow_Man;
                copyModel.Product_Model   = PTBQuotation.Product_Model;
                copyModel.Project_Name    = PTBQuotation.Project_Name;
                copyModel.Price           = PTBQuotation.Price;
                copyModel.Is_Tax          = PTBQuotation.Is_Tax;
                copyModel.Quotation_Type  = PTBQuotation.Quotation_Type;
                copyModel.Cycle_Time      = PTBQuotation.Cycle_Time;
                copyModel.Company_Name    = PTBQuotation.Company_Name;
                copyModel.Company_Address = PTBQuotation.Company_Address;
                copyModel.Contact_Man     = PTBQuotation.Contact_Man;
                copyModel.Tel             = PTBQuotation.Tel;
                copyModel.Email           = PTBQuotation.Email;
                copyModel.Fax             = PTBQuotation.Fax;
                copyModel.Remark          = PTBQuotation.Remark;
                copyModel.Oper_Time       = DateTime.Now;

                PTBQuotation = copyModel;
                LoadControlsValue();
            }
            catch (Exception ex)
            {
                XMessageBox.Exception(ex);
            }
        }
コード例 #5
0
        private void InitData(int index)
        {
            PageSettings ps = Config.GetPageSettings();

            MyReportViewer.SetPageSettings(ps);
            MyReportViewer.LocalReport.ReportPath = Config.TemplateLocation(PrintData.PrintTemplate.FileName);

            Dictionary <string, object> item = new Dictionary <string, object>();

            if (PrintData != null && PrintData.Data.Count > 0)
            {
                item = PrintData.Data[index];
            }
            else
            {
                XMessageBox.Warning("未加载到数据");
                return;
            }

            MyReportViewer.LocalReport.DataSources.Clear();
            MyReportViewer.LocalReport.DataSources.Add(new ReportDataSource(PrintData.PrintTemplate.DataSetName, item.ToDataTable()));
            var printParams = PrintData.PrintTemplate.PrintParams;

            if (printParams.Count > 0)
            {
                int j = 0;
                foreach (var parameter in MyReportViewer.LocalReport.GetParameters())
                {
                    var    db_param = PrintData.PrintTemplate.PrintParams.Find(p => p.PrintParamName == parameter.Name);
                    string fileName = $"{PrintData.PrintTemplate.PrintTemplateID}_{db_param.Value}{index}{j++}";

                    switch (db_param.ParamType)
                    {
                    case ParamType.BarCode:
                        //创建条形码文件
                        fileName += "1D";
                        string value = CanCreateCode(db_param, item, out bool isCreate);

                        if (isCreate == false)
                        {
                            XMessageBox.Error($"值({value})不能生成条形码");
                        }

                        PrintReport.CreateBarCode(value, fileName, Config.TempleAddress);
                        break;

                    case ParamType.QRCode:
                        //创建二维码
                        fileName += "2D";
                        value     = CanCreateCode(db_param, item, out isCreate);

                        if (isCreate == false)
                        {
                            XMessageBox.Error($"值({value})不能生成条形码");
                        }
                        PrintReport.CreateQRCode(value, fileName, Config.TempleAddress);
                        break;

                    case ParamType.Other:

                        MyReportViewer.LocalReport.SetParameters(new ReportParameter
                                                                     (parameter.Name, Convert.ToString(item[db_param.Value])));
                        continue;

                    case ParamType.SQL:
                        value = "0";
                        if (item.ContainsKey(db_param.Value))
                        {
                            value = Convert.ToString(item[db_param.Value]);
                        }
                        MyReportViewer.LocalReport.SetParameters(new ReportParameter
                                                                     (parameter.Name, value));
                        continue;
                    }
                    var file = Path.Combine(Config.TempleAddress, fileName + ".bmp");
                    MyReportViewer.LocalReport.SetParameters(new ReportParameter(parameter.Name, "file://" + file));
                }
            }
            MyReportViewer.SetDisplayMode(DisplayMode.PrintLayout);
            MyReportViewer.ZoomMode    = ZoomMode.Percent;
            MyReportViewer.ZoomPercent = 100;
        }
コード例 #6
0
        /// <summary>
        /// ReportViewer渲染完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReportView_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)
        {
            if (e.Exception != null)
            {
                var exp = e.Exception;
                while (exp.InnerException != null)
                {
                    exp = exp.InnerException;
                }
                XMessageBox.Error(string.Format("无法打印:{0}", exp.Message));
                return;
            }

            ReportViewer rv = sender as ReportViewer;

            //rv.SetPageSettings(Config.GetPageSettings());
            #region 如果能直接打印了

            if (!PrintData.PrintTemplate.IsAppend || CanPrint != null && CanPrint.Value)
            {
                if (e.Exception == null && rv.LocalReport.DataSources.Count > 0)
                {
                    try
                    {
                        Export(rv.LocalReport);
                        printDocument1.DefaultPageSettings = Config.GetPageSettings();
                        printDocument1.PrinterSettings     = Config.GetPrintSettings();
                        printDocument1.Print();
                        StreamDispose();
                    }
                    catch (Exception exp)
                    {
                        XMessageBox.Warning(string.Format("无法打印:{0}", exp.Message));
                        //XMessageBox.Warning(string.Format("无法打印:{0}", exp.Message));
                    }
                }

                return;
            }

            #endregion

            #region 往页后面追加行
            if (PrintData.PrintTemplate.IsAppend)
            {
                var totalPages = rv.GetTotalPages();

                if (LastPageCount == null)
                {
                    LastPageCount = totalPages;
                }
                var dt = rv.LocalReport.DataSources[0].Value as DataTable;
                if (LastPageCount == totalPages)
                {
                    dt.Rows.Add(dt.NewRow());
                }
                else
                {
                    dt.Rows.RemoveAt(dt.Rows.Count - 1);
                    CanPrint = true;
                }
                rv.RefreshReport();
                return;
            }


            #endregion
        }
コード例 #7
0
        /// <summary>
        /// 保存方法
        /// </summary>
        private bool SaveMethod()
        {
            //新单模式
            if (string.IsNullOrEmpty(PTBQuotation.Bill_Status))
            {
                string newQuotationNo = string.Empty;
                //手动录入单号情况
                if (m_IsHand)
                {
                    //校验是否新单
                    if (t_txt_QuotationNo.Text.Trim() == "新单" || string.IsNullOrEmpty(t_txt_QuotationNo.Text.Trim()))
                    {
                        XMessageBox.Warning("报价单号不能为空或包含【新单】字符!");
                        t_txt_QuotationNo.Focus();
                        return(false);
                    }
                    //校验是否重号
                    var temp = from p in m_Entities.PT_B_Quotation
                               where p.Quotation_No == t_txt_QuotationNo.Text.Trim()
                               select p;
                    if (temp.ToList().Count > 0)
                    {
                        string mes = string.Format("报价单号:{0} 已存在,请修改!", t_txt_QuotationNo.Text.Trim());
                        XMessageBox.Warning(mes);
                        t_txt_QuotationNo.Focus();
                        return(false);
                    }
                    newQuotationNo = t_txt_QuotationNo.Text.Trim();
                }
                else
                {
                    //单号自动生成
                    newQuotationNo = m_SerialNumberMethod.GetMaxQNumber();
                }

                PTBQuotation.Quotation_Id = Guid.NewGuid().ToString("N");
                SaveModel(newQuotationNo);
                m_Entities.PT_B_Quotation.Add(PTBQuotation);
                t_txt_QuotationNo.Text = newQuotationNo;
                t_tslStateText.Text    = "已入库";
            }
            else
            {
                //打开单证,手动录入单号情况
                if (m_IsHand)
                {
                    //校验是否新单
                    if (t_txt_QuotationNo.Text.Trim() == "新单" || string.IsNullOrEmpty(t_txt_QuotationNo.Text.Trim()))
                    {
                        XMessageBox.Warning("报价单号不能为空或包含【新单】字符!");
                        t_txt_QuotationNo.Focus();
                        return(false);
                    }
                    //当报价单号有修改时
                    if (t_txt_QuotationNo.Text.Trim() != PTBQuotation.Quotation_No)
                    {
                        //读取数据库判断是否有重号
                        ProjectTrackingEntities qEntities = new ProjectTrackingEntities();
                        var temp = from p in qEntities.PT_B_Quotation
                                   where p.Quotation_No == t_txt_QuotationNo.Text.Trim()
                                   select p;
                        if (temp.ToList().Count > 0)
                        {
                            string mes = string.Format("报价单号:{0} 已存在,请修改!", t_txt_QuotationNo.Text.Trim());
                            XMessageBox.Warning(mes);
                            t_txt_QuotationNo.Focus();
                            return(false);
                        }
                        ProjectTrackingEntities pEntities = new ProjectTrackingEntities();
                        //读取原报价单所关联的项目单
                        var project = from p in pEntities.PT_B_Project
                                      where p.Quotation_No == PTBQuotation.Quotation_No
                                      orderby p.Project_No
                                      select p;
                        //修改项目单的关联报价单号
                        foreach (PT_B_Project projectModel in project)
                        {
                            projectModel.Quotation_No           = t_txt_QuotationNo.Text.Trim();
                            pEntities.Entry(projectModel).State = System.Data.Entity.EntityState.Modified;
                        }
                        if (project.ToList().Count > 0)
                        {
                            pEntities.SaveChanges();
                        }
                    }
                }
                SaveModel(t_txt_QuotationNo.Text);
                m_Entities.Entry(PTBQuotation).State = System.Data.Entity.EntityState.Modified;
            }
            m_Entities.SaveChanges();
            return(true);
        }
コード例 #8
0
        /// <summary>
        /// 删除按钮事件
        /// </summary>
        /// <param name="sender">事件对象</param>
        /// <param name="e">事件参数</param>
        private void t_btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (t_pgg_Bill.SelectedItem == null)
                {
                    XMessageBox.Warning("未选中一条单据!", this);
                    return;
                }
                XTreeNode myItem    = t_tvw_Module.SelectedItem as XTreeNode;
                string    myTag     = string.Empty;
                string    parentTag = string.Empty;
                if (myItem == null && m_MQuery != null)
                {
                    myTag = m_MQuery.BillType;
                }
                else
                {
                    myTag = myItem.Tag.ToString();
                    if (myItem.Parent != null)
                    {
                        parentTag = myItem.Parent.Tag.ToString();
                    }
                }
                if (myTag == "Q" || parentTag == "Q")
                {
                    PT_B_Quotation myModel = (PT_B_Quotation)t_pgg_Bill.SelectedItem;
                    if (myModel.Bill_Status != "R")
                    {
                        MessageResult myResult = XMessageBox.Ask("确认删除当前选中的单据?", this);

                        if (myResult == MessageResult.Yes)
                        {
                            myModel.Bill_Status = "R";
                            m_Entities.SaveChanges();
                            RefreshTreeNode();
                        }
                    }
                    else
                    {
                        MessageResult myResult = XMessageBox.Ask("确认彻底删除当前选中的单据?", this);
                        if (myResult == MessageResult.Yes)
                        {
                            m_Entities.PT_B_Quotation.Remove(myModel);
                            m_Entities.SaveChanges();
                            RefreshTreeNode();
                        }
                    }
                }
                else
                {
                    PT_B_Project myModel = (PT_B_Project)t_pgg_Bill.SelectedItem;
                    if (myModel.Bill_Status != "R")
                    {
                        MessageResult myResult = XMessageBox.Ask("确认删除当前选中的单据?", this);

                        if (myResult == MessageResult.Yes)
                        {
                            myModel.Bill_Status = "R";
                            m_Entities.SaveChanges();
                            RefreshTreeNode();
                        }
                    }
                    else
                    {
                        MessageResult myResult = XMessageBox.Ask("确认彻底删除当前选中的单据?", this);
                        if (myResult == MessageResult.Yes)
                        {
                            m_Entities.PT_B_Project.Remove(myModel);
                            m_Entities.SaveChanges();
                            RefreshTreeNode();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XMessageBox.Exception(ex);
            }
        }
コード例 #9
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                #region 参数校验

                if (this.cmbPrinter.SelectedItem == null)
                {
                    XMessageBox.Warning("请选择打印机");
                    return;
                }
                if (this.cmbPaper.SelectedItem == null)
                {
                    XMessageBox.Warning("请选择打印纸张");
                    return;
                }

                if (!double.TryParse(this.tbPaperWidth.Text, out double nw) || !double.TryParse(this.tbPaperHeight.Text, out double nh) || nw <= 0 || nh <= 0)
                {
                    XMessageBox.Warning("请输入正确的纸张高度和宽度,宽度和高度必须大于零");
                    return;
                }

                if (!double.TryParse(this.tbMarginBottom.Text, out double mb) || !double.TryParse(this.tbMarginRight.Text, out double mr) || !double.TryParse(this.tbMarginLeft.Text, out double ml) || !double.TryParse(this.tbMarginTop.Text, out double mt) || mt < 0 || mb < 0 || ml < 0 || mr < 0)
                {
                    XMessageBox.Warning("请输入正确的页边距,上下左右边距必须大于等于零");
                    return;
                }

                if (nh - mt - mb <= 0 || Math.Abs(nh - mt - mb) / (double)nh < 0.2)
                {
                    XMessageBox.Warning("上下边距太大,可打印区域太小,请重新设置上下边距");
                    return;
                }

                if (nw - mr - ml <= 0 || Math.Abs(nw - mr - ml) / (double)nw < 0.2)
                {
                    XMessageBox.Warning("左右边距太大,可打印区域太小,请重新设置左右边距");
                    return;
                }

                #endregion

                PrinterSettings ps = cmbPrinter.SelectedItem as PrinterSettings;
                var             pz = cmbPaper.SelectedItem as PaperSize;
                ps.DefaultPageSettings.PaperSize = pz;
                if (pz.PaperName.Equals("自定义纸张"))
                {
                    pz.Width  = (int)Config.Mm2Inch(Convert.ToDouble(tbPaperWidth.Text));
                    pz.Height = (int)Config.Mm2Inch(Convert.ToDouble(tbPaperHeight.Text));
                }
                ps.DefaultPageSettings.Margins = new Margins
                {
                    Top    = (int)Config.Mm2Inch(Convert.ToDouble(tbMarginTop.Text)),
                    Bottom = (int)Config.Mm2Inch(Convert.ToDouble(tbMarginBottom.Text)),
                    Left   = (int)Config.Mm2Inch(Convert.ToDouble(tbMarginLeft.Text)),
                    Right  = (int)Config.Mm2Inch(Convert.ToDouble(tbMarginRight.Text))
                };
                ps.DefaultPageSettings.Landscape = this.rbLanscape.Checked;

                RawPrintSetting rps = new RawPrintSetting();
                rps.LandScape   = this.rbLanscape.Checked;
                rps.PageMargins = ps.DefaultPageSettings.Margins;
                rps.PaperName   = ps.DefaultPageSettings.PaperSize.PaperName;
                rps.PaperSize   = pz;
                rps.PrinterName = ps.PrinterName;



                XMessageBox.Info(Config.SaveSetting(rps));
            }
            catch (Exception exp)
            {
                XMessageBox.Error(string.Format("保存打印设置失败:{0}", exp.Message));
            }
        }