Ejemplo n.º 1
0
        private void btn_placeOrder_Click(object sender, EventArgs e)
        {
            using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
            {
                MySqlCommand cmd;
                cmd = new MySqlCommand("UPDATE purchase_order SET Status='Placed' WHERE OrderID=@OrderID", mysqlCon);
                mysqlCon.Open();
                cmd.Parameters.AddWithValue("@OrderID", order_id);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Order Status Updated Successfully");

                if (txt_orderRef.Text != "")
                {
                    Document pdoc = new Document(PageSize.A4, 50f, 0f, 0f, 30f);

                    PdfWriter pWriter = PdfWriter.GetInstance(pdoc, new FileStream("C:/" + txt_orderRef.Text + ".pdf", FileMode.Create));
                    pdoc.Open();

                    System.Drawing.Image  PImage     = System.Drawing.Image.FromFile("C:\\ReportHeader.png");
                    iTextSharp.text.Image ItextImage = iTextSharp.text.Image.GetInstance(PImage, System.Drawing.Imaging.ImageFormat.Png);
                    ItextImage.Alignment = Element.ALIGN_CENTER;
                    pdoc.Add(ItextImage);

                    Paragraph address = new Paragraph("KHS2 Cnstructions (Pvt) Ltd ," + "\n" + "No: 01 ," + "\n" + "Dane's Plains ," + "\n" + "Katukurunda ," + "\n" + "Kaluthara North." + "\n");
                    address.Alignment = Element.ALIGN_LEFT;
                    pdoc.Add(address);

                    Paragraph heading = new Paragraph("\n" + "\n" + "Prchase Order Requisition" + "\n" + "\n");
                    heading.Alignment = Element.ALIGN_CENTER;
                    pdoc.Add(heading);

                    Paragraph para = new Paragraph("\n" + "Purchase Order Details are as of below. Please be kind enough to let us know if there are any information that should be modified." + "\n" + "\n" + "\n");
                    para.Alignment = Element.ALIGN_LEFT;
                    pdoc.Add(para);

                    Paragraph para1 = new Paragraph("Order Reference   :   " + txt_orderRef.Text + "\n" + "Construction Site   :   " + txt_site.Text + "\n" + "Order Material       :   " + txt_material.Text + "\n" + "Order Description  :   " + txt_des.Text + "\n" + "Supplier Name       :   " + txt_supplier.Text + "\n" + "Agreed Price          :   LKR. " + txt_amount.Text + "\n" + "Delivery Date        :  " + dtp_po.Value + "\n" + "\n");
                    para1.Alignment = Element.ALIGN_BASELINE;
                    pdoc.Add(para1);

                    Paragraph para2 = new Paragraph("\n" + "Thanks & Regards!" + "\n");
                    para2.Alignment = Element.ALIGN_LEFT;
                    pdoc.Add(para2);

                    System.Drawing.Image  PImage1     = System.Drawing.Image.FromFile("C:\\stamp.png");
                    iTextSharp.text.Image ItextImage1 = iTextSharp.text.Image.GetInstance(PImage1, System.Drawing.Imaging.ImageFormat.Png);
                    ItextImage1.Alignment = Element.ALIGN_LEFT;
                    pdoc.Add(ItextImage1);

                    pdoc.Close();
                    MessageBox.Show("Order Report Created Successfully.");
                }

                GridFill();
            }

            if (txt_orderRef.Text != "")
            {
                string userMail = null;
                using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
                {
                    mysqlCon.Open();
                    String          sql  = "SELECT Email FROM pml_user WHERE Username='******'";
                    MySqlCommand    mySc = new MySqlCommand(sql, mysqlCon);
                    MySqlDataReader myDr = mySc.ExecuteReader();

                    while (myDr.Read())
                    {
                        userMail = myDr.GetValue(0).ToString();
                    }
                }

                string Tomail = null;
                using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
                {
                    mysqlCon.Open();
                    String          sql  = "SELECT Email FROM suppliers WHERE name='" + txt_supplier.Text + "'";
                    MySqlCommand    mySc = new MySqlCommand(sql, mysqlCon);
                    MySqlDataReader myDr = mySc.ExecuteReader();

                    while (myDr.Read())
                    {
                        Tomail = myDr.GetValue(0).ToString();
                    }
                }

                string ccMail = null;
                using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
                {
                    mysqlCon.Open();
                    String          sql  = "SELECT Email FROM pml_user WHERE Username='******'";
                    MySqlCommand    mySc = new MySqlCommand(sql, mysqlCon);
                    MySqlDataReader myDr = mySc.ExecuteReader();

                    while (myDr.Read())
                    {
                        ccMail = myDr.GetValue(0).ToString();
                    }
                }

                Mail.userEmail  = userMail;
                Mail.toName     = Tomail;
                Mail.ccName     = ccMail;
                Mail.attachment = "C:\\" + txt_orderRef.Text + ".pdf";
                Mail.subject    = "Purchase Order Requisition";
                Mail.message    = "Please find the attached pdf file of order details of " + txt_material.Text + " Order No: " + txt_orderRef.Text + "\n" + "\n" + "Thanks & Regards!";
                Mail openMail = new Mail();
                openMail.Show();
            }

            else
            {
                MessageBox.Show("Please select an order to be placed");
            }
        }