コード例 #1
0
 public static LTS.Customer GetCustomerItemByID(int?CustomerID)
 {
     LTS.Customer customer = new LTS.Customer();
     try
     {
         using (LTS.LTSBase access = new LTS.LTSDC())
         {
             customer = access.Customer.Where(o => o.CustID == CustomerID).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
     }
     return(customer);
 }
コード例 #2
0
 private void comboBoxOldNameC_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBoxOldNameC.SelectedItem != null)
     {
         string       id = comboBoxOldNameC.SelectedItem.ToString();
         LTS.Customer c  = DAT.DataAccess.GetCustomer().Where(u => u.IDno == id).FirstOrDefault();
         oldNameC.Text    = c.Name;
         oldSurnameC.Text = c.Surname;
         oldCellC.Text    = c.CellNo;
         oldEmailC.Text   = c.Email;
         oldAddressC.Text = c.CustAddress;
     }
     else
     {
     }
 }
コード例 #3
0
        public static int AddCustomer(LTS.Customer customer)
        {
            int?CustomerID = -1;

            try
            {
                using (LTS.LTSBase access = new LTS.LTSDC())
                {
                    access.InsertCustomer(customer.CellNo, customer.CustAddress, customer.Email, customer.IDno, customer.Name, customer.Surname, ref CustomerID);
                }
            }
            catch (Exception ex)
            {
            }
            return(CustomerID.Value);
        }
コード例 #4
0
        public static bool UpdateCustomer(LTS.Customer customer)
        {
            bool completed = false;

            try
            {
                using (LTS.LTSBase access = new LTS.LTSDC())
                {
                    access.UpdateCustomer(customer.CellNo, customer.CustAddress, customer.Email, customer.IDno, customer.Name, customer.Surname, customer.CustID);
                    completed = true;
                }
            }
            catch (Exception ex)
            {
                completed = false;
            }
            return(completed);
        }
コード例 #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            label22.Visible      = false;
            richTextBox1.Visible = false;
            if (cEmail.Text == "" || cAddress.Text == "" || cCell.Text == "" || cName.Text == "" || cSurname.Text == "" || cID.Text == "")
            {
                label22.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                ///////////////////////CHECKS//////////////////
                bool           isEmail = Regex.IsMatch(cEmail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                bool           isCell  = Regex.IsMatch(cCell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                bool           name    = Regex.IsMatch(cName.Text, @"^[a-zA-Z ]+$");
                bool           sName   = Regex.IsMatch(cSurname.Text, @"^[a-zA-Z ]+$");
                IdentityNumber id      = new IdentityNumber(cID.Text);
                bool           IDVALID = id.IsValid;
                int            exist;
                if (oldcID == cID.Text)
                {
                    exist = 0;
                }
                else
                {
                    exist = DAT.DataAccess.GetCustomer().Where(i => i.IDno == cID.Text).ToList().Count;
                }



                //////////////////////CHECKS//////////////////
                if (!isEmail || !isCell || !name || !sName || !IDVALID || exist != 0)
                {
                    label22.Visible      = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    int custID;

                    using (DataGridViewRow item = this.dataGridView1.SelectedRows[0])
                    {
                        int i = item.Index;

                        string ID = dataGridView1.Rows[i].Cells[2].Value.ToString();


                        custID = DAT.DataAccess.GetCustomer().Where(o => o.IDno == ID).FirstOrDefault().CustID;
                    }
                    try
                    {
                        LTS.Customer newCust = new LTS.Customer();
                        newCust.CustID      = custID;
                        newCust.Name        = cName.Text;
                        newCust.Surname     = cSurname.Text;
                        newCust.IDno        = cID.Text;
                        newCust.CustAddress = cAddress.Text;
                        newCust.CellNo      = cCell.Text;
                        newCust.Email       = cEmail.Text;
                        bool updated = DAT.DataAccess.UpdateCustomer(newCust);
                        if (updated)
                        {
                            if (DialogResult.OK == MessageBox.Show("Customer information edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllCustomer1>();
                            }
                        }
                        else
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the customer information was not edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllCustomer1>();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }
コード例 #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false))
            {
                label22.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "")
                {
                    IdentityNumber iN      = new IdentityNumber(newIDC.Text);
                    bool           validID = iN.IsValid;
                    if (validID)
                    {
                        label22.Visible = false;
                        LTS.Customer c = new LTS.Customer();
                        c.Name        = NewNameC.Text;
                        c.Surname     = NewSurnameC.Text;
                        c.IDno        = newIDC.Text;
                        c.Email       = newEmailC.Text;
                        c.CellNo      = newCellC.Text;
                        c.CustAddress = newAddressC.Text;

                        int custID = DAT.DataAccess.AddCustomer(c);

                        if (custID != -1)
                        {
                            LTS.Sale s = new LTS.Sale();
                            s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                            s.SaleDate = DateTime.Now.Date;
                            s.CustID   = custID;

                            if (comboBoxp.SelectedItem.ToString() == "Yes")
                            {
                                s.Paid = true;
                            }
                            else
                            {
                                s.Paid = false;
                            }
                            s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int saleID  = DAT.DataAccess.AddSale(s);

                            if (saleID == -1)
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                            else
                            {
                                LTS.Stock res = new LTS.Stock();

                                res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                                res.VehicleStatus = "Sold";
                                bool updated = DAT.DataAccess.UpdateStock(res);
                                if (updated)
                                {
                                    if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                    }
                                }
                                else
                                {
                                    if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
                else if (radioButton2.Checked && oldNameC.Text != "" && oldSurnameC.Text != "" && comboBoxOldNameC.SelectedItem != null && oldCellC.Text != "" && oldEmailC.Text != "" && oldAddressC.Text != "")
                {
                    label22.Visible      = false;
                    richTextBox1.Visible = false;
                    LTS.Customer c = DAT.DataAccess.GetCustomer().Where(p => p.IDno == comboBoxOldNameC.SelectedItem.ToString()).FirstOrDefault();
                    c.Name        = oldNameC.Text;
                    c.Surname     = oldSurnameC.Text;
                    c.Email       = oldEmailC.Text;
                    c.CellNo      = oldCellC.Text;
                    c.CustAddress = oldAddressC.Text;

                    bool custID = DAT.DataAccess.UpdateCustomer(c);

                    if (custID)
                    {
                        LTS.Sale s = new LTS.Sale();
                        s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                        s.SaleDate = DateTime.Now.Date;
                        s.CustID   = c.CustID;

                        if (comboBoxp.SelectedItem.ToString() == "Yes")
                        {
                            s.Paid = true;
                        }
                        else
                        {
                            s.Paid = false;
                        }
                        s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                        int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                        int saleID  = DAT.DataAccess.AddSale(s);

                        if (saleID == -1)
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                            }
                        }
                        else
                        {
                            LTS.Stock res = new LTS.Stock();

                            res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                            res.VehicleStatus = "Sold";
                            bool updated = DAT.DataAccess.UpdateStock(res);
                            if (updated)
                            {
                                if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                            else
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                        }
                    }
                }

                else

                {
                    label22.Visible      = true;
                    richTextBox1.Visible = true;
                }
            }
        }
コード例 #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            label22.Visible      = false;
            richTextBox1.Visible = false;
            if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false))
            {
                label22.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "")
                {
                    ///////////////////////CHECKS//////////////////
                    bool           isEmail = Regex.IsMatch(newEmailC.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                    bool           isCell  = Regex.IsMatch(newCellC.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                    bool           name    = Regex.IsMatch(NewNameC.Text, @"^[a-zA-Z ]+$");
                    bool           sName   = Regex.IsMatch(NewSurnameC.Text, @"^[a-zA-Z ]+$");
                    IdentityNumber id      = new IdentityNumber(newIDC.Text);
                    bool           IDVALID = id.IsValid;
                    int            exist;
                    exist = DAT.DataAccess.GetCustomer().Where(i => i.IDno == newIDC.Text).ToList().Count;

                    //////////////////////CHECKS//////////////////
                    if (!isEmail || !isCell || !name || !sName || !IDVALID || exist != 0)
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                    else
                    {
                        LTS.Customer c = new LTS.Customer();
                        c.Name        = NewNameC.Text;
                        c.Surname     = NewSurnameC.Text;
                        c.IDno        = newIDC.Text;
                        c.Email       = newEmailC.Text;
                        c.CellNo      = newCellC.Text;
                        c.CustAddress = newAddressC.Text;

                        int custID = DAT.DataAccess.AddCustomer(c);

                        if (custID != -1)
                        {
                            LTS.Sale s = new LTS.Sale();
                            s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                            s.SaleDate = DateTime.Now.Date;
                            s.CustID   = custID;

                            if (comboBoxp.SelectedItem.ToString() == "Yes")
                            {
                                s.Paid = true;
                            }
                            else
                            {
                                s.Paid = false;
                            }
                            s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int saleID  = DAT.DataAccess.AddSale(s);

                            if (saleID == -1)
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                }
                            }
                            else
                            {
                                LTS.Stock res = new LTS.Stock();

                                res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                                res.VehicleStatus = "Sold";
                                bool updated = DAT.DataAccess.UpdateStock(res);
                                if (updated)
                                {
                                    if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                    }
                                }
                                else
                                {
                                    if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                    }
                                }
                            }
                        }
                    }
                }
                else if (radioButton2.Checked && oldNameC.Text != "" && oldSurnameC.Text != "" && comboBoxOldNameC.SelectedItem != null && oldCellC.Text != "" && oldEmailC.Text != "" && oldAddressC.Text != "")
                {
                    ///////////////////////CHECKS//////////////////
                    bool isEmail = Regex.IsMatch(oldEmailC.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                    bool isCell  = Regex.IsMatch(oldCellC.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                    bool name    = Regex.IsMatch(oldNameC.Text, @"^[a-zA-Z ]+$");
                    bool sName   = Regex.IsMatch(oldSurnameC.Text, @"^[a-zA-Z ]+$");


                    //////////////////////CHECKS//////////////////
                    if (!isEmail || !isCell || !name || !sName)
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                    else
                    {
                        richTextBox1.Visible = false;
                        label22.Visible      = false;
                        LTS.Customer c = DAT.DataAccess.GetCustomer().Where(p => p.IDno == comboBoxOldNameC.SelectedItem.ToString()).FirstOrDefault();
                        c.Name        = oldNameC.Text;
                        c.Surname     = oldSurnameC.Text;
                        c.Email       = oldEmailC.Text;
                        c.CellNo      = oldCellC.Text;
                        c.CustAddress = oldAddressC.Text;

                        bool custID = DAT.DataAccess.UpdateCustomer(c);

                        if (custID)
                        {
                            LTS.Sale s = new LTS.Sale();
                            s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                            s.SaleDate = DateTime.Now.Date;
                            s.CustID   = c.CustID;

                            if (comboBoxp.SelectedItem.ToString() == "Yes")
                            {
                                s.Paid = true;
                            }
                            else
                            {
                                s.Paid = false;
                            }
                            s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int saleID  = DAT.DataAccess.AddSale(s);

                            if (saleID == -1)
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                }
                            }
                            else
                            {
                                LTS.Stock res = new LTS.Stock();

                                res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                                res.VehicleStatus = "Sold";
                                bool updated = DAT.DataAccess.UpdateStock(res);
                                if (updated)
                                {
                                    if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                    }
                                }
                                else
                                {
                                    if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                    }
                                }
                            }
                        }
                    }
                }

                else

                {
                    label22.Visible      = true;
                    richTextBox1.Visible = true;
                }
            }
        }
