private void packagesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            package = packagesList.SelectedItem as CPackage;

            servicesList.Items.Clear();
            for (int i = 0; i < package.services.Count; i++)
            {
                package.services[i].employee = null;
                servicesList.Items.Add(package.services[i]);
            }

            servicesList.SelectedIndex = 0;
            employeeList.SelectedIndex = -1;
        }
示例#2
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            connection.openConnection();
            // Screen 2

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

            getCustomers.CommandText = "SELECT * FROM Customers";
            OleDbDataReader customerReader = getCustomers.ExecuteReader();

            while (customerReader.Read())
            {
                string id = customerReader[0].ToString();
                string first_Name = customerReader[1].ToString();
                string last_Name = customerReader[2].ToString();
                string address = customerReader[3].ToString();
                string phone = customerReader[4].ToString();
                DateTime birthday = (DateTime)customerReader[5];

                CCustomer tmpCustomer = new CCustomer(id, first_Name, last_Name, address, phone, birthday);
                c_CustomersList.Items.Add(tmpCustomer);
            }

            // Screen 3

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

            getServices.CommandText = "SELECT * FROM Services";
            OleDbDataReader servicesReader = getServices.ExecuteReader();

            while (servicesReader.Read())
            {
                string id = servicesReader[0].ToString();
                string name = servicesReader[1].ToString();
                string price = servicesReader[2].ToString();

                CService tmpService = new CService(id, name, float.Parse(price));
                s_ServicesList.Items.Add(tmpService);

            }

            OleDbCommand getPackages = new OleDbCommand();
            getPackages.Connection = connection.connection;
            getPackages.CommandText = "SELECT * FROM Packages";

            OleDbDataReader packageReader = getPackages.ExecuteReader();

            while (packageReader.Read())
            {
                string id = packageReader[0].ToString();
                string name = packageReader[1].ToString();
                string price = packageReader[2].ToString();

                OleDbCommand getPackageServices = new OleDbCommand();
                getPackageServices.Connection = connection.connection;
                getPackageServices.CommandText = "SELECT Services.ID, Service_Name, Price FROM Services, Package_Services WHERE Package_Services.ID_Package = " + id + " AND Services.ID = Package_Services.ID_Service";

                OleDbDataReader packageServicesReader = getPackageServices.ExecuteReader();

                List<CService> services = new List<CService>();
                while (packageServicesReader.Read())
                {
                    string serviceId = packageServicesReader[0].ToString();
                    string serviceName = packageServicesReader[1].ToString();
                    string servicePrice = packageServicesReader[2].ToString();
                    CService tmpSerice = new CService(serviceId, serviceName, float.Parse(servicePrice));
                    services.Add(tmpSerice);
                }

                CPackage tmpPackage = new CPackage(id, name, float.Parse(price), services);
                s_PackagesList.Items.Add(tmpPackage);
            }

            // Screen 4

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

            getEmployees.CommandText = "SELECT * FROM Employees";
            OleDbDataReader employeesReader = getEmployees.ExecuteReader();

            e_employees = new List<CEmployee>();
            while (employeesReader.Read())
            {
                string id = employeesReader[0].ToString();
                string first_Name = employeesReader[1].ToString();
                string last_Name = employeesReader[2].ToString();
                string address = employeesReader[3].ToString();
                string phone = employeesReader[4].ToString();
                DateTime birthday = (DateTime)employeesReader[5];
                DateTime employmend = (DateTime)employeesReader[6];
                bool fired = (bool)employeesReader[7];

                CEmployee tmpEmployee = new CEmployee(id, first_Name, last_Name, address, phone, birthday, employmend,fired);
                e_employees.Add(tmpEmployee);
            }

            connection.closeConnection();

            if (c_CustomersList.Items.Count > 0)
                c_CustomersList.SelectedIndex = 0;
            else
            {
                c_EditBtn.Enabled = false;
                c_DeleteBtn.Enabled = false;
                c_LoadBtn.Enabled = false;
                c_ViewBilBtn.Enabled = false;
            }

            if (s_ServicesList.Items.Count > 0)
                s_ServicesList.SelectedIndex = 0;
            else
            {
                s_ServiceDelete.Enabled = false;
                s_ServiceEdit.Enabled = false;
                s_PackageAdd.Enabled = false;
            }
            if (s_PackagesList.Items.Count > 0)
                s_PackagesList.SelectedIndex = 0;
            else
            {
                s_PackageDelete.Enabled = false;
                s_PackageEdit.Enabled = false;
            }

            fillE_EmployeesList();
        }
示例#3
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();
        }
示例#4
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;
            }
        }
        private void selectPackage_Load(object sender, EventArgs e)
        {
            Connection connection = new Connection();

            connection.openConnection();

            OleDbCommand getPackages = new OleDbCommand();
            getPackages.Connection = connection.connection;
            getPackages.CommandText = "SELECT * FROM Packages";

            OleDbDataReader packageReader = getPackages.ExecuteReader();

            while (packageReader.Read())
            {
                string id = packageReader[0].ToString();
                string name = packageReader[1].ToString();
                string price = packageReader[2].ToString();

                OleDbCommand getPackageServices = new OleDbCommand();
                getPackageServices.Connection = connection.connection;
                getPackageServices.CommandText = "SELECT Services.ID, Service_Name, Price FROM Services, Package_Services WHERE Package_Services.ID_Package = " + id + " AND Services.ID = Package_Services.ID_Service";

                OleDbDataReader packageServicesReader = getPackageServices.ExecuteReader();

                List<CService> services = new List<CService>();
                while (packageServicesReader.Read())
                {
                    string serviceId = packageServicesReader[0].ToString();
                    string serviceName = packageServicesReader[1].ToString();
                    string servicePrice = packageServicesReader[2].ToString();
                    CService tmpSerice = new CService(serviceId, serviceName, float.Parse(servicePrice));
                    services.Add(tmpSerice);
                }

                CPackage tmpPackage = new CPackage(id, name, float.Parse(price), services);
                packagesList.Items.Add(tmpPackage);
            }

            OleDbCommand getEmployees = new OleDbCommand();
            getEmployees.Connection = connection.connection;
            getEmployees.CommandText = "SELECT * FROM Employees";

            OleDbDataReader employeesReader = getEmployees.ExecuteReader();

            while (employeesReader.Read())
            {
                string id = employeesReader[0].ToString();
                string first_name = employeesReader[1].ToString();
                string last_name = employeesReader[2].ToString();
                string address = employeesReader[3].ToString();
                string phone = employeesReader[4].ToString();
                DateTime birthday = (DateTime)employeesReader[5];
                DateTime dayOfEmploymend = (DateTime)employeesReader[6];
                bool fired = (bool)employeesReader[7];

                CEmployee tmpEmployee = new CEmployee(id,first_name, last_name, address, phone, birthday, dayOfEmploymend,fired);
                if (!fired)
                    employeeList.Items.Add(tmpEmployee);
            }

            connection.closeConnection();

            if (packagesList.Items.Count == 0)
            {
                doneBtn.Enabled = false;
                employeeList.Enabled = false;
            }
            else
                packagesList.SelectedIndex = 0;
        }
示例#6
0
        private void doneBtn_Click(object sender, EventArgs e)
        {
            if (nameTxt.Text.Length < 1 || priceTxt.Text.Length < 1 || addedSerivesList.Items.Count == 0)
            {
                MessageBox.Show("All fields must be entered!", "Invalid Values", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List<CService> services = new List<CService>();
            for (int i = 0; i < addedSerivesList.Items.Count; i++)
            {
                CService tmpService = addedSerivesList.Items[i] as CService;
                services.Add(tmpService);
            }

            connection.openConnection();

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

            if (edit)
            {
                packageCommand.CommandText = "UPDATE Packages SET Package_Name = '" + nameTxt.Text + "', Price = " + priceTxt.Text + " WHERE ID = " + package.id;
                packageCommand.ExecuteNonQuery();

                packageCommand.CommandText = "DELETE FROM Package_Services WHERE ID_Package = " + package.id;
                packageCommand.ExecuteNonQuery();

                for (int i = 0; i < services.Count; i++)
                {
                    OleDbCommand insertPackageService = new OleDbCommand();
                    insertPackageService.Connection = connection.connection;
                    insertPackageService.CommandText = "INSERT INTO Package_Services (ID_Service, ID_Package) VALUES (" + services[i].id + ", " + package.id + ")";

                    insertPackageService.ExecuteNonQuery();
                }

                package.name = nameTxt.Text;
                package.price = float.Parse(priceTxt.Text);
                package.services = services;
            }
            else
            {
                packageCommand.CommandText = "INSERT INTO Packages (Package_Name, Price) VALUES ('" + nameTxt.Text + "', " + priceTxt.Text + ")";
                packageCommand.ExecuteNonQuery();

                packageCommand.CommandText = "Select @@Identity";
                string packageID = packageCommand.ExecuteScalar().ToString();

                for (int i = 0; i < services.Count; i++)
                {
                    OleDbCommand insertPackageService = new OleDbCommand();
                    insertPackageService.Connection = connection.connection;
                    insertPackageService.CommandText = "INSERT INTO Package_Services (ID_Service, ID_Package) VALUES (" + services[i].id + ", " + packageID + ")";

                    insertPackageService.ExecuteNonQuery();
                }

                    package = new CPackage(packageID, nameTxt.Text, float.Parse(priceTxt.Text), services);
            }

            connection.closeConnection();

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }