private void btn_Receive_Click(object sender, EventArgs e)
 {
     try
     {
         listpanel[index = 2].BringToFront();
         String status            = "Placed";
         PurchaseOrderDBaccess Po = new PurchaseOrderDBaccess();
         grid_RecOrds.DataSource = Po.getSpecialPurchaseOrders(status);
     }
     catch (SqlException)
     {
         MetroMessageBox.Show(this, "\n\nConnecton Failed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (FormatException)
     {
         MetroMessageBox.Show(this, "\n\nInvalid Format", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (OutOfMemoryException)
     {
         MetroMessageBox.Show(this, "\n\nInsuffisent memory", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception)
     {
         MetroMessageBox.Show(this, "\n\nERROR", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void btn_AppOdr_Click(object sender, EventArgs e)
 {
     try
     {
         listpanel[index = 4].BringToFront();
         String Sts = "Approved";
         PurchaseOrderDBaccess PO = new PurchaseOrderDBaccess();
         grid_AppOdr.DataSource = PO.getSpecialPurchaseOrders(Sts);
     }
     catch (SqlException)
     {
         MetroMessageBox.Show(this, "\n\nConnecton Failed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (FormatException)
     {
         MetroMessageBox.Show(this, "\n\nInvalid Format", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (OutOfMemoryException)
     {
         MetroMessageBox.Show(this, "\n\nInsuffisent memory", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception)
     {
         MetroMessageBox.Show(this, "\n\nERROR", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btn_NotRec_Click(object sender, EventArgs e)
        {
            try
            {
                PurchaseOrderDBaccess PO = new PurchaseOrderDBaccess();
                String status            = "Not Recieved";

                String PurId  = grid_AppOdr.CurrentRow.Cells["pur_id"].Value.ToString();
                int    Status = PO.UpdatePurchaseOrderStatus(PurId, status);
                if (Status == 1)
                {
                    MetroMessageBox.Show(this, "\n\nStatus Changed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MetroMessageBox.Show(this, "\n\nUpdate Status Fail", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                String Sts = "Placed";
                grid_AppOdr.DataSource = PO.getSpecialPurchaseOrders(Sts);
            }
            catch (SqlException)
            {
                MetroMessageBox.Show(this, "\n\nConnecton Failed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (FormatException)
            {
                MetroMessageBox.Show(this, "\n\nInvalid Format", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (OutOfMemoryException)
            {
                MetroMessageBox.Show(this, "\n\nInsuffisent memory", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "\n\nERROR", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btn_PlaceOrds_Click(object sender, EventArgs e)
        {
            try
            {
                PurchaseOrderDBaccess PO = new PurchaseOrderDBaccess();
                if (String.IsNullOrEmpty(txt_OrderSupEmail.Text) || String.IsNullOrEmpty(txt_OrderSupContact.Text))
                {
                    MetroMessageBox.Show(this, "\n\nPlease Select Approved Purchase Order To Place Order", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (rbn_byEmail.Checked == false && rbn_byContact.Checked == false)
                {
                    MetroMessageBox.Show(this, "\n\nPlease Select Communication Method To Place Order", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    String status = "Placed";

                    String PurId  = grid_AppOdr.CurrentRow.Cells["pur_id"].Value.ToString();
                    int    Status = PO.UpdatePurchaseOrderStatus(PurId, status);
                    if (Status == 1)
                    {
                        MetroMessageBox.Show(this, "\n\nOrder Is Placed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "\n\n Fail To Place", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    String Sts = "Approved";
                    grid_AppOdr.DataSource = PO.getSpecialPurchaseOrders(Sts);

                    if (rbn_byEmail.Checked)
                    {
                        try
                        {
                            MailMessage message = new MailMessage();
                            SmtpClient  smtp    = new SmtpClient();

                            message.From = new MailAddress("*****@*****.**");
                            message.To.Add(new MailAddress(txt_OrderSupEmail.Text));
                            message.Subject = "Order No " + grid_AppOdr.CurrentRow.Cells["pur_id"].Value.ToString();
                            message.Body    = "Your Order Is Placed";

                            smtp.Port                  = 587;
                            smtp.Host                  = "smtp.gmail.com";
                            smtp.EnableSsl             = true;
                            smtp.UseDefaultCredentials = false;
                            smtp.Credentials           = new NetworkCredential("*****@*****.**", "0763854323xyz");
                            smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            smtp.Send(message);
                            MetroMessageBox.Show(this, "\n\nE-mail Sent", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        catch (SqlException)
                        {
                            MetroMessageBox.Show(this, "\n\nConnecton Failed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        catch (FormatException)
                        {
                            MetroMessageBox.Show(this, "\n\nInvalid Format", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        catch (OutOfMemoryException)
                        {
                            MetroMessageBox.Show(this, "\n\nInsuffisent memory", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        catch (Exception)
                        {
                            MetroMessageBox.Show(this, "\n\nERROR", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch (SqlException)
            {
                MetroMessageBox.Show(this, "\n\nConnecton Failed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (FormatException)
            {
                MetroMessageBox.Show(this, "\n\nInvalid Format", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (OutOfMemoryException)
            {
                MetroMessageBox.Show(this, "\n\nInsuffisent memory", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "\n\nERROR", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }