Ejemplo n.º 1
0
 protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         ImageButton imb = (ImageButton)sender;
         if (imb != null)
         {
             MasSender obj   = new MasSender();
             int       objID = ToInt32(imb.CommandArgument);
             using (BillingEntities cre = new BillingEntities())
             {
                 obj = cre.MasSenders.FirstOrDefault(w => w.SenderID.Equals(objID));
                 cre.MasSenders.Remove(obj);
                 cre.SaveChanges();
             };
             BindData();
         }
         else
         {
             SendMailError("imb is null", System.Reflection.MethodBase.GetCurrentMethod());
         }
     }
     catch (Exception ex)
     {
         ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
         SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
     }
 }
Ejemplo n.º 2
0
        protected void btnModalSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMSenderName.Text == "")
                {
                    ShowMessageBox("กรุณาระบุ ชื่อลูกค้า !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                MasSender o = new MasSender();
                if (hddMode.Value == "Add") // Add
                {
                    o             = new MasSender();
                    o.SenderName  = txtMSenderName.Text;
                    o.Tel         = txtMTel.Text;
                    o.CreatedBy   = GetUsername();
                    o.CreatedDate = DateTime.Now;
                    using (BillingEntities cre = new BillingEntities())
                    {
                        cre.MasSenders.Add(o);
                        cre.SaveChanges();
                    };
                }
                else //Edit
                {
                    int objID = ToInt32(hddID.Value);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        o = cre.MasSenders.FirstOrDefault(w => w.SenderID.Equals(objID));
                        if (o != null)
                        {
                            o.SenderName  = txtMSenderName.Text;
                            o.Tel         = txtMTel.Text;
                            o.UpdatedBy   = GetUsername();
                            o.UpdatedDate = DateTime.Now;
                        }
                        cre.SaveChanges();
                    };
                }

                BindData();
                ShowMessageBox("บันทึกข้อมูลสำเร็จ.");
            }
            catch (Exception ex)
            {
                ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
                SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
Ejemplo n.º 3
0
        protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton imb = (ImageButton)sender;
                MasSender   obj = new MasSender();
                if (imb != null)
                {
                    int objID = ToInt32(imb.CommandArgument);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        obj = cre.MasSenders.FirstOrDefault(w => w.SenderID.Equals(objID));
                    };

                    if (obj != null)
                    {
                        hddID.Value         = imb.CommandArgument;
                        txtMSenderName.Text = obj.SenderName;
                        txtMTel.Text        = obj.Tel;

                        ModalPopupExtender1.Show();
                        hddMode.Value = "Edit";
                    }
                    else
                    {
                        SendMailError("obj is null, objID = " + imb.CommandArgument, System.Reflection.MethodBase.GetCurrentMethod());
                    }
                }
                else
                {
                    SendMailError("imb is null", System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
                SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
Ejemplo n.º 4
0
        protected void ReportDeliveryExportPDF(List <SaleHeaderDTO> lst)
        {
            MemoryStream ms  = new MemoryStream();
            Document     doc = new Document(PageSize.A4, 3, 3, 3, 3);
            //var output = new FileStream(Server.MapPath(filename), FileMode.Create);
            var writer = PdfWriter.GetInstance(doc, ms);

            doc.Open();
            try
            {
                #region Variable
                BaseColor bc = new BaseColor(255, 255, 255);
                //string fontFamily = "C:/Windows/Fonts/Tahoma.ttf";
                string    fontFamily = Server.MapPath("~") + "Fonts\\CSChatThai.ttf";
                BaseFont  bf         = BaseFont.CreateFont(fontFamily, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                Font      fontBold   = new Font(bf, 15, iTextSharp.text.Font.BOLD);
                Font      fontNormal = new Font(bf, 15);
                PdfPTable table      = new PdfPTable(1);
                PdfPCell  cell1      = new PdfPCell();
                table.WidthPercentage = 99;
                PdfContentByte   pcbItemCode, pcbCOD;
                string           CODTextForm = "เก็บเงินปลายทาง \r\nจำนวนเงิน ";
                string           CODText = "", SenderName = "", SenderTel = "", ItemCode = "";
                int              i = 0, senderID = 0;
                int[]            lowerY = { 620, 350, 90 };
                int[]            upperY = { 650, 380, 120 };
                Rectangle        rect;
                List <MasSender> lstSen = new List <MasSender>();
                MasSender        Sen    = new MasSender();
                #endregion

                if (lst != null && lst.Count > 0)
                {
                    if (Session["ReportSaleDeliDDL"] != null)
                    {
                        lstSen   = (List <MasSender>)Session["ReportSaleDeliDDL"];
                        senderID = ToInt32(ddlSender.SelectedItem.Value);
                        Sen      = lstSen.FirstOrDefault(w => w.SenderID.Equals(senderID));
                        if (Sen != null)
                        {
                            SenderName = Sen.SenderName;
                            SenderTel  = Sen.Tel;
                        }
                    }

                    foreach (SaleHeaderDTO item in lst)
                    {
                        if (i > 0 && i % 3 == 0)
                        {
                            doc.Add(table);
                            doc.NewPage();
                            table = new PdfPTable(1);
                            table.WidthPercentage = 99;
                            i = 0;
                        }

                        AddTextToRow("  ", fontNormal, table);
                        AddTextToRow("  จัดส่ง :  " + item.Name, fontNormal, table);
                        AddTextToRow("  โทร :  " + item.Tel, fontNormal, table);
                        AddTextToRow("  ที่อยู่1 :  " + item.CustomerAddress, fontNormal, table);
                        AddTextToRow("  ที่อยู่2 :  " + item.CustomerDistrict + " " + item.CustomerCountry, fontNormal, table);
                        AddTextToRow("  ที่อยู่3 :  " + item.CustomerProvince + " " + item.CustomerPostalCode, fontNormal, table);
                        //AddTextToRow("ที่อยู่1 :  " + item.Add1, fontNormal, table);
                        //AddTextToRow("ที่อยู่2 :  " + item.Add2, fontNormal, table);
                        //AddTextToRow("ที่อยู่3 :  " + item.Add3, fontNormal, table);
                        AddTextToRow("  ผู้ส่ง :  " + SenderName, fontNormal, table);
                        AddTextToRow("  โทร.  " + SenderTel, fontNormal, table);

                        AddTextToRow("  ", fontNormal, table);
                        AddTextToRow("   ----------------------------------------------------------------------------------------------------", fontNormal, table);

                        //pcbItemCode = writer.DirectContent;
                        //PlaceText(pcbItemCode, item.ItemCode, fontBold, 300, lowerY[i], 550, upperY[i], 20, Element.ALIGN_CENTER);

                        pcbItemCode = writer.DirectContent;
                        if (item.dAmount > 1)
                        {
                            //ItemCode = item.ItemCode + "(" + item.dAmount + ")";
                            ItemCode = item.ItemCode + " * " + item.dAmount;
                        }
                        else
                        {
                            ItemCode = item.ItemCode;
                        }
                        PlaceText(pcbItemCode, ItemCode, fontBold, 300, lowerY[i], 550, upperY[i], 20, Element.ALIGN_CENTER);
                        rect = new Rectangle(300, lowerY[i], 550, upperY[i]);
                        pcbItemCode.SetColorStroke(BaseColor.BLACK);
                        pcbItemCode.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
                        pcbItemCode.Stroke();

                        if (!string.IsNullOrEmpty(item.COD) && item.COD == "1")
                        {
                            pcbCOD  = writer.DirectContent;
                            CODText = CODTextForm + item.SaleAmount.ToString("###,##0") + " บาท";
                            PlaceText(pcbCOD, CODText, fontBold, 300, lowerY[i] + 130, 550, upperY[i] + 150, 20, Element.ALIGN_CENTER);
                            rect = new Rectangle(300, lowerY[i] + 130, 550, upperY[i] + 150);
                            pcbCOD.SetColorStroke(BaseColor.BLACK);
                            pcbCOD.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
                            pcbCOD.Stroke();
                        }

                        i++;
                    }
                    doc.Add(table);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                doc.Close();
                writer.Close();
            }

            string filename = "ReportSaleDelivery_" + DateTime.Now.ToString("yyyyMMdd");
            Response.Clear();
            Response.Buffer          = false;
            Response.ContentEncoding = Encoding.UTF8;
            Response.HeaderEncoding  = Encoding.UTF8;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".pdf");
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(ms.ToArray());
            Response.Flush();
            Response.SuppressContent = true;
        }