Exemplo n.º 1
0
        private void CreatePDF(DataGridViewRow row)
        {
            string ordernum = row.Cells[4].Value.ToString().Trim();
            string cname    = row.Cells[2].Value.ToString();
            string realname = row.Cells[5].Value.ToString();
            string section  = row.Cells[3].Value.ToString().Replace("\\", "").Replace("/", "");
            string labname  = row.Cells[1].Value.ToString();
            string strpath  = Application.StartupPath + "\\reporttemplate\\";

            using (Report report = new CommonReport().GetReport(ordernum, strpath))
            {
                //生成PDF文件保存在PdfFile文件夹内,以时间命名
                string FilePdfPath = Application.StartupPath + "\\PdfFile\\" + labname + "\\" + ordernum.ToString().Substring(0, 8) + "\\" + cname + "\\";
                string randomName  = string.Empty;
                if (!string.IsNullOrEmpty(section))
                {
                    FilePdfPath += section + "\\";
                }
                randomName = string.Format("{0}_{1}.pdf", ordernum, realname);
                string pdfPath = FilePdfPath + randomName;
                if (!Directory.Exists(FilePdfPath))
                {
                    Directory.CreateDirectory(FilePdfPath); //若文件夹不存在则新建文件夹
                }
                if (File.Exists(pdfPath))
                {
                    File.Delete(pdfPath);
                }
                PDFExport tyt = new PDFExport()
                {
                    Compressed = true, RichTextQuality = 50, EmbeddingFonts = false
                };
                report.Export(tyt, pdfPath);
            }
            if (ckChangeStatus.Checked)
            {
                //修改状态
                Hashtable ht = new Hashtable();
                ht.Add("ordernum", ordernum);
                ht.Add("oldstatus", (int)ParamStatus.OrdersStatus.FinishCheck);
                ht.Add("status", (int)ParamStatus.OrdersStatus.FinishPrint);
                os.EditStatusByOldStatus(ht);
            }
        }
Exemplo n.º 2
0
        /// <summary>开始计时
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            string strOrderNum = "";//条码号

            if (b)
            {
                return;
            }
            //设置timer不可用
            timer.Stop();//
            //传输数据
            try
            {
                #region
                DataTable dt = orderservice.GetSelectOrdersByStatus();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //生成pdf
                        strOrderNum = dt.Rows[i]["barcode"].ToString();
                        string strpath = ConfigurationManager.AppSettings["path"];
                        using (Report report = new CommonReport().GetReport(strOrderNum, strpath))
                        {
                            //生成PDF文件保存在PdfFile文件夹内,以时间命名
                            string FilePdfPath = Application.StartupPath + "\\PdfFile\\";
                            string randomName  = "";
                            string idnumber    = dt.Rows[i]["idnumber"].ToString().Trim();
                            string ordernum    = strOrderNum;
                            string realname    = dt.Rows[i]["realname"].ToString();
                            if (string.IsNullOrEmpty(idnumber))
                            {
                                randomName = String.Format("{0}_{1}.pdf", ordernum, realname);
                            }
                            else
                            {
                                randomName = string.Format("{0}_{1}_{2}.pdf", idnumber, ordernum, realname);
                            }
                            string pdfPath = FilePdfPath + randomName;
                            if (!Directory.Exists(FilePdfPath))
                            {
                                Directory.CreateDirectory(FilePdfPath); //若文件夹不存在则新建文件夹
                            }
                            PDFExport tyt = new PDFExport()
                            {
                                Compressed = true, RichTextQuality = 50, EmbeddingFonts = false
                            };
                            report.Export(tyt, pdfPath);
                        }

                        //修改状态
                        Hashtable htorder = new Hashtable();
                        htorder.Add("Transed", "1");
                        htorder.Add("ordernum", strOrderNum);
                        bool falg = new OrdersService().EditTransed(htorder);

                        SetTB(String.Format("订单号:{0}报告生成状态【{1}】!", strOrderNum, falg));
                    }
                }
                else
                {
                    SetTB(String.Format("---{0}  没有传输的数据!\n", DateTime.Now));
                }
                #endregion
            }
            catch (Exception ex)
            {
                string strmessage = String.Format("订单号:{0}报告生成出错;时间{1}:  错误原因:{2}", strOrderNum, DateTime.Now, ex.Message);
                SetTB(strmessage);
                CreateErrorLog(strmessage);
            }
            finally
            {
                timer.Start();
            }
        }