예제 #1
0
        private void c_LoadBtn_Click(object sender, EventArgs e)
        {
            c_LoadBtn.Enabled = false;
            c_BillsList.Items.Clear();

            CCustomer tmpCustomer = c_CustomersList.SelectedItem as CCustomer;

            connection.openConnection();

            OleDbCommand billsCommand = new OleDbCommand();
            billsCommand.Connection = connection.connection;

            billsCommand.CommandText = "SELECT * FROM Bills WHERE ID_Customer = " + tmpCustomer.id + " ORDER BY Bill_Date ASC";
            OleDbDataReader billsReader = billsCommand.ExecuteReader();

            while (billsReader.Read())
            {
                string idBill = billsReader[0].ToString();
                DateTime billDate = (DateTime)billsReader[1];
                string billPrice = billsReader[2].ToString();
                string billNote = billsReader[3].ToString();

                OleDbCommand billServicesCommand = new OleDbCommand();
                billServicesCommand.Connection = connection.connection;

                billServicesCommand.CommandText = "SELECT Services.* FROM Services, Bill_Services WHERE Bill_Services.ID_Service = Services.ID AND Bill_Services.ID_Bill = " + idBill;
                OleDbDataReader billServicesReader = billServicesCommand.ExecuteReader();

                List<CService> tmpServices = new List<CService>();
                while (billServicesReader.Read())
                {
                    string idService = billServicesReader[0].ToString();
                    string name = billServicesReader[1].ToString();
                    string servicePrice = billServicesReader[2].ToString();
                    CService tmpSerice = new CService(idService, name, float.Parse(servicePrice));

                    OleDbCommand billServiceEmployeeCommand = new OleDbCommand();
                    billServiceEmployeeCommand.Connection = connection.connection;

                    billServiceEmployeeCommand.CommandText = "SELECT Employees.* FROM Employees, Bill_Services WHERE Bill_Services.ID_Bill = " + idBill + " AND Bill_Services.ID_Service = " + idService + "AND Bill_Services.ID_Employee = Employees.ID";
                    OleDbDataReader billServiceEmployeeReader = billServiceEmployeeCommand.ExecuteReader();

                    billServiceEmployeeReader.Read();

                    string idEmployee = billServiceEmployeeReader[0].ToString();
                    string first_name = billServiceEmployeeReader[1].ToString();
                    string last_name = billServiceEmployeeReader[2].ToString();
                    string address = billServiceEmployeeReader[3].ToString();
                    string phone = billServiceEmployeeReader[4].ToString();
                    DateTime birthday = (DateTime)billServiceEmployeeReader[5];
                    DateTime dayOfEmploymend = (DateTime)billServiceEmployeeReader[6];
                    bool fired = (bool)billServiceEmployeeReader[7];

                    CEmployee tmpEmployee = new CEmployee(idEmployee, first_name, last_name, address, phone, birthday, dayOfEmploymend, fired);
                    tmpSerice.employee = tmpEmployee;

                    tmpServices.Add(tmpSerice);
                }

                OleDbCommand billPackages = new OleDbCommand();
                billPackages.Connection = connection.connection;

                billPackages.CommandText = "SELECT DISTINCT Packages.* FROM Packages, Bill_PServices WHERE Packages.ID = Bill_PServices.ID_Package AND Bill_PServices.ID_Bill = " + idBill;
                OleDbDataReader billPackagesReader = billPackages.ExecuteReader();

                List<CPackage> tmpPackages = new List<CPackage>();
                while (billPackagesReader.Read())
                {
                    string idPackage = billPackagesReader[0].ToString();
                    string packageName = billPackagesReader[1].ToString();
                    string packagePrice = billPackagesReader[2].ToString();

                    OleDbCommand billPackageServices = new OleDbCommand();
                    billPackageServices.Connection = connection.connection;

                    billPackageServices.CommandText = "SELECT Services.* FROM Services, Bill_PServices WHERE Services.ID = Bill_PServices.ID_Service AND Bill_PServices.ID_Package = " + idPackage;
                    OleDbDataReader billPackageServicesReader = billPackageServices.ExecuteReader();

                    List<CService> tmpPServices = new List<CService>();
                    while (billPackageServicesReader.Read())
                    {
                        string idService = billPackageServicesReader[0].ToString();
                        string name = billPackageServicesReader[1].ToString();
                        string servicePrice = billPackageServicesReader[2].ToString();
                        CService tmpSerice = new CService(idService, name, float.Parse(servicePrice));

                        OleDbCommand billServiceEmployeeCommand = new OleDbCommand();
                        billServiceEmployeeCommand.Connection = connection.connection;

                        billServiceEmployeeCommand.CommandText = "SELECT Employees.* FROM Employees, Bill_PServices WHERE Bill_PServices.ID_Bill = " + idBill + " AND Bill_PServices.ID_Service = " + idService + " AND Bill_PServices.ID_Employee = Employees.ID AND Bill_PServices.ID_Package = " + idPackage;
                        OleDbDataReader billServiceEmployeeReader = billServiceEmployeeCommand.ExecuteReader();

                        billServiceEmployeeReader.Read();

                        string idEmployee = billServiceEmployeeReader[0].ToString();
                        string first_name = billServiceEmployeeReader[1].ToString();
                        string last_name = billServiceEmployeeReader[2].ToString();
                        string address = billServiceEmployeeReader[3].ToString();
                        string phone = billServiceEmployeeReader[4].ToString();
                        DateTime birthday = (DateTime)billServiceEmployeeReader[5];
                        DateTime dayOfEmploymend = (DateTime)billServiceEmployeeReader[6];
                        bool fired = (bool)billServiceEmployeeReader[7];

                        CEmployee tmpEmployee = new CEmployee(idEmployee, first_name, last_name, address, phone, birthday, dayOfEmploymend, fired);
                        tmpSerice.employee = tmpEmployee;

                        tmpPServices.Add(tmpSerice);
                    }

                    CPackage tmpPackage = new CPackage(idPackage, packageName, float.Parse(packagePrice), tmpPServices);
                    tmpPackages.Add(tmpPackage);
                }

                CBill tmpBill = new CBill(idBill,billNote,float.Parse(billPrice),tmpPackages,tmpServices,billDate,tmpCustomer);
                c_BillsList.Items.Add(tmpBill);
            }

            if (c_BillsList.Items.Count > 0)
            {
                c_BillsList.SelectedIndex = 0;
                c_ViewBilBtn.Enabled = true;
            }
            else
                MessageBox.Show(tmpCustomer.name + " " + tmpCustomer.lastName + " doesn't have any bills yet!", "No bills found", MessageBoxButtons.OK, MessageBoxIcon.Information);

            connection.closeConnection();
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            refreshBtn.Enabled = false;
            allBillsList.Items.Clear();
            ab_TotalBills = 0;
            ab_TotalPrice = 0.0f;

            connection.openConnection();

            OleDbCommand billsCommand = new OleDbCommand();
            billsCommand.Connection = connection.connection;

            billsCommand.CommandText = "SELECT * FROM Bills ORDER BY Bill_Date ASC";
            OleDbDataReader billsReader = billsCommand.ExecuteReader();

            while (billsReader.Read())
            {
                string idBill = billsReader[0].ToString();
                DateTime billDate = (DateTime)billsReader[1];
                string billPrice = billsReader[2].ToString();
                string billNote = billsReader[3].ToString();
                string idCustomer = billsReader[4].ToString();

                // FIlter by Date

                if (!(billDate.Date >= ab_From.Value.Date && billDate.Date <= ab_To.Value.Date))
                    continue;

                // Get Customer

                OleDbCommand customerComm = new OleDbCommand();
                customerComm.Connection = connection.connection;
                customerComm.CommandText = "SELECT * FROM Customers WHERE ID = " + idCustomer;

                OleDbDataReader customerReader = customerComm.ExecuteReader();
                customerReader.Read();

                string cID = customerReader[0].ToString();
                string CFN = customerReader[1].ToString();
                string CLN = customerReader[2].ToString();
                string CA = customerReader[3].ToString();
                string CP = customerReader[4].ToString();
                DateTime CB = (DateTime)customerReader[5];
                CCustomer tmpCustomer = new CCustomer(cID, CFN, CLN, CA, CP, CB);

                OleDbCommand billServicesCommand = new OleDbCommand();
                billServicesCommand.Connection = connection.connection;

                billServicesCommand.CommandText = "SELECT Services.* FROM Services, Bill_Services WHERE Bill_Services.ID_Service = Services.ID AND Bill_Services.ID_Bill = " + idBill;
                OleDbDataReader billServicesReader = billServicesCommand.ExecuteReader();

                List<CService> tmpServices = new List<CService>();
                while (billServicesReader.Read())
                {
                    string idService = billServicesReader[0].ToString();
                    string name = billServicesReader[1].ToString();
                    string servicePrice = billServicesReader[2].ToString();
                    CService tmpSerice = new CService(idService, name, float.Parse(servicePrice));

                    OleDbCommand billServiceEmployeeCommand = new OleDbCommand();
                    billServiceEmployeeCommand.Connection = connection.connection;

                    billServiceEmployeeCommand.CommandText = "SELECT Employees.* FROM Employees, Bill_Services WHERE Bill_Services.ID_Bill = " + idBill + " AND Bill_Services.ID_Service = " + idService + "AND Bill_Services.ID_Employee = Employees.ID";
                    OleDbDataReader billServiceEmployeeReader = billServiceEmployeeCommand.ExecuteReader();

                    billServiceEmployeeReader.Read();

                    string idEmployee = billServiceEmployeeReader[0].ToString();
                    string first_name = billServiceEmployeeReader[1].ToString();
                    string last_name = billServiceEmployeeReader[2].ToString();
                    string address = billServiceEmployeeReader[3].ToString();
                    string phone = billServiceEmployeeReader[4].ToString();
                    DateTime birthday = (DateTime)billServiceEmployeeReader[5];
                    DateTime dayOfEmploymend = (DateTime)billServiceEmployeeReader[6];
                    bool fired = (bool)billServiceEmployeeReader[7];

                    CEmployee tmpEmployee = new CEmployee(idEmployee, first_name, last_name, address, phone, birthday, dayOfEmploymend, fired);
                    tmpSerice.employee = tmpEmployee;

                    tmpServices.Add(tmpSerice);
                }

                OleDbCommand billPackages = new OleDbCommand();
                billPackages.Connection = connection.connection;

                billPackages.CommandText = "SELECT DISTINCT Packages.* FROM Packages, Bill_PServices WHERE Packages.ID = Bill_PServices.ID_Package AND Bill_PServices.ID_Bill = " + idBill;
                OleDbDataReader billPackagesReader = billPackages.ExecuteReader();

                List<CPackage> tmpPackages = new List<CPackage>();
                while (billPackagesReader.Read())
                {
                    string idPackage = billPackagesReader[0].ToString();
                    string packageName = billPackagesReader[1].ToString();
                    string packagePrice = billPackagesReader[2].ToString();

                    OleDbCommand billPackageServices = new OleDbCommand();
                    billPackageServices.Connection = connection.connection;

                    billPackageServices.CommandText = "SELECT Services.* FROM Services, Bill_PServices WHERE Services.ID = Bill_PServices.ID_Service AND Bill_PServices.ID_Package = " + idPackage;
                    OleDbDataReader billPackageServicesReader = billPackageServices.ExecuteReader();

                    List<CService> tmpPServices = new List<CService>();
                    while (billPackageServicesReader.Read())
                    {
                        string idService = billPackageServicesReader[0].ToString();
                        string name = billPackageServicesReader[1].ToString();
                        string servicePrice = billPackageServicesReader[2].ToString();
                        CService tmpSerice = new CService(idService, name, float.Parse(servicePrice));

                        OleDbCommand billServiceEmployeeCommand = new OleDbCommand();
                        billServiceEmployeeCommand.Connection = connection.connection;

                        billServiceEmployeeCommand.CommandText = "SELECT Employees.* FROM Employees, Bill_PServices WHERE Bill_PServices.ID_Bill = " + idBill + " AND Bill_PServices.ID_Service = " + idService + " AND Bill_PServices.ID_Employee = Employees.ID AND Bill_PServices.ID_Package = " + idPackage;
                        OleDbDataReader billServiceEmployeeReader = billServiceEmployeeCommand.ExecuteReader();

                        billServiceEmployeeReader.Read();

                        string idEmployee = billServiceEmployeeReader[0].ToString();
                        string first_name = billServiceEmployeeReader[1].ToString();
                        string last_name = billServiceEmployeeReader[2].ToString();
                        string address = billServiceEmployeeReader[3].ToString();
                        string phone = billServiceEmployeeReader[4].ToString();
                        DateTime birthday = (DateTime)billServiceEmployeeReader[5];
                        DateTime dayOfEmploymend = (DateTime)billServiceEmployeeReader[6];
                        bool fired = (bool)billServiceEmployeeReader[7];

                        CEmployee tmpEmployee = new CEmployee(idEmployee, first_name, last_name, address, phone, birthday, dayOfEmploymend, fired);
                        tmpSerice.employee = tmpEmployee;

                        tmpPServices.Add(tmpSerice);
                    }

                    CPackage tmpPackage = new CPackage(idPackage, packageName, float.Parse(packagePrice), tmpPServices);
                    tmpPackages.Add(tmpPackage);
                }

                CBill tmpBill = new CBill(idBill, billNote, float.Parse(billPrice), tmpPackages, tmpServices, billDate, tmpCustomer);
                tmpBill.inAll = true;

                allBillsList.Items.Add(tmpBill);

                ab_TotalBills += 1;
                ab_TotalPrice += tmpBill.price;
            }

            connection.closeConnection();

            if (allBillsList.Items.Count == 0)
            {
                MessageBox.Show("There arent any bills in that period", "No bills found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                button26.Enabled = false;
                ab_TotalBillTxt.Text = "";
                ab_TotalIncomeTxt.Text = "";
            }
            else
            {
                button26.Enabled = true;
                ab_TotalBillTxt.Text = ab_TotalBills.ToString();
                ab_TotalIncomeTxt.Text = ab_TotalPrice.ToString();
                allBillsList.SelectedIndex = 0;
            }
        }