private void AssignEmployeeJobRegisterButton_Click(object sender, RoutedEventArgs e) { try { CheckForEmpty(this.AssignEmplyeeJobGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } // look for fields in the tables AllContainer = new Container(); DB1 = new DBManager(); AllContainer = DB1.GetWholeEntity(); var result = from item in AllContainer._employeeslist where item.employee_name.ToLower().Contains(this.AssignEmployeejobEmployeeNameTextbox.Text.ToLower()) select item; // get the id of the first value found employees emp = (employees)result.ToList().First(); var rs = from item in AllContainer._job_typelist where item.job_name.ToLower().Contains(this.AssignEmployeeJobJobNameTextBox.Text.ToLower()) select item; job_type job = (job_type)rs.ToList().First(); // get the values from the two entities so as to merge them Container Entity1 = new Container(); Entity1._job_description.employee_id = emp.employee_id; Entity1._job_description.job_type_id = job.job_type_id; if (DB1.InsertValue(Entity1, Constants.Job_Description)) { MessageBox.Show("the job description has been registered"); EmptyAllfields(this.AssignEmplyeeJobGrid); RefreshContainer(); } } catch { } }
private void RegisterStockCreateButton_Click(object sender, RoutedEventArgs e) { try { // check for empty value CheckForEmpty(this.RegisterStockGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } // check if the material already exists if (this.AllContainer._employeeslist.Count == 0) { RefreshContainer(); } // get the list of all materials var result = from item in AllContainer._materialslist where (item.material_name.ToLower().Contains(this.RegisterStockMaterialNameTextBox.Text)) select item; if (result.Count() > 0) { // get the id of the material int material_id = (from _mat in (List<materials>)result.ToList() select (_mat.material_id)).ToList().First(); //find the row with the material id provided var s = from item in AllContainer._stock_materialslist where (item.material_id == material_id) select item; if (s.Count() > 0) { stock_materials stock = ((List<stock_materials>)s.ToList()).First(); // change the values of the quantity of the stock stock.quanitity += Convert.ToInt32(this.RegisterStockQuantityTextBox.Text); //update the db if (DB1.UpdateValue(stock)) { MessageBox.Show("Stock has been updated"); } EmptyAllfields(this.RegisterStockGrid); } else { // create a new row for the material Container Entity1 = new Container(); Entity1._stock_materials = new stock_materials(); Entity1._stock_materials.material_id = material_id; Entity1._stock_materials.quanitity = Convert.ToInt32(this.RegisterStockQuantityTextBox.Text); DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.Stock_Materails)) { MessageBox.Show("New value entered successfull"); EmptyAllfields(this.RegisterStockGrid); RefreshContainer(); } } } } catch { } }
private void RegisterMaterialCreateButton_Click(object sender, RoutedEventArgs e) { try { // check for empty value CheckForEmpty(this.RegisterMaterialsGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } // get the values from the fields Container Entity1 = new Container(); Entity1._materials.material_name = this.RegisterMaterialMaterialNameTextBox.Text; Entity1._materials.measuring_unit = this.RegisterMaterialMeasuringUnitTextBox.Text; DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.Materials)) { MessageBox.Show("has been successfully registered"); EmptyAllfields(this.RegisterMaterialsGrid); RefreshContainer(); } } catch { } }
private void AssignProjectEmployeeAssignButton_Click(object sender, RoutedEventArgs e) { try { // check for empty value CheckForEmpty(this.AssignProjectEmployeeGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } } catch { } try { // get the details of employee and project DB1 = new DBManager(); projects prj = (projects)DB1.GetProjects("SELECT * FROM projects where project_name = '" + this.AssignProjectEmployeeProjectNameTextBox.Text + "'").First(); employees emp = (employees)DB1.GetEmployees("SELECT * FROM employees WHERE employee_name = '" + this.AssignProjectEmployeeEmployeeNameComboBox.SelectedItem.ToString() + "'").First(); Container c = new Container(); c._project_employee_allocation = new project_employee_allocation(); c._project_employee_allocation.employee_id = emp.employee_id; c._project_employee_allocation.project_id = prj.project_id; if (DB1.InsertValue(c, Constants.Project_Employee_Allocation)) { MessageBox.Show("Employee allocated"); EmptyAllfields(this.AssignProjectEmployeeGrid); RefreshContainer(); } } catch { } }
private void RegisterEmployeeButton_Click(object sender, RoutedEventArgs e) { try { // check for empty value CheckForEmpty(this.RegisterEmployeeGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } } catch { } try { // get the name of the employee Container Entity1 = new Container(); Entity1._employees.employee_id = 0; Entity1._employees.employee_name = this.RegisterEmployeeNameTextBox.Text; Entity1._employees.employee_contact_number = this.RegisterEmployeeContactNumberTextBox.Text; DBManager DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.employees)) { MessageBox.Show(this.RegisterEmployeeNameTextBox.Text + " has been successfully registered"); EmptyAllfields(this.RegisterEmployeeGrid); RefreshContainer(); } else { MessageBox.Show("There was a problem entering data to the database"); EmptyAllfields(this.RegisterEmployeeGrid); RefreshContainer(); } } catch { } }
private void RegisterClientButton_Click(object sender, RoutedEventArgs e) { try { try { // check for empty value CheckForEmpty(this.RegisterClientGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } } catch { } // get the name of the client Container Entity1 = new Container(); Entity1._client.client_name = this.RegisterClientNameTextBox.Text; Entity1._client.email = this.RegisterClientEmailTextBox.Text; Entity1._client.contact = this.RegisterClientEmailTextBox.Text; Entity1._client.client_id = 0; DBManager DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.Client)) { MessageBox.Show("has been successfully registered"); EmptyAllfields(this.RegisterClientGrid); RefreshContainer(); } } catch { } }
private void CreateProject_Click(object sender, RoutedEventArgs e) { // get all the values from the // check if any of the values is left empty try { // check for empty ness CheckForEmpty(this.RegisterProjectGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } try { Container Entity1 = new Container(); Entity1._project.project_id = 0; Entity1._project.project_name = this.RegisterProjectProjectNameTextBox.Text; Entity1._project.location = this.RegisterProjectLocationTextBox.Text; Entity1._project.description = this.RegisterProjectDescriptionTextBox.Text; Entity1._project.end_date = (DateTime)this.RegisterProjectEndDatePicker.SelectedDate; Entity1._project.start_date = (DateTime)this.RegisterProjectStartDatePicker.SelectedDate; // get the client try { Container container1 = new Container(); DB1 = new DBManager(); container1 = DB1.GetWholeEntity(); List<clients> cc = container1._clientlist; var result = from item in cc where item.client_name.ToLower().Contains(this.RegisterProjectClientTextBox.Text.ToLower()) select item; if (result != null) { Entity1._project.client_id = Convert.ToInt32(((List<clients>)result.ToList()).First().client_id); } } catch { } if (DB1.InsertValue(Entity1, Constants.Project)) { MessageBox.Show("The Project has been registered successfully"); EmptyAllfields(this.RegisterProjectGrid); } } catch { } } catch { } }
private void AssignTaskMaterialsAssignButton_Click(object sender, RoutedEventArgs e) { try { RefreshContainer(); // check for empty value CheckForEmpty(this.AssignTaskMaterialsGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } // check if the material already exists if (this.AllContainer._employeeslist.Count == 0) { RefreshContainer(); } // get the detials of the assignment Container Entity1 = new Container(); Entity1._task_materials = new task_materials(); //get the project id var projectresult = from item in DB1.GetProjects("") where ((item.project_name).Contains(this.AssignTaskMaterialsProjectNameTextBox.Text)) select item; int pid = projectresult.ToList().First().project_id; // get the task id var taskresult = from item in AllContainer._tasklist where ( (item.task_name.ToLower().Contains(this.AssignTaskMaterialsTaskNameTextBox.Text.ToLower()) ) && (item.project_id == pid) ) select item; if (taskresult.Count() > 0) { // get the first id Entity1._task_materials.task_id = taskresult.ToList().First().task_id; } else { return; } //get the material id var materialresult = from item in AllContainer._materialslist where (item.material_name.ToLower().Contains(this.AssignTaskMaterialsMaterialNameTextBox.Text.ToLower())) select item; if (materialresult.Count() > 0) { Entity1._task_materials.material_id = materialresult.ToList().First().material_id; } else { return; } // get the type of assignment the administrator wishes to do MessageBoxResult r = MessageBox.Show("Do you wish to assign from stock", "Assign materials", MessageBoxButton.YesNoCancel); if (r == MessageBoxResult.Yes) { // remove the values from the stock and update it Entity1._task_materials.unit_buying_price = 0; //update the stock stock_materials s = DB1.GetStock("SELECT * FROM stock_materials WHERE material_id = " + Entity1._task_materials.material_id).First(); s.quanitity -= Convert.ToInt32(this.AssignTaskMaterialsQuantityTextBox.Text); DB1.UpdateValue(s); } else if (r == MessageBoxResult.No) { Entity1._task_materials.unit_buying_price = Convert.ToInt32(this.AssignTaskMaterialsUnitBuyingPriceTextBox.Text); } else if (r == MessageBoxResult.Cancel) { return; } Entity1._task_materials.quantity = Convert.ToInt32(this.AssignTaskMaterialsQuantityTextBox.Text); Entity1._task_materials.date_allocated = DateTime.Now; DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.Task_Materials)) { MessageBox.Show("the materials have been allocated"); EmptyAllfields(this.AssignTaskMaterialsGrid); RefreshContainer(); } } catch { } }
private void RegisterTaskCreateButton_Click(object sender, RoutedEventArgs e) { try { RefreshContainer(); // check for empty value CheckForEmpty(this.RegisterTaskGrid); if (this.textboxstatus == false) { MessageBox.Show("A field has not been entered"); textboxstatus = false; return; } // get the project id // check if the material already exists if (this.AllContainer._employeeslist.Count == 0) { RefreshContainer(); } var result = from item in AllContainer._projectlist where (item.project_name.Contains(this.RegisterTaskProjectNameTextBox.Text)) select (item.project_id); int p_id = ((List<int>)result.ToList()).First(); result = from item in AllContainer._employeeslist where (item.employee_name.Contains(this.RegisterTaskForemanTextBox.Text)) select (item.employee_id); int e_id = ((List<int>)result.ToList()).First(); Container Entity1 = new Container(); Entity1._task = new task(); Entity1._task.task_name = this.RegisterTaskTaskNameTextBox.Text; Entity1._task.project_id = p_id; Entity1._task.employee_id = e_id; Entity1._task.budget = Convert.ToInt32(this.RegisterTaskBudgetTextBox.Text); Entity1._task.start_date = (DateTime)this.RegisterTaskStartDatePicker.SelectedDate; Entity1._task.end_date = (DateTime)this.RegisterTaskDeadlineDatePicker.SelectedDate; //register in database DB1 = new DBManager(); if (DB1.InsertValue(Entity1, Constants.Task)) { MessageBox.Show("the task has been registered"); EmptyAllfields(this.RegisterTaskGrid); Initialization(); } } catch { } }
private static Request LabourerRequestHander(Request req) { try { LabourerRequest lr = JsonConvert.DeserializeObject<LabourerRequest>(req.content); switch (req.purpose) { case Constants.New_Labourer: //inform the user MessageBoxResult mr = MessageBox.Show("A request has been made to register a new labourer proceed" ,"Labourer registration" , MessageBoxButton.YesNo); if(mr == MessageBoxResult.No) { return null; } Container c = new Container(); c._labourers = new labourers(); c._project_labour_allocation = new project_labour_allocation(); // insert a new value to the labourers table c._labourers.national_id = lr.national_id; c._labourers.labourer_id = lr.labourer_id; c._labourers.labourer_name = lr.labourer_name; c._labourers.labourer_contact = lr.labourer_contact; DB1 = new DBManager(); if (DB1.InsertValue(c, Constants.Labourers)) { MessageBox.Show("the labourer has been registered"); } // get the derived labourer id //allocate the registered labourer c._project_labour_allocation.project_id = lr.project_id; c._project_labour_allocation.labourer_id = DB1.GetLabourers("SELECT * FROM labourers WHERE national_id = '" + lr.national_id + "'").First().labourer_id; if (DB1.InsertValue(c, Constants.Project_Labour_Allocation)) { MessageBox.Show("the labourer has been registered to the project"); } break; case Constants.Labourers_List: // return the list of labourers to the foreman // DB1 = new DBManager(); c = new Container(); c._labourerslist = new List<labourers>(); c._labourerslist = DB1.GetLabourers("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + ""); Debug.WriteLine("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + ""); c._employeeslist = new List<employees>(); c._employeeslist = DB1.GetEmployees("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + ""); Debug.WriteLine("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + ""); //c._employees_list = DB1.GetLabourers() req.content = JsonConvert.SerializeObject(c); req.category = Constants.Labourers; req.purpose = Constants.Labourers_List; break; case Constants.Submit_Work_Day: DB1 = new DBManager(); c = JsonConvert.DeserializeObject<Container>(req.content); foreach (labourers labour in c._labourerslist) { // get the project allocation id where the labourer id is entered c._project_labour_working_day = new project_labour_working_day(); c._project_labour_working_day.project_labour_allocation_id = DB1.GetProjectLabourAllocation("SELECT a.* FROM project_labour_allocation a , labourers b WHERE a.labourer_id = b.labourer_id AND b.labourer_id = " + labour.labourer_id + "").First().project_labour_allocation_id; c._project_labour_working_day.working_date = DateTime.Now.Date; if(!DB1.InsertValue(c , Constants.Project_Labour_Working_Day)) { MessageBox.Show("labourer not entered"); } } foreach (employees emp in c._employeeslist) { c._project_employee_working_day = new project_employee_working_day(); c._project_employee_working_day.project_employee_allocation_id = DB1.GetProjectEmployeeAllocation("SELECT a.* FROM project_employee_allocation a , employees b WHERE a.employee_id = b.employee_id AND b.employee_id = " + emp.employee_id + "").First().project_employee_allocation_id; c._project_employee_working_day.working_date = DateTime.Now.Date; if (!DB1.InsertValue(c, Constants.Project_employee_Working_Day)) { MessageBox.Show("employee not entered"); } } MessageBox.Show("data entered"); break; } return req; } catch { return null ; } }