private void btn_OdrClr_Click(object sender, EventArgs e)
 {
     txt_OsupId.Text    = null;
     txt_OsupName.Text  = null;
     txt_OsupEmail.Text = null;
     cmb_ItemType.Text  = null;
     txt_qty.Text       = null;
     txt_qty2.Text      = null;
     txt_ItemType.Text  = null;
     Picker_ReqDate.ResetText();
     datagrid_add.Rows.Clear();
     datagrid_add.ClearSelection();
     grid_IdNameItem.ClearSelection();
     lb_SelectSup.Visible = true;
 }
 private void btn_OdrClr_Click(object sender, EventArgs e)
 {
     txt_OcltId.Text      = null;
     txt_OcltName.Text    = null;
     txt_OcltAdd.Text     = null;
     txt_OcltEmail.Text   = null;
     txt_CintContact.Text = null;
     cmb_ProType.Text     = null;
     cmb_ftype.Text       = null;
     cmb_Brand.Text       = null;
     cmb_Design.Text      = null;
     cmb_size.Text        = null;
     cmb_color.Text       = null;
     txt_qty.Text         = null;
     txt_odrTot.Text      = null;
     Picker_ReqDate.ResetText();
     datagrid_add.Rows.Clear();
     datagrid_add.ClearSelection();
     grid_IdNameItem.ClearSelection();
     lb_SelectClt.Visible = true;
 }
        private void btn_CreOdr_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txt_odrTot.Text))
                {
                    MessageBox.Show("You must get Order Total", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Picker_ReqDate.Value.Date == DateTime.Today.Date)
                {
                    MessageBox.Show("You must select a Date", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Picker_ReqDate.Value.Date <= DateTime.Today.Date)
                {
                    MessageBox.Show("You must select a Future Date", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (string.IsNullOrEmpty(txt_OcltId.Text))
                {
                    MessageBox.Show("You must select a Client", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    SalesOrderDBaccess SO = new SalesOrderDBaccess();

                    SaleMaster SM = new SaleMaster();
                    SM.sale_id    = txt_SOno.Text;
                    SM.clt_id     = txt_OcltId.Text;
                    SM.sale_date  = Picker_ReqDate.Value.Date;
                    SM.sale_total = Convert.ToInt32(txt_odrTot.Text);

                    int Status = SO.createSale_master(SM);
                    if (Status == 1)
                    {
                        MetroMessageBox.Show(this, "\n\nOrder Created succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "\n\nOrder Creation Fail", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    grid_Sales.DataSource = SO.getSalesOrders();
                    txt_SOno.Text         = SO.GetSaleId();

                    txt_OcltId.Text      = null;
                    txt_OcltName.Text    = null;
                    txt_OcltAdd.Text     = null;
                    txt_OcltEmail.Text   = null;
                    txt_CintContact.Text = null;
                    cmb_ProType.Text     = null;
                    cmb_ftype.Text       = null;
                    cmb_Brand.Text       = null;
                    cmb_Design.Text      = null;
                    cmb_size.Text        = null;
                    cmb_color.Text       = null;
                    txt_qty.Text         = null;
                    txt_odrTot.Text      = null;
                    Picker_ReqDate.ResetText();
                    datagrid_add.Rows.Clear();
                    datagrid_add.ClearSelection();
                    grid_IdNameItem.ClearSelection();
                    lb_SelectClt.Visible = true;
                }

                // PurDetails PD = new PurDetails();
                // PD.pd_id =
            }
            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_CreOdr_Click(object sender, EventArgs e)
        {
            try
            {
                if (datagrid_add.Rows.Count == 1)
                {
                    MetroMessageBox.Show(this, "Add Items Before proceed", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    PurchaseOrderDBaccess PO = new PurchaseOrderDBaccess();

                    PurMaster PM = new PurMaster();
                    PM.pur_id   = txt_POno.Text;
                    PM.sup_id   = txt_OsupId.Text;
                    PM.pur_date = Picker_ReqDate.Value.Date;

                    int Status = PO.createPurOrder_master(PM);
                    if (Status == 1)
                    {
                        MetroMessageBox.Show(this, "\n\nOrder Success, And Sending For Approvel", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txt_OsupId.Text    = null;
                        txt_OsupName.Text  = null;
                        txt_OsupEmail.Text = null;
                        cmb_ItemType.Text  = null;
                        txt_qty.Text       = null;
                        txt_qty2.Text      = null;
                        txt_ItemType.Text  = null;
                        Picker_ReqDate.ResetText();
                        datagrid_add.Rows.Clear();
                        datagrid_add.ClearSelection();
                        grid_IdNameItem.ClearSelection();
                        lb_SelectSup.Visible = true;
                        txt_POno.Text        = PO.GetPurId();
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "\n\nOrder Fail", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // PurDetails PD = new PurDetails();
                    // PD.pd_id =

                    for (int i = 0; i < (datagrid_add.Rows.Count - 1); i++)
                    {
                        PurDetails PD = new PurDetails();
                        PD.pd_id        = PO.GetPDId();
                        PD.pur_id       = txt_POno.Text;
                        PD.pd_Item_type = (datagrid_add.Rows[i].Cells["Item"].Value).ToString();
                        PD.Size         = (datagrid_add.Rows[i].Cells["Size"].Value).ToString();
                        PD.color        = (datagrid_add.Rows[i].Cells["Color"].Value).ToString();
                        PD.pd_qty       = (datagrid_add.Rows[i].Cells["Qty"].Value).ToString();

                        int status = PO.createPurOrder_details(PD);
                    }
                    PurchaseOrderDBaccess Po = new PurchaseOrderDBaccess();
                    Grid_PurchaseOrder.DataSource = Po.getAllPurchaseOrders();
                }
            }
            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);
            }
        }