Esempio n. 1
0
 public static LTS.Sale GetSaleItemByID(int?SaleID)
 {
     LTS.Sale sale = new LTS.Sale();
     try
     {
         using (LTS.LTSBase access = new LTS.LTSDC())
         {
             sale = access.Sale.Where(o => o.SaleID == SaleID).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
     }
     return(sale);
 }
Esempio n. 2
0
        public static int AddSale(LTS.Sale sale)
        {
            int?SaleID = -1;

            try
            {
                using (LTS.LTSBase access = new LTS.LTSDC())
                {
                    access.InsertSale(sale.CustID, sale.EmpID, sale.Paid, sale.SaleDate, sale.StockID, ref SaleID);
                }
            }
            catch (Exception ex)
            {
            }
            return(SaleID.Value);
        }
Esempio n. 3
0
        public static bool UpdateSale(LTS.Sale sale)
        {
            bool completed = false;

            try
            {
                using (LTS.LTSBase access = new LTS.LTSDC())
                {
                    access.UpdateSale(sale.CustID, sale.EmpID, sale.Paid, sale.SaleDate, sale.StockID, sale.SaleID);
                    completed = true;
                }
            }
            catch (Exception ex)
            {
                completed = false;
            }
            return(completed);
        }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool edit;


            if (dataGridView1.SelectedRows == null)
            {
                label15.Visible = true;
            }
            else
            {
                if (comboBoxp.SelectedItem == null)
                {
                    label15.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();
                    s.Paid = Convert.ToBoolean(comboBoxp.SelectedItem.ToString());
                    edit   = DAT.DataAccess.UpdateSale(s);
                    if (edit)
                    {
                        if (DialogResult.OK == MessageBox.Show("Sale item edited successfully!"))
                        {
                            ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                        }
                    }
                    else
                    {
                        if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale item was not edited successfully!"))
                        {
                            ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                        }
                    }
                }
            }
        }
Esempio n. 5
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;
                }
            }
        }
Esempio n. 6
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;
                }
            }
        }
        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;
                    }
                }
            }
        }