コード例 #8
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool   edit;
            string oldVIN;

            if (dataGridView1.SelectedRows == null)
            {
                label15.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                if (comboBoxVINID.SelectedItem == null || dateTimePicker1.Value == null || comboBoxp.SelectedItem == null || comboBoxempID.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false))
                {
                    label15.Visible      = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    int      sID = DAT.DataAccess.GetStock().Where(i => i.VIN == dataGridView1.SelectedRows[0].Cells[0].Value.ToString()).FirstOrDefault().StockID;
                    LTS.Sale s   = new LTS.Sale();
                    s = DAT.DataAccess.GetSale().Where(i => i.StockID == sID).FirstOrDefault();
                    if (radioButton2.Checked && comboBoxcusID.SelectedItem != null)
                    {
                        if (s.StockID == DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID)
                        {
                        }
                        else
                        {
                            LTS.Stock old = DAT.DataAccess.GetStock().Where(u => u.StockID == s.StockID).FirstOrDefault();
                            old.VehicleStatus = "Available";
                            DAT.DataAccess.UpdateStock(old);
                            s.StockID = DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID;
                            LTS.Stock newer = DAT.DataAccess.GetStock().Where(u => u.StockID == s.StockID).FirstOrDefault();
                            newer.VehicleStatus = "Sold";
                            DAT.DataAccess.UpdateStock(newer);
                        }

                        s.SaleDate = dateTimePicker1.Value.Date;
                        s.Paid     = Convert.ToBoolean(comboBoxp.SelectedItem.ToString());
                        s.EmpID    = Convert.ToInt32(comboBoxempID.SelectedItem.ToString());
                        s.CustID   = DAT.DataAccess.GetCustomer().Where(o => o.IDno == comboBoxcusID.SelectedItem.ToString()).FirstOrDefault().CustID;
                        edit       = DAT.DataAccess.UpdateSale(s);

                        if (edit)
                        {
                            if (DialogResult.OK == MessageBox.Show("Sale item edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                            }
                        }
                        else
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                            }
                        }
                    }
                    else if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "")
                    {
                        s.StockID  = DAT.DataAccess.GetStock().Where(o => o.VIN == comboBoxVINID.SelectedItem.ToString()).FirstOrDefault().StockID;
                        s.SaleDate = dateTimePicker1.Value.Date;
                        s.Paid     = Convert.ToBoolean(comboBoxp.SelectedItem.ToString());
                        s.EmpID    = Convert.ToInt32(comboBoxempID.SelectedItem.ToString());
                        LTS.Customer c = new LTS.Customer();
                        c.Name        = NewNameC.Text;
                        c.Surname     = NewSurnameC.Text;
                        c.IDno        = newIDC.Text;
                        c.CellNo      = newCellC.Text;
                        c.Email       = newEmailC.Text;
                        c.CustAddress = newAddressC.Text;
                        int CID = DAT.DataAccess.AddCustomer(c);
                        if (CID == -1)
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!"))
                            {
                            }
                        }
                        else
                        {
                            s.CustID = CID;
                            edit     = DAT.DataAccess.UpdateSale(s);
                            if (edit)
                            {
                                if (DialogResult.OK == MessageBox.Show("Sale item edited successfully!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                }
                            }
                            else
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <AllSales1>();
                                }
                            }
                        }
                    }
                    else
                    {
                        label15.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }