Esempio n. 1
0
        private void btnSaveStaff_Click(object sender, EventArgs e)
        {
            CreateStaffFromForm();
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                try
                {
                    var staff = (from s in context.Staffs
                                 where (s.FirstName == currentStaff.FirstName && s.LastName == currentStaff.LastName)
                                 select s).First();

                    if (staff != null)
                    {
                        BindStaff(staff);
                    }
                }
                catch
                {
                    context.Staffs.AddObject(currentStaff);
                }
                finally
                {
                    context.SaveChanges();
                }

                BindStaffListBox();
                lbxStaff.SelectedItem = currentStaff;
                lbxStaff.Enabled      = true;
                DisableStaffFields();
            }
        }
Esempio n. 2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (DealershipManagerEntities context = new DealershipManagerEntities())
     {
         if (currentInsuranceBroker != null)
         {
             //It exists, find it, and edit it.
             InsuranceBroker insuranceBroker = (from insBroker in context.InsuranceBrokers
                                                where insBroker.BrokerId == currentInsuranceBroker.BrokerId
                                                select insBroker).FirstOrDefault();
             updateInsuranceBroker(insuranceBroker);
             context.SaveChanges();
             context.Connection.Close();
         }
         else
         {
             InsuranceBroker insuranceBroker = new InsuranceBroker();
             updateInsuranceBroker(insuranceBroker);
             context.InsuranceBrokers.AddObject(insuranceBroker);
             context.SaveChanges();
             context.Connection.Close();
         }
     }
     MessageBox.Show("Insurance Broker has been saved");
     customerForm.insuranceBrokerTableAdapter.Fill(customerForm.dealershipManagerDataSet.InsuranceBroker);
     customerForm.cboInsuranceBroker.SelectedItem = currentInsuranceBroker;
     customerForm.currentInsuranceBroker          = currentInsuranceBroker;
     customerForm.BindInsuranceBrokerToForm();
     this.Close();
 }
Esempio n. 3
0
        private void btnDeleteStaff_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this Staff Member?", "ALERT", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (DealershipManagerEntities context = new DealershipManagerEntities())
                {
                    var staff = (from s in context.Staffs
                                 where s.Id == currentStaff.Id
                                 select s).First();

                    context.Staffs.DeleteObject(staff);
                    context.SaveChanges();
                }
            }
            ;
            BindStaffListBox();
            DisableStaffFields();
        }
Esempio n. 4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this contact?", "ALERT", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (DealershipManagerEntities context = new DealershipManagerEntities())
                {
                    var contact = (from c in context.Contacts
                                   where c.Id == currentContact.Id
                                   select c).First();

                    context.Contacts.DeleteObject(contact);
                    context.SaveChanges();
                }
            }
            ;
            BindContactsListBox();
            DisableContactFields();
        }
Esempio n. 5
0
 public InsuranceBrokerForm(int brokerId)
 {
     InitializeComponent();
     using (DealershipManagerEntities context = new DealershipManagerEntities())
     {
         InsuranceBroker insuranceBroker = (from insBroker in context.InsuranceBrokers
                                            where insBroker.BrokerId == brokerId
                                            select insBroker).FirstOrDefault();
         currentInsuranceBroker      = insuranceBroker;
         txtAddress.Text             = currentInsuranceBroker.BrokerAddress;
         txtCity.Text                = currentInsuranceBroker.BrokerCity;
         txtEmail.Text               = currentInsuranceBroker.BrokerEmail;
         txtFax.Text                 = currentInsuranceBroker.BrokerFax;
         txtInsuranceBrokerName.Text = currentInsuranceBroker.BrokerName;
         txtPhone.Text               = currentInsuranceBroker.BrokerPhone;
         txtPostal.Text              = currentInsuranceBroker.BrokerPostal;
         cboCountry.SelectedItem     = currentInsuranceBroker.BrokerCountry;
         cboProvince.SelectedItem    = currentInsuranceBroker.BrokerProvince;
     }
 }
Esempio n. 6
0
 public InsuranceCompanyForm(int companyId)
 {
     InitializeComponent();
     using (DealershipManagerEntities context = new DealershipManagerEntities())
     {
         InsuranceCompany insuranceCompany = (from insCompany in context.InsuranceCompanies
                                              where insCompany.CompanyId == companyId
                                              select insCompany).FirstOrDefault();
         currentInsuranceCompany      = insuranceCompany;
         txtAddress.Text              = currentInsuranceCompany.CompanyAddress;
         txtCity.Text                 = currentInsuranceCompany.CompanyCity;
         txtEmail.Text                = currentInsuranceCompany.CompanyEmail;
         txtFax.Text                  = currentInsuranceCompany.CompanyFax;
         txtInsuranceCompanyName.Text = currentInsuranceCompany.InsuranceCompany1;
         txtPhone.Text                = currentInsuranceCompany.CompanyPhone;
         txtPostal.Text               = currentInsuranceCompany.CompanyPostal;
         cboCountry.SelectedItem      = currentInsuranceCompany.CompanyCountry;
         cboProvince.SelectedItem     = currentInsuranceCompany.CompanyProvince;
     }
 }
Esempio n. 7
0
        private void BindContactsListBox()
        {
            lbxContacts.Items.Clear();
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                List <Contact> contactQuery = (from contact in context.Contacts
                                               select contact).ToList <Contact>();

                contactQuery = contactQuery.OrderBy(x => x.CompanyName).ToList();
                try
                {
                    foreach (var contact in contactQuery)
                    {
                        lbxContacts.Items.Add(contact);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
        private void cboVehicle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (null != cboVehicle.SelectedValue)
            {
                int id = (int)cboVehicle.SelectedValue;
                using (DealershipManagerEntities context = new DealershipManagerEntities())
                {
                    IQueryable <Vehicle> vehicleQuery = from vehicle in context.Vehicles
                                                        where vehicle.Id == id
                                                        select vehicle;

                    Vehicle veh = vehicleQuery.FirstOrDefault();
                    if (null == veh)
                    {
                        veh = new Vehicle();
                    }

                    BindVehicleInfo(veh);
                }
            }
        }
Esempio n. 9
0
        private void BindStaffListBox()
        {
            lbxStaff.Items.Clear();

            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                List <Staff> staffQuery = (from staff in context.Staffs
                                           select staff).ToList <Staff>();

                staffQuery = staffQuery.OrderBy(x => x.LastName).ToList();
                try
                {
                    foreach (var staff in staffQuery)
                    {
                        lbxStaff.Items.Add(staff);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Esempio n. 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //CreateContactFromForm();
            //using (DealershipManagerEntities context = new DealershipManagerEntities())
            //{
            //    var contact = (from c in context.Contacts
            //                    where c.Id == currentContact.Id
            //                    select c).First();

            //    context.SaveChanges();
            //}
            CreateContactFromForm();
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                try
                {
                    var contact = (from c in context.Contacts
                                   where c.CompanyName == currentContact.CompanyName
                                   select c).First();

                    if (contact != null)
                    {
                        bindContact(contact);
                    }
                }
                catch
                {
                    context.Contacts.AddObject(currentContact);
                }
                finally
                {
                    context.SaveChanges();
                }

                BindContactsListBox();
                lbxContacts.SelectedItem = currentContact;
                DisableContactFields();
            }
        }
Esempio n. 11
0
        public SelectVehicle(Customer c, Insurance i)
        {
            InitializeComponent();
            currentInsurance = i;
            vehicleHistory   = new List <Vehicle>();
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                IQueryable <Sale> saleQuery = from sale in context.Sales
                                              where (sale.CustomerId == c.Id)
                                              select sale;
                IQueryable <Lease> leaseQuery = from lease in context.Leases
                                                where (lease.CustomerId == c.Id)
                                                select lease;

                foreach (Sale s in saleQuery)
                {
                    Vehicle veh = (from vehicle in context.Vehicles
                                   where (vehicle.Id == s.VehicleId)
                                   select vehicle).FirstOrDefault();
                    vehicleHistory.Add(veh);
                }

                foreach (Lease l in leaseQuery)
                {
                    Vehicle veh = (from vehicle in context.Vehicles
                                   where (vehicle.Id == l.VehicleId)
                                   select vehicle).FirstOrDefault();
                    vehicleHistory.Add(veh);
                }

                foreach (Vehicle v in vehicleHistory)
                {
                    lbxVehicleHistory.Items.Add(v);
                }
            }
        }
Esempio n. 12
0
        private void btnPrintReport_Click(object sender, EventArgs e)
        {
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                try
                {
                    context.ExecuteStoreCommand("DELETE FROM tmpCalculation");
                }
                catch
                {
                }
                finally
                {
                    context.SaveChanges();
                }

                int id = 0;
                foreach (DataGridViewRow row in dgvLeaseInfo.Rows)
                {
                    try
                    {
                        TmpCalculation tmp = new TmpCalculation();

                        tmp.id = id;
                        id++;
                        Double balance = 0;
                        Double.TryParse(row.Cells["Balance"].Value.ToString().Replace("$", ""), out balance);
                        tmp.Balance = balance;

                        double cost = 0;
                        Double.TryParse(txtCapitalizedCost.Text, out cost);
                        tmp.Cost = cost;

                        Double gst = 0;
                        Double.TryParse(row.Cells["GST"].Value.ToString().Replace("$", ""), out gst);
                        tmp.GST = gst;

                        Double interest = 0;
                        Double.TryParse(row.Cells["Interest"].Value.ToString().Replace("$", ""), out interest);
                        tmp.Interest = interest;

                        Double interestrate = 0;
                        Double.TryParse(txtInterestRate.Text, out interestrate);
                        tmp.InterestRate = interestrate;

                        int numberofmonths = 0;
                        int.TryParse(txtNumberOfMonths.Text, out numberofmonths);
                        tmp.Months = numberofmonths;

                        Double paymentAmount = 0;
                        Double.TryParse(row.Cells["Payment"].Value.ToString().Replace("$", ""), out paymentAmount);
                        tmp.PaymentAmount = paymentAmount;

                        int paymentno = 0;
                        int.TryParse(row.Cells["Payment No."].Value.ToString().Replace("$", ""), out paymentno);
                        tmp.PmtNo = paymentno;

                        Double principle = 0;
                        Double.TryParse(row.Cells["Principle"].Value.ToString().Replace("$", ""), out principle);
                        tmp.Principle = principle;

                        context.TmpCalculations.AddObject(tmp);
                    }
                    catch (Exception ex)
                    {
                        string test = ex.Message;
                    }
                    finally
                    {
                        context.SaveChanges();
                    }
                }
            }

            ReportViewerForm form = new ReportViewerForm();

            form.rptviewer.LocalReport.ReportPath = "TempCalculationReport.rdlc";
            form.SetTempCalcReportDataSource();
            form.rptviewer.Show();
            form.Show();
            form.rptviewer.RefreshReport();
            form.rptviewer.LocalReport.Refresh();


            //ReportViewerForm rptv = new ReportViewerForm();
            //rptv.MdiParent = this.MdiParent;
            //rptv.Show();
            //rptv.rptviewer.LocalReport.Refresh();
            //rptv.rptviewer.Refresh();
            //rptv.rptviewer.RefreshReport();
            //rptv.rptviewer.Visible = true;
        }
        private void btnCustomerCompleteFinanceReport_Click(object sender, EventArgs e)
        {
            using (DealershipManagerEntities context = new DealershipManagerEntities())
            {
                IQueryable <Customer> customerQuery = (from customer in context.Customers
                                                       join sale in context.Sales on customer.Id equals sale.CustomerId
                                                       where customer.BandName != "" && sale.current == true
                                                       orderby customer.LastName, customer.FirstName
                                                       select customer).Distinct().OrderBy(x => x.LastName).ThenBy(y => y.FirstName);



                List <FinanceReportRow> rows      = new List <FinanceReportRow>();
                List <Customer>         customers = customerQuery.ToList();
                foreach (Customer c in customerQuery)
                {
                    FinanceReportRow frr = new FinanceReportRow();
                    frr.First_Name = c.FirstName;
                    frr.Last_Name  = c.LastName;
                    frr.Notes      = "";

                    Finance financeQuery = (from finance in context.Finances
                                            join sale in context.Sales on finance.saleId equals sale.id
                                            join customer in customerQuery on sale.CustomerId equals customer.Id
                                            where sale.CurrentBalance > 0 && sale.current == true && customer.Id == c.Id
                                            orderby finance.DatePaid descending
                                            select finance).FirstOrDefault();
                    if (financeQuery != null)
                    {
                        frr.Current_Balance = financeQuery.Balance ?? 0;
                        frr.Payment_Due     = financeQuery.Payment ?? 0;
                        rows.Add(frr);
                    }
                }

                ReportViewerForm form = new ReportViewerForm();
                form.rptviewer.LocalReport.ReportPath           = "CompleteFinanceReport.rdlc";
                form.rptviewer.LocalReport.DataSources[0].Value = rows;
                form.rptviewer.LocalReport.DataSources[0].Name  = "FinanceRows";
                form.rptviewer.Show();
                form.Show();
                form.rptviewer.RefreshReport();
                form.rptviewer.LocalReport.Refresh();

                //dgvReport.Columns.Add("Last_Name", "Last Name");
                //dgvReport.Columns["Last_Name"].DataPropertyName = "Last_Name";
                //dgvReport.Columns.Add("First_Name", "First Name");
                //dgvReport.Columns["First_Name"].DataPropertyName = "First_Name";
                //dgvReport.Columns.Add("Current_Balance", "Current Balance");
                //dgvReport.Columns["Current_Balance"].DataPropertyName = "Current_Balance";
                //dgvReport.Columns["Current_Balance"].DefaultCellStyle.Format = "C";
                //dgvReport.Columns.Add("Payment_Due", "Payment Due");
                //dgvReport.Columns["Payment_Due"].DataPropertyName = "Payment_Due";
                //dgvReport.Columns["Payment_Due"].DefaultCellStyle.Format = "C";
                //dgvReport.Columns.Add("Notes", "Notes");
                //dgvReport.Columns["Notes"].DataPropertyName = "Notes";

                //// Initialize the DataGridView.
                //dgvReport.AutoGenerateColumns = false;
                //dgvReport.AutoSize = true;

                //dgvReport.DataSource = rows;
                //dgvReport.Refresh();

                //PrintPreviewDialog objPPdialog = new PrintPreviewDialog();

                //printDocument1.DocumentName = "Payment Information";
                //objPPdialog.Document = printDocument1;
                //objPPdialog.ShowDialog();
            }
        }
        public DealershipManager()
        {
            InitializeComponent();
            String sMessage = "";

            try
            {
                using (DealershipManagerEntities context = new DealershipManagerEntities())
                {
                    List <Insurance> insuranceQuery = (from insurance in context.Insurances
                                                       select insurance).ToList <Insurance>();

                    List <Lien> lienQuery = (from lien in context.Liens
                                             select lien).ToList <Lien>();

                    insuranceQuery = insuranceQuery.OrderBy(x => x.ExpiryDate).ToList();
                    sMessage      += "The following people have insurance that will expire in the next seven days:\n";
                    sMessage      += "-------------------------------------------------------------------------------\n";
                    try
                    {
                        foreach (var insurance in insuranceQuery)
                        {
                            int custId = insurance.CustomerId ?? 0;
                            //if (insurance.ExpiryDate.Value < DateTime.Now.AddDays(7) && insurance.ExpiryDate.Value > DateTime.Now)
                            if (insurance.ExpiryDate.Value < DateTime.Now.AddDays(7))
                            {
                                Customer customerQuery = (from customer in context.Customers
                                                          where customer.Id == custId
                                                          select customer).FirstOrDefault();

                                sMessage += "\n";
                                sMessage += customerQuery.LastName + ", " + customerQuery.FirstName + "  -  " + insurance.ExpiryDate.Value.ToShortDateString();
                            }
                        }

                        sMessage += "\n";
                        sMessage += "\n";
                        sMessage += "The following liens will expire in the next seven days:\n";
                        sMessage += "-------------------------------------------------------------------------------\n";

                        foreach (var lien in lienQuery)
                        {
                            int custId = lien.Customer ?? 0;
                            //if (lien.ExpiryDate.Value < DateTime.Now.AddDays(7) && lien.ExpiryDate.Value > DateTime.Now)
                            if (lien.ExpiryDate.Value < DateTime.Now.AddDays(7))
                            {
                                Vehicle vehicleQuery = (from vehicle in context.Vehicles
                                                        where vehicle.Id == lien.VehicleId
                                                        select vehicle).FirstOrDefault();
                                Customer customerQuery = (from customer in context.Customers
                                                          where customer.Id == custId
                                                          select customer).FirstOrDefault();

                                sMessage += "\n";
                                sMessage += vehicleQuery.Year.ToString() + " " + vehicleQuery.Make.ToString() + " " + vehicleQuery.Model.ToString() + " - " + vehicleQuery.VIN.ToString() + "\n";
                                sMessage += customerQuery.LastName + ", " + customerQuery.FirstName + "\n";
                                sMessage += "Registration Number: " + lien.RegNumber.ToString() + "   Expiry Date: " + lien.ExpiryDate.Value.ToShortDateString() + "\n";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    MessageBox.Show(sMessage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.InnerException.Message);
            }
        }