Ejemplo n.º 1
0
        /// <summary>
        ///  匯出yahoo出貨當
        /// </summary>
        public void OutChannelOrderCSV()
        {
            DeliverMasterQuery query = new DeliverMasterQuery();
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            try
            {
                int totalCount = 0;
                string condition = Request.Params["condition"];
                string content = Request.Params["content"];
                string deliverystore = Request.Params["delivery_store"];
                string channel = Request.Params["channel"];
                string ddstatus = Request.Params["delivery_status"];
                string retrieve_mode = Request.Params["retrieve_mode"];
                string datequery = Request.Params["datequery"];
                string starttime = Request.Params["time_start"];
                string endtime = Request.Params["time_end"];
                query.IsPage = false;
                if (condition != "0")
                {
                    if (!string.IsNullOrEmpty(content))
                    {
                        switch (condition)
                        {
                            case "1":
                                query.od_order_id = uint.Parse(content);
                                break;
                            case "2":
                                query.channel_order_id = content;
                                break;
                            case "3":
                                query.sub_order_id = content;
                                break;
                            default:
                                break;
                        }
                    }
                }
                if (deliverystore != "0" && !string.IsNullOrEmpty(deliverystore))
                {
                    query.delivery_store = uint.Parse(deliverystore);
                }
                if (channel != "0" && !string.IsNullOrEmpty(channel))
                {
                    query.channel = int.Parse(channel);
                }
                if (ddstatus != "-1")
                {
                    query.dd_status = int.Parse(ddstatus);
                }
                if (retrieve_mode != "-1" && !string.IsNullOrEmpty(retrieve_mode))
                {
                    query.retrieve_mode = int.Parse(retrieve_mode);
                }
                if (datequery != "0")
                {
                    if (!string.IsNullOrEmpty(starttime))
                    {
                        starttime = DateTime.Parse(starttime).ToString("yyyy-MM-dd HH:mm:ss");
                        query.sqlwhere = " and dm.delivery_date >='" + starttime + "'";
                    }
                    if (!string.IsNullOrEmpty(endtime))
                    {
                        endtime = DateTime.Parse(endtime).ToString("yyyy-MM-dd") + " 23:59:59";
                        query.sqlwhere += " and dm.delivery_date <='" + endtime + "'";
                    }
                }
                object ob = _DeliverDetailMgr.GetChannelOrderList(query, out totalCount, 1);
                DataTable channelorder = new DataTable();
                if (ob.GetType() == typeof(DataTable))
                {
                    channelorder = (DataTable)ob;
                }
                //DataTable newchannel = channelorder.DefaultView.ToTable(false, new string[] { "sub_order_id", "delivery_code" });
                // newchannel.Columns["delivery_store"].Expression = " IIF (delivery_store <> 11,11,11)";
                DataColumn dcol = new DataColumn("delivery_store", typeof(String));
                dcol.DefaultValue = 11;
                channelorder.Columns.Add(dcol);
                channelorder.Columns["delivery_store"].SetOrdinal(1);
                //dcol.Expression = " IIF (delivery_store <> 11,11,11)";
                DataColumn col = new DataColumn("ok", typeof(String));
                col.DefaultValue = "OK";
                channelorder.Columns.Add(col);
                string fileName = string.Empty;
                string newName = string.Empty;
                fileName = "channel_order_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
                if (!System.IO.Directory.Exists(Server.MapPath(excelPath)))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(excelPath));
                }
                newName = Server.MapPath(excelPath) + fileName;

                if (System.IO.File.Exists(newName))
                {
                    //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除
                    System.IO.File.SetAttributes(newName, FileAttributes.Normal);
                    System.IO.File.Delete(newName);
                }
                //StringWriter sw = ExcelHelperXhf.SetCsvFromData(channelorder, fileName);
                // CsvHelper.ExportDataTableToCsv(channelorder,newName,null,false);
                StringWriter sw = new StringWriter();
                foreach (DataRow dr in channelorder.Rows)
                {
                    for (int i = 0; i < channelorder.Columns.Count; i++)
                    {
                        sw.Write(dr[i].ToString());
                        if (i != channelorder.Columns.Count - 1)
                        {
                            sw.Write(",");
                        }
                    }
                    sw.WriteLine("");
                }
                sw.Close();

                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                Response.ContentType = "application/ms-excel";
                Response.ContentEncoding = Encoding.Default;
                Response.Write(sw);
                Response.End();
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }


        }
Ejemplo n.º 2
0
        /// <summary>
        /// 貨運單  delivery_store=17 即 吉甲地車隊貨到付款 才須匯出貨運單
        /// </summary>
        public void GetCarWaybillsPDF()
        {
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            string deliver_id = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
            {
                deliver_id = Request.Params["deliver_id"];
            }
            string ticketid = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["ticket_id"]))
            {
                ticketid = Request.Params["ticket_id"];
                ticketid = ticketid.Remove(ticketid.LastIndexOf(','));
            }
            DataTable bills = _DeliverDetailMgr.GetWayBills(deliver_id, ticketid);
            string estimated_delivery_date = string.Empty;
            string sestimated_arrival_period = string.Empty;
            string estimated_arrival_period = string.Empty;
            string infor = string.Empty;
            string receivable = string.Empty;
            string order_id = string.Empty;
            int i = 0;
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)5, (float)0.5);
            int iTemp = 0;
            string filename = string.Empty;
            if (int.TryParse(ticketid, out iTemp))
            {
                filename = "carwaybills_T" + ticketid.PadLeft(8, '0') + ".pdf";
            }
            else
            {
                filename = "carwaybills_T" + ticketid.Substring(0, ticketid.IndexOf(',')).ToString().PadLeft(8, '0') + ".pdf";
            }

            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  

            foreach (DataRow dr in bills.Rows)
            {
                estimated_delivery_date = !string.IsNullOrEmpty(dr["estimated_delivery_date"].ToString()) ? DateTime.Parse(dr["estimated_delivery_date"].ToString()).ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM-dd");
                estimated_arrival_period = dr["estimated_arrival_period"].ToString();
                switch (dr["estimated_arrival_period"].ToString())
                {
                    case "0":
                        sestimated_arrival_period = "不限時";
                        break;
                    case "1":
                        sestimated_arrival_period = "12:00以前";
                        break;
                    case "2":
                        sestimated_arrival_period = "12:00-17:00";
                        break;
                    case "3":
                        sestimated_arrival_period = "17:00-20:00";
                        break;
                    default:
                        break;

                }
                //infor = dr["delivery_name"].ToString() + "\n\n" + CommonFunction.ZipAddress(dr["delivery_zip"].ToString()) + "\n" + dr["delivery_address"].ToString() + "\n\n\n" + dr["delivery_mobile"].ToString();
                receivable = dr["receivable"].ToString() != "0" ? dr["receivable"].ToString() : "不收款";
                order_id = dr["order_id"].ToString();
                font = new iTextSharp.text.Font(bfChinese, 16, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c1 = new Chunk(dr["delivery_name"].ToString() + "\n\n", font);
                font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c2 = new Chunk(CommonFunction.ZipAddress(dr["delivery_zip"].ToString()) + "\n\n" + dr["delivery_address"].ToString() + "\n\n\n", font);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c3 = new Chunk(dr["delivery_mobile"].ToString(), font);
                Phrase pinfor = new Phrase();
                pinfor.Add(c1);
                pinfor.Add(c2);
                pinfor.Add(c3);
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage(order_id, BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 40);
                Chunk orderidck = new Chunk(IMG, 0, 0); //图片可设置 偏移


                imgTemp = _Code.GetCodeImage("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 40);
                Chunk deliveridck = new Chunk(IMG, 0, 0); //图片可设置 偏移



                //PdfContentByte cb = writer.DirectContent;
                // cb.BeginText();
                if (i % 2 == 0 && i != 0)
                {
                    document.NewPage();
                }
                PdfPTable totaltable = new PdfPTable(3);
                totaltable.WidthPercentage = 100;
                totaltable.SetWidths(new int[] { 45, 2, 53 });
                totaltable.DefaultCell.DisableBorderSide(1);
                totaltable.DefaultCell.DisableBorderSide(2);
                totaltable.DefaultCell.DisableBorderSide(4);
                totaltable.DefaultCell.DisableBorderSide(8);
                PdfPCell cell;
                #region 左邊框
                PdfPTable table = new PdfPTable(4);
                table.SetTotalWidth(new float[] { 60, 75, 10, 100 });
                table.DefaultCell.UseAscender = true;
                table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell = new PdfPCell(new Phrase("出貨日", font));
                cell.FixedHeight = 17f;
                table.AddCell(cell);
                table.AddCell(new Phrase("預定配送日", font));

                cell = new PdfPCell(new Phrase("指定時段", font));
                cell.Colspan = 2;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
                cell.FixedHeight = 17f;
                table.AddCell(cell);
                //table.AddCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
                table.AddCell(new Phrase(estimated_delivery_date, font));
                table.AddCell(new Phrase(estimated_arrival_period, font));
                table.AddCell(new Phrase(sestimated_arrival_period, font));
                table.AddCell(new Phrase("收\n件\n人", font));
                cell = new PdfPCell(pinfor);
                cell.Colspan = 3;
                table.AddCell(cell);
                table.AddCell(new Phrase("寄件人", font));
                font = new iTextSharp.text.Font(bfChinese, 7, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("台北市南港區八德路四段768巷5號4F之一 \n\n 吉甲地好市集股份有限公司", font));
                cell.UseAscender = true;
                cell.HorizontalAlignment = 3;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("訂單編號", font));
                cell = new PdfPCell(new Phrase(orderidck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = 1;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("吉\n甲\n地", font));
                cell.UseDescender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(2);
                table.AddCell(cell);
                PdfPTable stable = new PdfPTable(2);
                stable.DefaultCell.UseAscender = true;
                stable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                stable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                stable.AddCell(new Phrase("代收貨款", font));
                stable.AddCell(new Phrase(receivable, font));
                stable.AddCell(new Phrase("出貨單號", font));
                cell = new PdfPCell(new Phrase(deliveridck));
                float h = cell.Height;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                stable.AddCell(cell);
                cell = new PdfPCell(stable);
                cell.Colspan = 3;
                table.AddCell(cell);
                // table.WriteSelectedRows(0, -1, 10, 820, writer.DirectContent);
                #endregion
                #region
                totaltable.AddCell(table);
                totaltable.AddCell(" ");
                #endregion
                #region 右邊框
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table = new PdfPTable(6);
                table.SetTotalWidth(new float[] { 60, 70, 40, 65, 40, 50 });
                table.DefaultCell.UseAscender = true;
                table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell = new PdfPCell();
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(4);
                table.AddCell(cell);
                stable = new PdfPTable(1);
                stable.DefaultCell.UseAscender = true;
                stable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                stable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                //stable.AddCell(new Phrase("包裹查詢號碼", font));
                cell = new PdfPCell(new Phrase("包裹查詢號碼", font));
                cell.FixedHeight = 17f;
                stable.AddCell(cell);
                //stable.AddCell(new Phrase("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), font));
                cell = new PdfPCell(new Phrase("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), font));
                cell.FixedHeight = 17f;
                stable.AddCell(cell);
                cell = new PdfPCell(stable);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(deliveridck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 2;
                table.AddCell(cell);
                table.AddCell(new Phrase("備註", font));
                string name = string.Empty;
                for (int k = 0; k < dr["delivery_name"].ToString().Length; k++)
                {
                    name += dr["delivery_name"].ToString()[k] + "\n";
                }
                font = new iTextSharp.text.Font(bfChinese, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("吉\n甲\n地\n\n" + name, font));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Rowspan = 6;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("收\n件\n人", font));
                cell = new PdfPCell(pinfor);
                //cell.UseAscender = true;
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell = new PdfPCell();
                cell.Rowspan = 5;
                table.AddCell(cell);
                table.AddCell(new Phrase("寄件人", font));
                font = new iTextSharp.text.Font(bfChinese, 7, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("台北市南港區八德路四段768巷5號4F之一 \n\n 吉甲地好市集股份有限公司", font));
                //cell.UseAscender = true;
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("訂單編號", font));
                cell = new PdfPCell(new Phrase(orderidck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 3;
                table.AddCell(cell);
                table.AddCell(new Phrase("指定時段", font));
                table.AddCell(new Phrase(sestimated_arrival_period, font));
                cell = new PdfPCell(new Phrase("\n\n收件人簽名\n\n", font));
                cell.Rowspan = 2;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                // cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                PdfPCell ncell = new PdfPCell();
                //ncell.DisableBorderSide(1);
                //ncell.DisableBorderSide(2);
                ncell.Rowspan = 2;
                table.AddCell(ncell);
                //table.AddCell(new Phrase("收件人簽名", font));
                cell = new PdfPCell(new Phrase("代收貨款", font));
                cell.FixedHeight = h;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                table.AddCell(new Phrase(receivable, font));
                // table.WriteSelectedRows(0, -1, 280, 820, writer.DirectContent);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                #endregion
                totaltable.AddCell(table);
                // cb.EndText();
                totaltable.SpacingAfter = 75f;
                document.Add(totaltable);
                i++;
            }
            document.Close();


            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);

        }
Ejemplo n.º 3
0
        public HttpResponseBase GetChannelOrderList()
        {
            string json = String.Empty;
            List<DeliverMasterQuery> store = new List<DeliverMasterQuery>();

            try
            {
                DeliverMasterQuery query = new DeliverMasterQuery();
                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量
                int totalCount = 0;
                string condition = Request.Params["condition"];
                string content = Request.Params["content"];
                string deliverystore = Request.Params["delivery_store"];
                string channel = Request.Params["channel"];
                string ddstatus = Request.Params["delivery_status"];
                string retrieve_mode = Request.Params["retrieve_mode"];
                string datequery = Request.Params["datequery"];
                string starttime = Request.Params["time_start"];
                string endtime = Request.Params["time_end"];
                if (condition != "0")
                {
                    if (!string.IsNullOrEmpty(content))
                    {
                        switch (condition)
                        {
                            case "1":
                                query.od_order_id = uint.Parse(content);
                                break;
                            case "2":
                                query.channel_order_id = content;
                                break;
                            case "3":
                                query.sub_order_id = content;
                                break;
                            default:
                                break;
                        }
                    }
                }
                if (deliverystore != "0" && !string.IsNullOrEmpty(deliverystore))
                {
                    query.delivery_store = uint.Parse(deliverystore);
                }
                if (channel != "0")
                {
                    query.channel = int.Parse(channel);
                }
                if (ddstatus != "-1")
                {
                    query.dd_status = int.Parse(ddstatus);
                }
                if (retrieve_mode != "-1" && !string.IsNullOrEmpty(retrieve_mode))
                {
                    query.retrieve_mode = int.Parse(retrieve_mode);
                }
                if (datequery != "0")
                {
                    if (!string.IsNullOrEmpty(starttime))
                    {
                        starttime = DateTime.Parse(starttime).ToString("yyyy-MM-dd HH:mm:ss");
                        query.sqlwhere = " and dm.delivery_date >='" + starttime + "'";
                    }
                    if (!string.IsNullOrEmpty(endtime))
                    {
                        endtime = DateTime.Parse(endtime).ToString("yyyy-MM-dd") + " 23:59:59";
                        query.sqlwhere += " and dm.delivery_date <='" + endtime + "'";
                    }
                }
                object ob = _DeliverDetailMgr.GetChannelOrderList(query, out totalCount);
                if (ob.GetType() == typeof(List<DeliverMasterQuery>))
                {
                    store = (List<DeliverMasterQuery>)ob;
                }
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 出貨明細
        /// </summary>
        public void GetDeliverDetailsPDF()
        {
            string deliver_id = Request.Params["deliver_id"];
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable deliverdetail = _DeliverDetailMgr.GetOrderDelivers(deliver_id, 1);
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = "deliver_details_D" + deliver_id.PadLeft(8, '0') + ".pdf";
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            PdfContentByte cb = writer.DirectContent;
            cb.BeginText();
            DataRow[] singleproduct = new DataRow[] { };//單一商品
            DataRow[] fatherproduct = new DataRow[] { };//組合商品中的父商品
            DataRow[] sonproduct = new DataRow[] { };//組合商品中的子商品
            //DataRow[] normal;
            //DataRow[] low;
            //DataRow[] lowstore;
            //List<DataRow> deliverdetails = new List<DataRow>();
            ArrayList combine = new ArrayList();

            singleproduct = deliverdetail.Select(" combined_mode<=1  and ddeliver_id=" + deliver_id, "item_id asc");//單一商品
            fatherproduct = deliverdetail.Select(" combined_mode>1 and item_mode=1 and ddeliver_id=" + deliver_id, "item_id asc");//組合商品中父商品是否存在
            foreach (var item in fatherproduct)
            {
                combine.Add(item);
                sonproduct = deliverdetail.Select(" combined_mode>1  and item_mode<>1 and parent_id=" + item["parent_id"] + " and pack_id=" + item["pack_id"], "item_id asc");//對應組合商品中的子商品
                foreach (var son in sonproduct)
                {
                    son["buy_num"] = (int.Parse(son["buy_num"].ToString()) * int.Parse(son["parent_num"].ToString())).ToString();
                    combine.Add(son);
                }

            }

            List<DataRow[]> deliverdetails = new List<DataRow[]>();
            //normal = deliverdetail.Select("product_freight_set in(1,3)  and ddeliver_id=" + deliver_id, "item_id asc");//常溫
            //low = deliverdetail.Select("product_freight_set in(2,4)  and ddeliver_id=" + deliver_id, "item_id asc");//冷凍
            //lowstore = deliverdetail.Select("product_freight_set in(5,6)  and ddeliver_id=" + deliver_id, "item_id asc");//冷藏
            if (singleproduct.Count() > 0)
            {
                deliverdetails.Add(singleproduct);
            }
            if (combine.Count > 0)
            {
                deliverdetails.Add((DataRow[])combine.ToArray(typeof(DataRow)));
            }
            if (deliverdetail.Rows.Count > 0)
            {

                cb.SetFontAndSize(bfChinese, 20);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地台灣好市集出貨明細", 30, 750, 0);
                string freight_set = string.Empty;

                switch (deliverdetail.Rows[0]["freight_set"].ToString().Trim())
                {
                    case "1":
                        freight_set = "常溫";
                        break;
                    case "2":
                        freight_set = "冷凍";
                        break;
                    case "5":
                        freight_set = "冷藏";
                        break;
                }
                cb.SetFontAndSize(bfChinese, 12);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, freight_set, 350, 780, 0);
                if (deliverdetail.Rows[0]["estimated_arrival_period"].ToString() != "0")
                {
                    string estimated_arrival_period = string.Empty;
                    switch (deliverdetail.Rows[0]["estimated_arrival_period"].ToString().Trim())
                    {
                        case "0":
                            estimated_arrival_period = "不限時";
                            break;
                        case "1":
                            estimated_arrival_period = "12:00以前";
                            break;
                        case "2":
                            estimated_arrival_period = "12:00-17:00";
                            break;
                        case "3":
                            estimated_arrival_period = "17:00-20:00";
                            break;
                    }
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, estimated_arrival_period, 350, 765, 0);
                }

                Phrase ph = new Phrase();
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp1 = _Code.GetCodeImage("D" + deliverdetail.Rows[0]["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp1.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG1 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG1.ScaleToFit(200, 30);
                Chunk ck = new Chunk(IMG1, 345, -100); //图片可设置 偏移
                ph.Add(ck);
                document.Add(ph);
                cb.SetFontAndSize(bfChinese, 10);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款單號:", 10, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購時間:", 10, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "转单日期:", 200, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "订购人:", 10, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收货人:", 200, 640, 0);
                string address = string.Empty;


                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_id"].ToString(), 80, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_createdate"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 80, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["money_collect_date"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["money_collect_date"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 250, 660, 0);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["holiday_deliver"].ToString() == "1" ? "可" : "不可", 250, 620, 0);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["note_order"].ToString(), 80, 600, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_name"].ToString(), 80, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["delivery_name"].ToString(), 250, 640, 0);
                if (deliverdetail.Rows[0]["type"].ToString() != "3")
                {
                    PdfPTable ptable = new PdfPTable(4);
                    ptable.SetTotalWidth(new float[] { 100, 320, 70, 70 });
                    PdfPCell cell = new PdfPCell();
                    cell.BorderWidth = 0.1f;
                    cell.BorderColor = new BaseColor(0, 0, 0);
                    cell = new PdfPCell(new Phrase("商品編號", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("商品名稱", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("數量", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("售价", font));
                    ptable.AddCell(cell);
                    PdfPCell td = new PdfPCell();
                    td.BorderWidth = 0.1f;
                    int j = 0;
                    foreach (var item in deliverdetails)
                    {
                        j++;
                        for (int i = 0; i < item.Count(); i++)
                        {
                            string item_id = string.Empty;
                            if (item[i]["item_mode"].ToString() == "1")
                            {
                                item_id = item[i]["parent_id"].ToString();
                            }
                            else
                            {
                                item_id = item[i]["item_id"].ToString();
                            }
                            cell = new PdfPCell(new Phrase(item_id, font));
                            ptable.AddCell(cell);
                            string datacontent = ((item[i]["item_mode"].ToString() == "2") ? " *" : "") + item[i]["product_name"].ToString() + item[i]["product_spec_name"].ToString();
                            cell = new PdfPCell(new Phrase(item[i]["brand_name"].ToString() + "-" + datacontent, font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["buy_num"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["item_mode"].ToString() == "1" ? "" : item[i]["single_money"].ToString(), font));
                            ptable.AddCell(cell);
                        }
                        if (deliverdetails.Count > 1 && j != deliverdetails.Count)
                        {
                            td = new PdfPCell();
                            td.Colspan = 4;
                            td.BorderWidthTop = 0.2f;
                            td.DisableBorderSide(2);
                            ptable.AddCell(td);
                        }
                    }
                    ptable.WriteSelectedRows(0, -1, 10, 620, writer.DirectContent);
                }
                else
                {
                    PdfPTable ptable = new PdfPTable(4);
                    // ptable.WidthPercentage = 90;
                    // ptable.TotalWidth = ptable.WidthPercentage;
                    ptable.SetTotalWidth(new float[] { 100, 350, 70, 70 });
                    PdfPCell cell = new PdfPCell();
                    cell.BorderWidth = 0.1f;
                    cell = new PdfPCell(new Phrase("產品細項編號", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("產品名稱", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("規格", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("數量", font));
                    ptable.AddCell(cell);
                    int j = 0;
                    foreach (var item in deliverdetails)
                    {
                        j++;
                        for (int i = 0; i < item.Count(); i++)
                        {
                            cell = new PdfPCell(new Phrase(item[i]["item_id"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["brand_name"].ToString() + "-" + item[i]["product_name"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["product_spec_name"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["buy_num"].ToString(), font));
                            ptable.AddCell(cell);
                        }
                        if (deliverdetails.Count > 1 && j != deliverdetails.Count)
                        {
                            cell = new PdfPCell();
                            cell.Colspan = 4;
                            cell.BorderWidthTop = 0.2f;
                            cell.DisableBorderSide(2);
                            ptable.AddCell(cell);
                        }
                    }
                    ptable.WriteSelectedRows(0, -1, 10, 620, writer.DirectContent);

                }

                cb.EndText();
                document.Close();
                writer.Resume();

                Response.Clear();
                Response.Charset = "gb2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
                Response.WriteFile(newPDFName);
            }

        }
Ejemplo n.º 5
0
        /// <summary>
        /// 貨運單  delivery_store=42 即 到店取貨 才須匯出貨運單
        /// </summary>
        public void GetShopbillsPDF()
        {
            string deliver_id = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
            {
                deliver_id = Request.Params["deliver_id"];
            }
            string ticket_id = string.Empty;
            string fticket_id = string.Empty; ;
            if (!string.IsNullOrEmpty(Request.Params["ticket_id"]))
            {
                ticket_id = Request.Params["ticket_id"];
                ticket_id = ticket_id.Remove(ticket_id.LastIndexOf(','));
                string[] ticket_ids = ticket_id.Split(',');
                if (ticket_ids.Length > 0)
                {
                    fticket_id = ticket_ids[0];
                }
                else
                {
                    fticket_id = ticket_id;
                }

            }

            int i = 0;//用來計算表格數量,來分頁
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable bills = _DeliverDetailMgr.GetWayBills(deliver_id, ticket_id);
            BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = string.Empty;
            if (string.IsNullOrEmpty(ticket_id))
            {
                filename = "shopbills_T" + deliver_id.PadLeft(8, '0') + ".pdf";
            }
            else
            {
                filename = "shopbills_T" + fticket_id.PadLeft(8, '0') + ".pdf";
            }
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            #region 條形碼
            foreach (DataRow dr in bills.Rows)
            {
                #region 條形碼要顯示的內容
                string code1 = string.Empty;
                string csvuser = "******";
                string deliver_stno = dr["deliver_stno"].ToString();
                string delivercode = "0".PadLeft(11 - dr["deliver_id"].ToString().Length, '0');
                if (deliver_stno.Length >= 1)
                {
                    switch (deliver_stno.Substring(0, 1))
                    {
                        case "F":
                            code1 = "1" + csvuser + "00";
                            break;
                        case "K":
                            code1 = "3" + csvuser + "00";
                            break;
                        case "L":
                            code1 = "2" + csvuser + "00";
                            break;
                        default:
                            break;
                    }
                }
                code1 += delivercode + dr["deliver_id"].ToString();
                int checkcode = 0;
                for (int j = 0; j < code1.Length; j++)
                {
                    checkcode += int.Parse(code1.Substring(j, 1));
                }
                checkcode = checkcode % 43;
                string[] checkcodemap = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S",
			     "T","U","V","W","X","Y","Z","-",".","SP","$","/","+","%" };
                code1 += checkcodemap.GetValue(checkcode).ToString();

                string code2 = string.Empty;
                code2 = csvuser + delivercode.Substring(0, 3) + "963";
                string code3 = string.Empty;
                string nreceivable = string.Empty;
                string ndeliver_id = string.Empty;
                ndeliver_id = (delivercode + dr["deliver_id"].ToString()).Substring(3, 8);
                nreceivable = "0".PadLeft(5 - dr["receivable"].ToString().Length, '0') + dr["receivable"].ToString();
                if (dr["order_payment"].ToString() == "20")
                {
                    code3 = ndeliver_id + "1" + nreceivable;
                }
                else
                {
                    code3 = ndeliver_id + "3" + nreceivable;
                }
                int basenum = 0;//奇數
                int evennum = 0;//偶數
                for (int k = 0; k < code2.Length; k++)
                {
                    if ((k + 1) % 2 == 1)
                    {
                        basenum += int.Parse(code2.Substring(k, 1));
                    }
                    else
                    {
                        evennum += int.Parse(code2.Substring(k, 1));
                    }
                }
                for (int l = 0; l < code3.Length; l++)
                {
                    if ((l + 1) % 2 == 1)
                    {
                        basenum += int.Parse(code3.Substring(l, 1));
                    }
                    else
                    {
                        evennum += int.Parse(code3.Substring(l, 1));
                    }
                }
                basenum = basenum % 11;
                evennum = evennum % 11;
                if (basenum == 10)
                {
                    basenum = 1;
                }
                if (evennum == 10)
                {
                    evennum = 9;
                }
                else if (evennum == 0)
                {
                    evennum = 8;
                }
                code3 += basenum.ToString() + evennum.ToString();
                #endregion
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp1 = _Code.GetCodeImage((!string.IsNullOrEmpty(dr["dcrono"].ToString())) ? dr["dcrono"].ToString() : "0", BarCode.Code128.Encode.Code128A);
                imgTemp1.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG1 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG1.ScaleToFit(200, 30);

                Chunk ck1 = new Chunk(IMG1, 0, 0); //图片可设置 偏移


                _Code = new BarCode.Code128();
                //如果條形碼顯示的內容過長的話,一定要注意設置的字體大小,字體過大,內容不會顯示
                _Code.ValueFont = new System.Drawing.Font("宋体", 18);
                System.Drawing.Bitmap imgTemp2 = _Code.GetCodeImage(code1, BarCode.Code128.Encode.Code128A);
                imgTemp2.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG2 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG2.ScaleToFit(200, 30);
                Chunk ck2 = new Chunk(IMG2, 0, 0); //图片可设置 偏移

                _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp3 = _Code.GetCodeImage(code2, BarCode.Code128.Encode.Code128A);
                imgTemp3.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG3 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG3.ScaleToFit(200, 30);
                Chunk ck3 = new Chunk(IMG3, 0, 0); //图片可设置 偏移

                _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 18);
                System.Drawing.Bitmap imgTemp4 = _Code.GetCodeImage(code3, BarCode.Code128.Encode.Code128A);
                imgTemp4.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG4 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG4.ScaleToFit(200, 30);
                Chunk ck4 = new Chunk(IMG4, 0, 0); //图片可设置 偏移


            #endregion
                if (i % 3 == 0 && i != 0)
                {
                    document.NewPage();
                }
                string stnm_1 = string.Empty;
                string stnm_2 = string.Empty;
                string stnm = dr["stnm"].ToString();
                if (dr["deliver_stno"].ToString().Length >= 1)
                {
                    switch (dr["deliver_stno"].ToString().Substring(0, 1))
                    {
                        case "F":
                            if (stnm.Length * 3 >= 6)
                            {
                                stnm_1 = stnm.Substring(0, 6 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(6 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 >= 6)
                                {
                                    stnm_2 = stnm.Substring(6 / 3, stnm.Length - 6 / 3);
                                }
                            }
                            break;
                        case "K":
                            if (stnm.Length * 3 >= 4)
                            {
                                stnm_1 = stnm.Substring(0, 4 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(2 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 > 2)
                                {
                                    stnm_2 = stnm.Substring(2 / 3, stnm.Length - 2 / 3);
                                }
                            }
                            break;
                        case "L":
                            if (stnm.Length * 3 >= 10)
                            {
                                stnm_1 = stnm.Substring(0, 10 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(9 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 >= 9)
                                {
                                    stnm_2 = stnm.Substring(9 / 3, stnm.Length - 9 / 3);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                PdfPTable totaltable = new PdfPTable(3);
                totaltable.WidthPercentage = 100;
                totaltable.SetWidths(new int[] { 40, 2, 58 });
                PdfPTable table = new PdfPTable(3);
                #region 左邊框
                table.SetWidths(new int[] { 25, 15, 60 });
                table.DefaultCell.DisableBorderSide(1);
                table.DefaultCell.DisableBorderSide(2);
                table.DefaultCell.DisableBorderSide(4);
                table.DefaultCell.DisableBorderSide(8);
                PdfPCell cell;
                font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["dcrono"].ToString(), font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("   提貨人:" + dr["delivery_name"].ToString(), font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(stnm_1 + "\n" + stnm_2, font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck1));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck2));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                //cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("廠商出貨編號:" + dr["deliver_id"].ToString(), font));
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("金額:" + dr["receivable"].ToString() + "元", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("吉甲地在地好物 www.gigade100.com", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("客服專線:(02) 2783-4997", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("若需退貨請消費者聯繫上述電子商務網站\n\n\n\n\n\n", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new PdfPCell(new Phrase("D10", font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell();
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                #endregion
                totaltable.AddCell(table);
                cell = new PdfPCell();
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(8);
                totaltable.AddCell(cell);
                #region 右邊
                table = new PdfPTable(6);
                table.SetWidths(new int[] { 20, 20, 37, 10, 1, 12 });
                table.DefaultCell.DisableBorderSide(1);
                table.DefaultCell.DisableBorderSide(2);
                table.DefaultCell.DisableBorderSide(4);
                table.DefaultCell.DisableBorderSide(8);
                table.DefaultCell.UseAscender = true;
                table.HorizontalAlignment = Element.ALIGN_CENTER;
                //table.AddCell(new Phrase(dr["order_payment"].ToString() == "20" ? "取貨付款" : "取貨不付款", font));
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["order_payment"].ToString() == "20" ? " 取貨付款" : " 取貨不付款", font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new PdfPCell(new Phrase("D10", font)));
                //cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase());
                if (dr["order_payment"].ToString() == "20")
                {
                    cell.Rowspan = 6;
                }
                else
                {
                    cell.Rowspan = 7;
                }
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                string delivery_name = string.Empty;
                for (int k = 0; k < dr["delivery_name"].ToString().Length; k++)
                {
                    delivery_name += dr["delivery_name"].ToString()[k] + "\n";
                }
                cell = new PdfPCell(new Phrase("吉\n甲\n地\n\n" + delivery_name, font));
                if (dr["order_payment"].ToString() == "20")
                {
                    cell.Rowspan = 6;
                }
                else
                {
                    cell.Rowspan = 7;
                }
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck3));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 5;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck4));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 5;
                table.AddCell(cell);

                if (dr["order_payment"].ToString() == "20")
                {
                    font = new iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    Phrase p = new Phrase("*應付金額:" + dr["receivable"].ToString() + "元*\n\n", font);
                    font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase("消費者簽名:____________________\n\n\n\n\n", font));
                    cell = new PdfPCell(p);
                    cell.Colspan = 5;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);

                }
                else
                {
                    Phrase p = new Phrase();
                    font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase(" *憑身分證件正本領貨*\n\n", font));
                    font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase(" 消費者簽名:____________________\n\n", font));
                    p.Add(new Phrase(" 消費者身分證末四碼\n", font));
                    cell = new PdfPCell(p);
                    cell.Colspan = 5;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);

                    PdfPTable stable = new PdfPTable(4);
                    stable.SetTotalWidth(new float[] { 20, 20, 20, 20 });
                    stable.DefaultCell.FixedHeight = 10;
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    //p.Add(new Phrase("請核對證件\n並  簽  名", font));
                    cell = new PdfPCell(stable);
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);
                    cell = new PdfPCell(new Phrase("請核對證件\n並  簽  名\n", font));
                    //cell.AddElement(new Phrase("請核對證件\n並  簽  名", font));
                    cell.Colspan = 4;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    cell.UseAscender = true;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell);

                }
                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                cell = new PdfPCell(new Phrase("\n門市結帳人員簽名:____________________", font));
                cell.Colspan = 5;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                string estimated_delivery_date = (!string.IsNullOrEmpty(dr["estimated_delivery_date"].ToString())) ? DateTime.Parse(dr["estimated_delivery_date"].ToString()).ToString("yyyy/MM/dd") : "";

                cell = new PdfPCell(new PdfPCell(new Phrase(dr["deliver_stno"].ToString(), font)));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(" " + estimated_delivery_date, font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                table.AddCell(cell);
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["dcrono"].ToString(), font)));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell);
                table.AddCell("");
                //cell = new PdfPCell(new Phrase("11111111111", font));
                //cell.Colspan = 5;
                //table.AddCell(cell);

                totaltable.AddCell(table);
                totaltable.SpacingAfter = 25f;
                #endregion
                document.Add(totaltable);
            }


            document.Close();

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);


        }
Ejemplo n.º 6
0
        /// <summary>
        /// 修改物流單號 出貨日期 出貨信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase DeliverDetailEdit()
        {
            string json = string.Empty;
            try
            {
                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                string deliver_id = Request.Params["deliver_id"];
                string delivery_store = string.Empty;
                string delivery_code = string.Empty;
                string delivery_date = string.Empty;
                string sms_date = string.Empty;
                bool success = false;
                if (!string.IsNullOrEmpty(Request.Params["delivery_store"]) && !string.IsNullOrEmpty(Request.Params["delivery_code"]))
                {
                    delivery_store = Request.Params["delivery_store"];
                    delivery_code = Request.Params["delivery_code"];
                    delivery_date = Request.Params["delivery_date"];
                    success = _DeliverDetailMgr.DeliveryCode(deliver_id, delivery_store, delivery_code, delivery_date, "0");
                    if (success)
                    {
                        json = "{success:true}";
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }
                else if (!string.IsNullOrEmpty(Request.Params["sms_date"]))
                {
                    Sms sms = new Sms();
                    sms.memo = deliver_id;
                    string smsid = _DeliverDetailMgr.GetSmsId(sms);
                    if (!string.IsNullOrEmpty(smsid))
                    {
                        int i = _DeliverDetailMgr.UpSmsTime(deliver_id, sms_date, smsid);
                        if (i > 0)
                        {
                            json = "{success:true}";
                        }
                        else
                        {
                            json = "{success:false}";
                        }
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }
                else
                {
                    DeliverMaster dm = new DeliverMaster();
                    int type = int.Parse(Request.Params["type"]);
                    dm.deliver_id = uint.Parse(deliver_id);
                    if (type == 1)
                    {
                        if (!string.IsNullOrEmpty(Request.Params["estimated_arrival_date"]))
                        {
                            dm.estimated_arrival_date = DateTime.Parse(Request.Params["estimated_arrival_date"]);
                        }
                        if (!string.IsNullOrEmpty(Request.Params["estimated_delivery_date"]))
                        {
                            dm.estimated_delivery_date = DateTime.Parse(Request.Params["estimated_arrival_date"]);
                        }
                        dm.estimated_arrival_period = int.Parse(Request.Params["estimated_arrival_period"]);
                        //dm.estimated_delivery_date = DateTime.Parse(Request.Params["estimated_delivery_date"]);

                    }
                    if (type == 2)
                    {
                        dm.delivery_name = Request.Params["delivery_name"];
                        dm.delivery_mobile = Request.Params["delivery_mobile"];
                        dm.delivery_phone = Request.Params["delivery_phone"];
                        dm.delivery_zip = uint.Parse(Request.Params["delivery_zip"]);
                        dm.delivery_address = Request.Params["delivery_address"];
                    }
                    int j = _DeliverDetailMgr.DeliverMasterEdit(dm, type);
                    if (j == 1)
                    {
                        json = "{success:true}";
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
Ejemplo n.º 7
0
        /// <summary>
        /// 订单出货明细
        /// </summary>
        public void GetOrderDetailsPDF()
        {
            string deliver_id = Request.Params["deliver_id"];
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable orderdeliver = _DeliverDetailMgr.GetOrderDelivers(deliver_id);
            Dictionary<string, string> dicproduct_freight_set = new Dictionary<string, string> { { "1", "1" }, { "2", "2" }, { "3", "1" }, { "4", "2" }, { "5", "5" }, { "6", "5" } };
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑

            string filename = "order_details_D" + deliver_id.PadLeft(8, '0') + ".pdf";
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();

            PdfContentByte cb = writer.DirectContent;

            if (orderdeliver.Rows.Count > 0)
            {
                #region 生成條形碼
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage("D" + orderdeliver.Rows[0]["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 30);
                IMG.SetAbsolutePosition(345, 740);
                #endregion

                cb.BeginText();
                cb.SetFontAndSize(bfChinese, 20);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地市集出貨明細", 30, 750, 0);
                //首購
                if (orderdeliver.Rows[0]["priority"].ToString() == "1")
                {
                    PdfPTable ot = new PdfPTable(1);
                    ot.SetTotalWidth(new float[] { 190 });
                    PdfPCell c = new PdfPCell(new Phrase("", font));
                    c.FixedHeight = 30;
                    c.BorderWidthBottom = 0.5f;
                    c.BorderWidthLeft = 0.5f;
                    c.BorderWidthRight = 0.5f;
                    c.BorderWidthTop = 0.5f;
                    ot.AddCell(c);
                    ot.WriteSelectedRows(0, -1, 29, 770, cb);
                }
                cb.AddImage(IMG);
                if (orderdeliver.Rows[0]["channel"].ToString() != "1")
                {
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["channel_name_simple"].ToString(), 80, 700, 0);
                }
                if (orderdeliver.Rows[0]["retrieve_mode"].ToString() == "1")
                {
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "7-11取貨", 200, 700, 0);
                }
                cb.SetFontAndSize(bfChinese, 10);
                string freight_set = string.Empty;
                switch (orderdeliver.Rows[0]["freight_set"].ToString().Trim())
                {
                    case "1":
                        freight_set = "常溫";
                        break;
                    case "2":
                        freight_set = "冷凍";
                        break;
                    case "5":
                        freight_set = "冷藏";
                        break;
                }
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, freight_set, 345, 785, 0);
                string estimated_arrival_period = string.Empty;
                if (orderdeliver.Rows[0]["estimated_arrival_period"].ToString() != "0")
                {
                    switch (orderdeliver.Rows[0]["estimated_arrival_period"].ToString().Trim())
                    {
                        case "0":
                            estimated_arrival_period = "不限時";
                            break;
                        case "1":
                            estimated_arrival_period = "12:00以前";
                            break;
                        case "2":
                            estimated_arrival_period = "12:00-17:00";
                            break;
                        case "3":
                            estimated_arrival_period = "17:00-20:00";
                            break;
                    }

                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, estimated_arrival_period, 345, 773, 0);
                }

            }
            cb.SetFontAndSize(bfChinese, 10);
            //cb.SetTextMatrix(150,20);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購人:", 10, 680, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收件人:", 200, 680, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款單號:", 10, 660, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收件地址:", 200, 660, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購時間:", 10, 640, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "聯絡電話:", 200, 640, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款時間:", 10, 620, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "假日可收貨:", 200, 620, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "出貨備註:", 10, 600, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂單明細:", 10, 580, 0);
            if (orderdeliver.Rows.Count > 0 && orderdeliver.Rows[0]["receivable"].ToString() != "0")
            {
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "應收金額:" + orderdeliver.Rows[0]["receivable"].ToString(), 200, 580, 0);
            }

            string address = string.Empty;
            string deliver_note = string.Empty;
            if (orderdeliver.Rows.Count > 0)
            {
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["order_name"].ToString(), 65, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["delivery_name"].ToString(), 250, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["order_id"].ToString(), 65, 660, 0);
                address += CommonFunction.ZipAddress(orderdeliver.Rows[0]["delivery_zip"].ToString()) + orderdeliver.Rows[0]["delivery_address"].ToString();

                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, address, 250, 660, 0);
                string order_createdate = orderdeliver.Rows[0]["order_createdate"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(orderdeliver.Rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "";
                string money_collect_date = orderdeliver.Rows[0]["money_collect_date"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(orderdeliver.Rows[0]["money_collect_date"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "";
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, order_createdate, 65, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["delivery_mobile"].ToString(), 250, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, money_collect_date, 65, 620, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["holiday_deliver"].ToString() == "1" ? "可" : "不可", 260, 620, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["note_order"].ToString().Trim(), 65, 600, 0);
                if (orderdeliver.Rows[0]["delivery_store"].ToString() == "12")
                {
                    deliver_note = "*自取(取貨地址:台北市南港區八德路4段768巷7號6樓之1,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                else if (orderdeliver.Rows[0]["delivery_store"].ToString() == "13")
                {
                    deliver_note = "*自取(取貨地址:新北市板橋區三民路二段33號21樓,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                else if (orderdeliver.Rows[0]["delivery_store"].ToString() == "14")
                {
                    deliver_note = "*自取(取貨地址:新北市永和區成功路一段80號20樓,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                cb.SetFontAndSize(bfChinese, 8);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliver_note, 65, 580, 0);
            }
            cb.EndText();
            PdfPTable ptable = new PdfPTable(7);
            ptable.WidthPercentage = 98;
            ptable.SetTotalWidth(new float[] { 50, 280, 50, 50, 50, 50, 50 });
            PdfPCell cell;
            font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            cell = new PdfPCell(new Phrase("商品編號", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("商品名稱", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("托運單屬性", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("數量", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("本次出貨", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("預計出貨日", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("供應商自出", font));
            cell.DisableBorderSide(2);
            ptable.AddCell(cell);
            PdfPCell td;
            string lastdeliverid = "0";
            ArrayList normal = new ArrayList();
            ArrayList low = new ArrayList();
            ArrayList lowstore = new ArrayList();
            DataRow[] sinceorder = new DataRow[] { };

            DataRow[] singleproduct = new DataRow[] { };//單一商品
            DataRow[] fatherproduct = new DataRow[] { };//組合商品中的父商品
            DataRow[] sonproduct = new DataRow[] { };//組合商品中的子商品
            ArrayList combine = new ArrayList();
            List<DataRow[]> orderdelivers = new List<DataRow[]>();

            sinceorder = orderdeliver.Select("dtype=2 and combined_mode<=1 ", "item_id asc");//自出商品
            singleproduct = orderdeliver.Select("dtype <>2 and combined_mode<=1  ", "item_id asc");//單一商品
            if (singleproduct.Count() > 0)
            {
                orderdelivers.Add(singleproduct);
            }
            fatherproduct = orderdeliver.Select(" combined_mode>1 and item_mode=1", "item_id asc");//組合商品中父商品是否存在
            foreach (var item in fatherproduct)
            {
                combine.Add(item);
                sonproduct = orderdeliver.Select(" combined_mode>1 and item_mode<>1 and parent_id=" + item["parent_id"] + " and pack_id=" + item["pack_id"], "item_id asc");//對應組合商品中的子商品
                foreach (var son in sonproduct)
                {
                    son["buy_num"] = (int.Parse(son["buy_num"].ToString()) * int.Parse(son["parent_num"].ToString())).ToString();
                    combine.Add(son);
                }
            }
            if (combine.Count > 0)
            {
                orderdelivers.Add((DataRow[])combine.ToArray(typeof(DataRow)));
            }
            //區分常溫、冷凍、冷藏
            foreach (var item in orderdelivers)
            {
                foreach (var row in item)
                {
                    string s = row["product_freight_set"].ToString();
                    switch (row["product_freight_set"].ToString())
                    {
                        case "1":
                        case "3":
                            normal.Add(row);//常溫
                            break;
                        case "2":
                        case "4":
                            low.Add(row);//冷凍
                            break;
                        case "5":
                        case "6":
                            lowstore.Add(row);//冷藏
                            break;
                        default:
                            break;
                    }
                }
            }

            orderdelivers = new List<DataRow[]>();
            if (normal.Count > 0)
            {
                orderdelivers.Add((DataRow[])normal.ToArray(typeof(DataRow)));
            }
            if (low.Count > 0)
            {
                orderdelivers.Add((DataRow[])low.ToArray(typeof(DataRow)));
            }
            if (lowstore.Count > 0)
            {
                orderdelivers.Add((DataRow[])lowstore.ToArray(typeof(DataRow)));
            }
            if (sinceorder.Count() > 0)
            {
                orderdelivers.Add(sinceorder);
            }
            int j = 0;
            foreach (var item in orderdelivers)
            {
                j++;
                for (int i = 0; i < item.Count(); i++)
                {
                    if (item[i]["ddeliver_id"].ToString() != lastdeliverid || i == 0)
                    {
                        lastdeliverid = item[i]["ddeliver_id"].ToString();//以一個出貨單號為界限
                        if (lastdeliverid != "0" || i == 0)
                        {
                            td = new PdfPCell();
                            td.Colspan = 7;
                            td.DisableBorderSide(2);
                            td.DisableBorderSide(4);
                            td.DisableBorderSide(8);
                            //td.BorderWidthTop = 0.2f;
                            ptable.AddCell(td);
                        }
                    }
                    string item_id = string.Empty;
                    if (item[i]["item_mode"].ToString() == "1")
                    {
                        item_id = item[i]["parent_id"].ToString();
                    }
                    else
                    {
                        item_id = item[i]["item_id"].ToString();
                    }
                    font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    td = new PdfPCell(new Phrase(item_id, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    string datacontent = ((item[i]["product_mode"].ToString() == "2" && item[i]["item_mode"].ToString() != "1") ? "*" : " ") + item[i]["brand_name"].ToString() + "-" + item[i]["product_name"].ToString() + item[i]["product_spec_name"].ToString();
                    if (item[i]["combined_mode"].ToString() != "0" && item[i]["item_mode"].ToString() == "2")
                    {
                        datacontent = "  " + datacontent;
                    }
                    td = new PdfPCell(new Phrase(datacontent, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    ptable.AddCell(td);
                    string value = string.Empty;
                    string freight_set = string.Empty;
                    if (dicproduct_freight_set.TryGetValue(item[i]["product_freight_set"].ToString(), out value))
                    {

                    }
                    switch (value)
                    {
                        case "1":
                            freight_set = "常溫";
                            break;
                        case "2":
                            freight_set = "冷凍";
                            break;
                        case "5":
                            freight_set = "冷藏";
                            break;
                    }
                    td = new PdfPCell(new Phrase(freight_set, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    td = new PdfPCell(new Phrase(item[i]["item_mode"].ToString() != "1" ? item[i]["buy_num"].ToString() : "", font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    // td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    td = new PdfPCell();
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    td = new PdfPCell();
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);

                    Image image = Image.GetInstance(Server.MapPath("../Content/img/icons/mark.png"));
                    image.ScalePercent(5, 5);
                    if (item[i]["dtype"].ToString() == "2")
                    {
                        td = new PdfPCell(image, false);
                    }
                    else
                    {
                        td = new PdfPCell();
                    }
                    td.HorizontalAlignment = Element.ALIGN_CENTER;
                    td.VerticalAlignment = Element.ALIGN_MIDDLE;
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    ptable.AddCell(td);
                }
            }
            string note_order = orderdeliver.Rows.Count.ToString() != "0" ? orderdeliver.Rows[0]["note_order"].ToString().Trim() : "";
            cell = new PdfPCell(new Phrase(new Chunk("備註:" + note_order, font)));
            cell.Colspan = 7;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            ptable.AddCell(cell);
            PdfPTable nulltable = new PdfPTable(2);
            nulltable.SetWidths(new int[] { 20, 20 });
            nulltable.DefaultCell.DisableBorderSide(1);
            nulltable.DefaultCell.DisableBorderSide(2);
            nulltable.DefaultCell.DisableBorderSide(4);
            nulltable.DefaultCell.DisableBorderSide(8);
            nulltable.AddCell("");
            nulltable.AddCell("");
            nulltable.SpacingAfter = 250;
            document.Add(nulltable);
            ptable.SpacingAfter = 50;
            document.Add(ptable);

            font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("吉甲地市集網路平台購物發票說明:\n", font));
            font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("若您訂購時未選擇開立三聯式發票,平台一律開立電子發票。\n", font));
            document.Add(new Phrase("發票將於該筆訂單商品完全出貨之後第10天開立並以E-Mail通知您。\n", font));
            document.Add(new Phrase("如需紙本發票請來信客服中心,會計部門將會依需求將電子發票印出並以平信郵寄約2~7個工作天內送達。\n", font));
            document.Add(new Phrase("託管發票將會在單月26日進行對獎作業後,系統將會發信通知中獎發票持有人,\n", font));
            document.Add(new Phrase("且為保障您的權益,我們將在七個工作天內,以掛號方式把中獎發票寄給您。\n", font));
            font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("祝您購物愉快!", font));
            document.Close();
            writer.Resume();

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 下一次出貨
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase Split()
        {
            string json = string.Empty;
            try
            {
                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                string deliver_id = Request.Params["deliver_id"];
                string detail_ids = Request.Params["detail_ids"];
                string[] detailids = detail_ids.Split(',');
                string newdeliverid = _DeliverDetailMgr.Split(deliver_id, detailids);
                if (!string.IsNullOrEmpty(newdeliverid))
                {
                    json = "{success:true,msg:" + newdeliverid + "}";
                }
                else
                {
                    json = "{success:false:msg:}";
                }


            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false:msg:}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
Ejemplo n.º 9
0
        /// <summary>
        /// 未到貨
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase LackDelivery()
        {
            string json = string.Empty;
            try
            {
                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                string deliver_id = Request.Params["deliver_id"];
                string detail_id = Request.Params["detail_id"];
                bool success = _DeliverDetailMgr.NoDelivery(deliver_id, detail_id);
                if (success == true)
                {
                    json = "{success:true}";
                }
                else
                {
                    json = "{success:false}";
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
Ejemplo n.º 10
0
 /// <summary>
 /// 獲取出貨信息
 /// </summary>
 /// <returns></returns>
 public HttpResponseBase GetDeliverMaster()
 {
     string json = String.Empty;
     List<DeliverMasterQuery> store = new List<DeliverMasterQuery>();
     DeliverMasterQuery query = new DeliverMasterQuery();
     try
     {
         _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
         if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
         {
             query.deliver_id = uint.Parse(Request.Params["deliver_id"]);
         }
         store = _DeliverDetailMgr.GetDeliverMaster(query);
         IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
         //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
         timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         json = "{success:true,data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false,data:[]}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 獲取grid的數據
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase GetDeliverDetail()
        {
            string json = String.Empty;
            StringBuilder sb = new StringBuilder();
            List<DeliverDetailQuery> store = new List<DeliverDetailQuery>();
            List<DeliverDetailQuery> cancel = new List<DeliverDetailQuery>();//取消狀態列表
            List<DeliverDetailQuery> newstore = new List<DeliverDetailQuery>();//去掉組合商品中的父商品
            DeliverDetailQuery query = new DeliverDetailQuery();
            try
            {

                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量
                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
                {
                    query.deliver_id = uint.Parse(Request.Params["deliver_id"]);
                }
                store = _DeliverDetailMgr.GetDeliverDetail(query);
                uint[] cancelstatus = { 5, 89, 90, 91, 92 };//取消
                IList cstatus = (IList)cancelstatus;
                foreach (var item in store)
                {
                    if (item.item_mode != 1)
                    {
                        newstore.Add(item);
                        if (cstatus.Contains(item.detail_status))
                        {
                            cancel.Add(item);
                        }

                    }
                }
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd";
                json = "{success:true,normaldata:" + JsonConvert.SerializeObject(newstore, Formatting.Indented, timeConverter) + ",canceldata:" + JsonConvert.SerializeObject(cancel, Formatting.Indented, timeConverter) + "}";//返回json數據

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Ejemplo n.º 12
0
        public void GetWaybillsXls()
        {
            if (!string.IsNullOrEmpty(Request.Params["ticket_id"]))
            {
                string strTemp = Request.Params["ticket_id"].ToString();
                strTemp = strTemp.Remove(strTemp.LastIndexOf(','));

                string newPDFName = string.Empty;
                int iTemp = 0;
                if (int.TryParse(strTemp, out iTemp))
                {
                    newPDFName = "waybills_T" + strTemp.PadLeft(8, '0').ToString() + ".xls";
                }
                else
                {
                    string ss = strTemp.Substring(0, strTemp.IndexOf(','));
                    newPDFName = "waybills_T" + ss.PadLeft(8, '0').ToString() + ".xls";
                }

                _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
                DataTable dt = _DeliverDetailMgr.GetWayBills(null, strTemp);
                DataTable dtTemp = new DataTable();
                dtTemp.Columns.Add("訂單編號", typeof(String));
                dtTemp.Columns.Add("收件人姓名", typeof(String));
                dtTemp.Columns.Add("收件人電話", typeof(String));
                dtTemp.Columns.Add("收件人手機", typeof(String));
                dtTemp.Columns.Add("收件人地址", typeof(String));
                dtTemp.Columns.Add("出貨日期\nYYYYMMDD", typeof(String));
                dtTemp.Columns.Add("預定配達日期\n YYYYMMDD", typeof(String));
                dtTemp.Columns.Add("預定配達時段\n (1:中午前~2:12-17時~3:17-20時~4:不指定~5:20-21時)", typeof(String));
                dtTemp.Columns.Add("品名", typeof(String));
                dtTemp.Columns.Add("代收貨款", typeof(String));
                dtTemp.Columns.Add("溫層\n (1:常溫~2:冷藏~3:冷凍)", typeof(String));
                dtTemp.Columns.Add("距離\n  (0:同縣市~1:外縣市~2:離島)", typeof(String));
                dtTemp.Columns.Add("規格\n  (1:60cm~2:90cm~3:120cm~4:150cm)", typeof(String));
                dtTemp.Columns.Add("易碎 \n  (Y~N)", typeof(String));
                dtTemp.Columns.Add("精密 \n  (Y~N)", typeof(String));
                dtTemp.Columns.Add("備註", typeof(String));
                dtTemp.Columns.Add("假日可出貨", typeof(String));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dtTemp.NewRow();
                    dr[0] = dt.Rows[i]["order_id"];
                    dr[1] = dt.Rows[i]["delivery_name"];
                    dr[2] = dt.Rows[i]["delivery_mobile"];

                    dr[3] = dt.Rows[i]["delivery_phone"];
                    dr[4] = CommonFunction.ZipAddress(dt.Rows[i]["delivery_zip"].ToString()) + dt.Rows[i]["delivery_address"].ToString();

                    dr[5] = DateTime.Now.ToString("yyyy-MM-dd");

                    dr[7] = dt.Rows[i]["estimated_arrival_period"];
                    if (dt.Rows[i]["estimated_arrival_period"].ToString() == "2")
                    {
                        dr[8] = "冷凍食品";
                    }

                    dr[9] = dt.Rows[i]["receivable"];
                    dr[10] = dt.Rows[i]["freight_set"];
                    dr[15] = dt.Rows[i]["note_order"];
                    dr[16] = dt.Rows[i]["holiday_deliver"].ToString() == "1" ? "是" : "否";
                    dtTemp.Rows.Add(dr);
                }

                MemoryStream ms = ExcelHelperXhf.ExportDT(dtTemp, "");
                //Response.Clear();
                //Response.Charset = "gb2312";
                //Response.ContentEncoding = System.Text.Encoding.UTF8;
                // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + newPDFName);
                Response.BinaryWrite(ms.ToArray());
            }
        }