private void btn_reg_Click(object sender, EventArgs e)
 {
     try
     {
         listpanel[index = 0].BringToFront();
         //Get last record from Client
         ClientDBaccess CA = new ClientDBaccess();
         txt_CltId.Text = CA.GetClientId();
     }
     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 grid_AppOdr_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         ClientDBaccess CA    = new ClientDBaccess();
         String         cltId = grid_AppOdr.CurrentRow.Cells["clt_id"].Value.ToString();
         if (CA.getOrdrClients(cltId).Rows.Count != 0)
         {
             DataRow dr = CA.getOrdrClients(cltId).Rows[0];
             txt_OrderClientEmail.Text   = dr["clt_email"].ToString();
             txt_OrderClientContact.Text = dr["clt_cont"].ToString();
         }
     }
     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 SalesOrderForm_Load(object sender, EventArgs e)
        {
            try
            {
                listpanel.Add(panel_reg);
                listpanel.Add(panel_order);
                listpanel.Add(panel_delivery);
                listpanel.Add(panel_disply);
                listpanel.Add(Panel_AppOdr);
                listpanel[index].BringToFront();
                listpanel[index = 3].BringToFront();

                ClientDBaccess CA = new ClientDBaccess();
                grid_IdNameItem.DataSource = CA.getAllClients();
            }
            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);
            }
        }
 public SalesOrderForm()
 {
     try
     {
         InitializeComponent();
         ClientDBaccess CA = new ClientDBaccess();
         DataTable      dt = CA.getAllClients();
         Grid_clt.DataSource = dt;
     }
     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_Order_Click(object sender, EventArgs e)
        {
            try
            {
                listpanel[index = 1].BringToFront();
                //Hide other text boxes when first time open

                SalesOrderDBaccess So = new SalesOrderDBaccess();
                ClientDBaccess     CA = new ClientDBaccess();
                grid_IdNameItem.DataSource = CA.getAllClients();
                grid_Sales.DataSource      = So.getSalesOrders();
                txt_SOno.Text = So.GetSaleId();
            }
            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);
            }
        }
Example #6
0
        private void fillClientChart()
        {
            try
            {
                DateTime date = DateTime.Today.Date;

                var firstDayOfMonth = new DateTime(date.Year, date.Month, 1).AddDays(-1);
                var lastDayOfMonth  = firstDayOfMonth.AddMonths(-1).AddDays(1);


                var firstDayOfMonth1 = lastDayOfMonth.AddDays(-1);
                var lastDayOfMonth1  = firstDayOfMonth.AddMonths(-2).AddDays(1);


                lb_cltFrom.Text = lastDayOfMonth.ToString("dd/MM/yyyy");
                lb_cltTo.Text   = firstDayOfMonth.ToString("dd/MM/yyyy");

                ReportDBaccess RD = new ReportDBaccess();
                DateTime       d1 = firstDayOfMonth.Date;
                DateTime       d2 = lastDayOfMonth.Date;
                DateTime       d3 = firstDayOfMonth1.Date;
                DateTime       d4 = lastDayOfMonth1.Date;

                ClientDBaccess CB = new ClientDBaccess();
                grid_Clientreport.DataSource = CB.getAllClients();
                grid_Clientreport.Columns.Add("Order_Placed", "Orders Placed");


                int x = 0;
                while (x < grid_Clientreport.RowCount - 1)
                {
                    grid_Clientreport.Rows[x].Cells["Order_Placed"].Value = RD.getClientcount(grid_Clientreport.Rows[x].Cells[0].Value.ToString(), d2, d1).Rows.Count.ToString();
                    x = x + 1;
                }

                int a = 0;
                chart3.Titles.Add("Client Orders");
                while (a < grid_Clientreport.RowCount - 1)
                {
                    chart3.Series["Client Orders"].Points.AddXY(grid_Clientreport.Rows[a].Cells[1].Value.ToString(), grid_Clientreport.Rows[a].Cells[5].Value.ToString());
                    a = a + 1;
                }

                int total = 0;
                for (int b = 0; b < grid_Clientreport.Rows.Count; b++)
                {
                    total += Convert.ToInt32(grid_Clientreport.Rows[b].Cells[5].Value);
                }
                lb_cltTot.Text = total.ToString();
                lb_cltnow.Text = total.ToString();
                int tot = 0;
                for (int b = 0; b < grid_Clientreport.Rows.Count - 1; b++)
                {
                    int[] y = new int[grid_Clientreport.Rows.Count];
                    y[b] = Convert.ToInt32(RD.getClientcount(grid_Clientreport.Rows[b].Cells[0].Value.ToString(), d4, d3).Rows.Count);
                    tot  = tot + y[b];
                }

                //int sum = Convert.ToInt32(RD.getClientcount(grid_Clientreport.Rows[x].Cells[0].Value.ToString(), d2, d1).Compute("SUM(Order_Placed)", string.Empty));
                lb_cltlast.Text = tot.ToString();

                lb_cltnext.Text = (Convert.ToInt32(total) + (Convert.ToInt32(total) - Convert.ToInt32(tot))).ToString();

                string pMonth  = DateTime.Now.AddMonths(-1).ToString("MMMM");
                string pMonth1 = DateTime.Now.AddMonths(-2).ToString("MMMM");
                string pMonth2 = DateTime.Now.ToString("MMMM");
                lb_cltlastmonth.Text = pMonth1;
                lb_cltnowmonrh.Text  = pMonth;
                lb_cltNextmonth.Text = pMonth2;
            }
            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_CltReg_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txt_CltName.Text) || !Regex.Match(txt_CltName.Text, "^([A-Z]|[a-z])[a-zA-Z]*$").Success)
                {
                    MessageBox.Show("First Name Can Not Be Blank or Invalid Pattern, Please Check In That Field \nPlease Fill This Way => Pasan ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (string.IsNullOrEmpty(txt_CltAdd.Text) || !Regex.Match(txt_CltAdd.Text, @"^([A-Z]|[a-zA-Z]|[0-9])+(|[ ]+|[A-Z]+|[a-z]+|[0-9]+|[.-;-/])*$").Success)
                {
                    MessageBox.Show("Address Line Can Not Be Blank or Invalid Pattern, Please Check In That Field. \nPlease Fill This Way => No. 50/1/A ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (string.IsNullOrEmpty(txt_CltEmail.Text) || !Regex.Match(txt_CltEmail.Text, @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                                                 @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$").Success)
                {
                    MessageBox.Show("Invalid Email, Please Check In That Field \n( Example :- [email protected] )", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (string.IsNullOrEmpty(txt_CltContact.Text) || txt_CltContact.Text.Length > 0)
                {
                    if (!Regex.Match(txt_CltContact.Text, "^[0-9]*$").Success || txt_CltContact.Text.Length != 10)
                    {
                        MessageBox.Show("Invalid Mobile Number, Please Check In That Field \nPlease Fill This Way => 0766656326 ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    Client client = new Client(); // new Client object created and get values to variables
                    client.Clt_Id        = txt_CltId.Text.ToString();
                    client.Clt_Name      = txt_CltName.Text.ToString();
                    client.Clt_Address   = txt_CltAdd.Text.ToString();
                    client.Clt_Email     = txt_CltEmail.Text.ToString();
                    client.Clt_ContactNo = txt_CltContact.Text.ToString();

                    ClientDBaccess CA     = new ClientDBaccess();
                    int            Status = CA.createClient(client);
                    if (Status == 1)
                    {
                        MetroMessageBox.Show(this, "\n\nYou were registerd succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "\n\nRegistation Fail", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    DataTable dt = CA.getAllClients();
                    Grid_clt.DataSource = dt;
                }
            }
            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);
            }
        }