Esempio n. 1
0
        //Method to compare the profits of the last thirty days to the store's expenditure on staff wages
        public void getThirtyDaysProfitsWages()
        {
            //List of records storing store name list of salaries, and list of sales records
            List<StoreRecord> storeRecordList = new List<StoreRecord>();
            List<Worker> workerList = new List<Worker>();

            //Add the two necessary series
            chartSalariesIncome.Series.Clear();
            chartSalariesIncome.Series.Add("Sale Profits");
            chartSalariesIncome.Series.Add("Monthly Wage Expenditure");

            //Set axis labels
            chartSalariesIncome.ChartAreas[0].AxisX.Title = "Store Name";
            chartSalariesIncome.ChartAreas[0].AxisY.Title = "Profit/Cost (£)";

            //When calling in chartStoresRecords, pass in a 2 (that means we'll get data for past 30 days only
            //Set the list to the result of the SQL command getting sales of all stores
            storeRecordList = graphConnect.chartStoresRecords(2);

            //Get list of worker details
            workerList = graphConnect.chartWorkersSalaries();

            //This is a new list which will store each store's salaries
            List<Salary> storeSalaryList = new List<Salary>();

            //Loop through the worker list
            for (int i = 0; i < workerList.Count; i++)
            {
                //Get the position of the new list on which to add items to, if the worker's store IDs match
                int pos = findStorePos(workerList[i].getStoreID(), storeSalaryList);

                //If pos is less than 0, the search returned no results
                //Therefore the entry to the salary list is a new entry
                if (pos < 0)
                {
                    Salary salaryToAdd = new Salary(workerList[i].getStoreID(), workerList[i].getSalary());
                    storeSalaryList.Add(salaryToAdd);
                }
                //Else, it returned a position in which the salaries are already stored
                //Therefore, to avoid duplicate country entries, we simply add the sales of the current entry to the new list's entry
                else
                {
                    storeSalaryList[pos].addSalary(workerList[i].getSalary());
                }

            }

            //Loop through stores
            for (int i = 0; i < storeRecordList.Count; i++)
            {
                //Get the relative position in the salary list of the salaries for the current store
                int pos = findStorePos(storeRecordList[i].getStoreID(), storeSalaryList);

                //Get totals for that store
                decimal salesTotal = storeRecordList[i].getTotalSales();
                chartSalariesIncome.Series["Sale Profits"].Points.AddXY(storeRecordList[i].getStoreName(), salesTotal);

                //Add total salaries for that store
                chartSalariesIncome.Series["Monthly Wage Expenditure"].Points.AddXY(storeRecordList[i].getStoreName(), storeSalaryList[pos].getTotalSalaries());

            }

            //Display
            chartSalariesIncome.Show();
        }
        //Get name based on jobID
        public Salary getJobDetails(int jobID)
        {
            Salary salaryToReturn = new Salary();

            try
            {
                connection.Open();
                MySqlCommand command;
                MySqlDataReader data;

                string query = "BEGIN; CREATE OR REPLACE VIEW t AS SELECT JobName, Salary FROM Job where idJob = " + jobID + "; SELECT * FROM t;";
                command = new MySqlCommand(query, connection);
                data = command.ExecuteReader();

                while (data.Read())
                {
                    String jobName = data.GetString("JobName");
                    decimal jobSalary = data.GetDecimal("Salary");

                    salaryToReturn.setJobName(jobName);
                    salaryToReturn.setSingleSalary(jobSalary);
                }
                connection.Close();

                return salaryToReturn;

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
        }