/// <summary> /// Whenever user selects a supplier, filter DGV contents. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbSupplier_SelectedIndexChanged(object sender, EventArgs e) { if (cmbSupplier.SelectedItem == null || cmbSupplier.SelectedItem.ToString() == "") { productFilterCondition = ""; supplierFilterCondition = ""; cmbProduct.Enabled = true; dgvPS.DataSource = PSDB.GetPS("", ""); } else { supplierFilterCondition = " AND Suppliers.SupName = '" + cmbSupplier.SelectedItem.ToString() + "'"; productFilterCondition = ""; if (PSDB.GetPS(productFilterCondition, supplierFilterCondition).Count == 0) { cmbSupplier.SelectedIndex = 0; MessageBox.Show("No results found, please filter by a different selection."); dgvPS.DataSource = PSDB.GetPS("", ""); } else { cmbProduct.Enabled = false; dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } } }
/// <summary> /// Do not allow user to add/update if: /// - user has not picked a product /// - user has not picked a supplier /// - the product/supplier the user picked already exists in this package. /// </summary> private void isReadyForSubmission() { if (cmbProduct.SelectedItem == null || cmbSupplier.SelectedItem == null) { btnSubmit.Enabled = false; lblGandalf.Visible = false; } else if (cmbProduct.SelectedItem.ToString() == "" || cmbSupplier.SelectedItem.ToString() == "") { btnSubmit.Enabled = false; lblGandalf.Visible = false; } else if (cmbSupplier.SelectedItem.ToString() == "----------") { btnSubmit.Enabled = false; lblGandalf.Visible = false; } //Check if user's selection already exists in this package. //If so, prevent submission and display message. else if (PSDB.recordAlreadyExistsInPS(cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == true) { btnSubmit.Enabled = false; lblGandalf.Visible = true; } else { btnSubmit.Enabled = true; lblGandalf.Visible = false; } }
private void UpdateCustomerComplaintsButton_Click(object sender, RoutedEventArgs e) { using (var db = new PSDB()) { foreach (var c in CustomerComplaints) { var ms = db.CustomerComplaints.Find(c.CustomerComplaintID); if (ms == null) { continue; } ms.Jan = c.Jan; ms.Feb = c.Feb; ms.Mar = c.Mar; ms.Apr = c.Apr; ms.May = c.May; ms.Jun = c.Jun; ms.Jul = c.Jul; ms.Aug = c.Aug; ms.Sep = c.Sep; ms.Oct = c.Oct; ms.Nov = c.Nov; ms.Dec = c.Dec; } db.SaveChanges(); MessageBox.Show("Update Complete", "Update Info", MessageBoxButton.OK, MessageBoxImage.Information); } }
public MainWindow() { InitializeComponent(); MonthlyStats = new ObservableCollection <MonthlyStat>(); EventDictionary = new Dictionary <string, Event>(); CustomerComplaints = new ObservableCollection <CustomerComplaint>(); using (var db = new PSDB()) { var stats = from s in db.MonthlyStats where s.Year == DateTime.Now.Year select s; var events = from e in db.Events select e; var complaints = db.CustomerComplaints.ToList(); foreach (MonthlyStat m in stats) { MonthlyStats.Add(m); } foreach (Event e in events) { EventDictionary.Add(e.Tag, e); } if (EventDictionary["LastAccidentDate"].Timestamp != null) { AccidentDatePicker.SelectedDate = EventDictionary["LastAccidentDate"].Timestamp.Value; } if (EventDictionary["CustomerComplaintDate"].Timestamp != null) { CustomerComplaintDatePicker.SelectedDate = EventDictionary["CustomerComplaintDate"].Timestamp.Value; } foreach (CustomerComplaint c in complaints) { CustomerComplaints.Add(c); } StatsDataGrid.DataContext = MonthlyStats; ComplaintsGrid.DataContext = CustomerComplaints; Inventory = new ObservableCollection <Inventory>(); Labour = new ObservableCollection <Labour>(); } }
/// <summary> /// When user clicks 'Connect product to supplier' button, update /// the global variables for the Add/Modify form dialog to access, /// then create Add/Modify form dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddPS_Click(object sender, EventArgs e) { currentlyDGVSelectedProductName = ""; currentlyDGVSelectedSupplierName = ""; frmPSAddModify secondForm = new frmPSAddModify(); secondForm.mainForm = this; DialogResult result = secondForm.ShowDialog(); //If a product was succesfully added, update products DGV. if (result == DialogResult.OK) { dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } }
private void ReloadPPSData() { dgvPS.DataSource = PSDB.GetPS("", ""); cmbProduct.Items.Clear(); foreach (string product in ProductDB.GetAllProducts()) { cmbProduct.Items.Add(product); } cmbSupplier.Items.Clear(); foreach (string supplier in SupplierDB.GetAllSuppliers()) { cmbSupplier.Items.Add(supplier); } }
private void UpdateStatsButton_Click(object sender, RoutedEventArgs e) { using (var db = new PSDB()) { EventDictionary["CustomerComplaintDate"].Timestamp = CustomerComplaintDatePicker.SelectedDate; EventDictionary["LastAccidentDate"].Timestamp = AccidentDatePicker.SelectedDate; foreach (var m in MonthlyStats) { // try to retrieve existing entity var ms = db.MonthlyStats.Find(m.ID); ms.Inventory_Actual = m.Inventory_Actual; ms.Inventory_Average = m.Inventory_Average; ms.Inventory_Target = m.Inventory_Target; ms.LPC_Actual = m.LPC_Actual; ms.LPC_Target = m.LPC_Target; ms.NQC_Actual = m.NQC_Actual; ms.NQC_Target = m.NQC_Target; ms.OEE_Actual = m.OEE_Actual; ms.OEE_Target = m.OEE_Target; } foreach (Event ev in EventDictionary.Values) { var eve = db.Events.Find(ev.ID); eve.Timestamp = ev.Timestamp; } db.SaveChanges(); MessageBox.Show("Update Complete", "Update Info", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Any combination of product and supplier must exist in the Products_Suppliers /// table before it can be added to the Packages_Products_Suppliers table. /// Therefore, when user clicks Submit button, first check if user's selection exists /// in Products_Suppliers /// - if yes, then add it to Packages_Products_Suppliers /// - if not, add it to Products_Suppliers first, then add to Packages_Products_Suppliers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { //bool value determines whether to proceed with add/modify, depending on some //if conditions. bool proceed = true; //Check if user's selection exists in Products_Suppliers, and check ifthey still wish to proceed. //The only time where we do NOT proceed is if user clicks 'No' in dialog or if there is database error. if (PSDB.recordExistsInPS(cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == false) { DialogResult dialogresult = MessageBox.Show("Are you sure that " + cmbProduct.SelectedItem.ToString() + " is being provided by " + cmbSupplier.SelectedItem.ToString() + "? \n\nThis information is not in our database.", "Confirm information", MessageBoxButtons.YesNo); if (dialogresult == DialogResult.Yes) { if (PSDB.addToPSThenConfirmSuccess(cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) != true) { MessageBox.Show("Database error, please contact your administrator"); proceed = false; } } else { proceed = false; } } //If we are clear to proceed with add/modify, proceed. if (proceed == true) { //If user is adding a record, customize message box text accordingly. if (isAddAndNotModify == true) { if (PPSDB.addToPPSThenConfirmSuccess(mainPackageForm.currentlySelectedPackageId, cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == true) { MessageBox.Show("You have added \n\n" + cmbProduct.SelectedItem.ToString() + " provided by " + cmbSupplier.SelectedItem.ToString() + "\n\nto the package " + mainPackageForm.currentlySelectedPackageName + ".", "Success!"); } else { MessageBox.Show("Database error, please contact your administrator"); } DialogResult = DialogResult.OK; } //Otherwise, user is modifying a record, so customize message box text accordingly. else { if (PPSDB.UpdatePPSThenConfirmSuccess(mainPackageForm.currentlySelectedPackageId, mainPackageForm.currentlySelectedProductName, mainPackageForm.currentlySelectedSupplierName, cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == true) { MessageBox.Show(mainPackageForm.currentlySelectedProductName + " provided by " + mainPackageForm.currentlySelectedSupplierName + "\n\nin the package " + mainPackageForm.currentlySelectedPackageName + " has been successfully updated to \n\n" + cmbProduct.SelectedItem.ToString() + " provided by " + cmbSupplier.SelectedItem.ToString() + ".", "Success!"); } else { MessageBox.Show("Database error, please contact your administrator"); } DialogResult = DialogResult.OK; } } }
private void btnSubmit_Click(object sender, EventArgs e) { //If user is adding a record, customize message box text accordingly. if (isAddAndNotModify == true) { if (PSDB.addToPSThenConfirmSuccess(cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == true) { MessageBox.Show("You have added \n\n" + cmbProduct.SelectedItem.ToString() + " provided by " + cmbSupplier.SelectedItem.ToString() + ".", "Success!"); } else { MessageBox.Show("Database error, please contact your administrator"); } DialogResult = DialogResult.OK; } //Otherwise, user is modifying a record. else { //Check how many records in Packages_Products_Suppliers also contain this combination //of product and supplier. //If none, simply ask if user wishes to delete. if (PPSDB.GetPPSWithPS(originalProduct, originalSupplier).Count == 0) { if (PSDB.UpdatePSThenConfirmSuccess(mainForm.currentlyDGVSelectedProductName, mainForm.currentlyDGVSelectedSupplierName, cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) == true) { MessageBox.Show(mainForm.currentlyDGVSelectedProductName + " provided by " + mainForm.currentlyDGVSelectedSupplierName + "\n\nhas been successfully updated to \n\n" + cmbProduct.SelectedItem.ToString() + " provided by " + cmbSupplier.SelectedItem.ToString() + ".", "Success!"); } else { MessageBox.Show("Database error, please contact your administrator"); } DialogResult = DialogResult.OK; } else { frmPSDeleteUpdate secondForm = new frmPSDeleteUpdate(); secondForm.mainFormPSAM = this; secondForm.isDeleteAndNotUpdate = false; DialogResult result = secondForm.ShowDialog(); if (result == DialogResult.OK) { if (PSDB.addToPSThenConfirmSuccess(cmbProduct.SelectedItem.ToString(), cmbSupplier.SelectedItem.ToString()) != true) { MessageBox.Show("Database error, please contact your administrator"); } else { if (PPSDB.UpdatePPSWithPSThenConfirmSuccess(originalProduct, originalSupplier, newlyPickedProduct, newlyPickedSupplier) != true) { MessageBox.Show("Someone has deleted or changed that product(s) in the package(s).", "Concurrency error"); } else { if (PSDB.DeletePSThenConfirm(mainForm.currentlyDGVSelectedProductName, mainForm.currentlyDGVSelectedSupplierName) != true) { MessageBox.Show("Database error, please contact your administrator"); } else { MessageBox.Show(mainForm.currentlyDGVSelectedProductName + " provided by " + mainForm.currentlyDGVSelectedSupplierName + "\n\nhas been successfully updated to \n\n" + cmbProduct.SelectedItem.ToString() + " provided by " + cmbSupplier.SelectedItem.ToString() + ".", "Success!"); } } } DialogResult = DialogResult.OK; } } } }
/// <summary> /// Some cells in the products DGV contain buttons. /// This method contains method for the different buttons. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvPS_CellClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; //If user clicks a button next to record in column index 0, which is the Delete button, //get ready to delete it. if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.ColumnIndex == 0) { //Select record and confirm with user to delete it. dgvPS.Rows[e.RowIndex].Selected = true; currentlyDGVSelectedProductName = dgvPS.SelectedCells[2].Value.ToString(); currentlyDGVSelectedSupplierName = dgvPS.SelectedCells[3].Value.ToString(); //Check how many records in Packages_Products_Suppliers also contain this combination //of product and supplier. //If none, simply ask if user wishes to delete. if (PPSDB.GetPPSWithPS(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()).Count == 0) { DialogResult dialogresult = MessageBox.Show("Are you sure you wish to delete \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + "?", "Confirm delete", MessageBoxButtons.YesNo); //If user says yes, try to delete record. if (dialogresult == DialogResult.Yes) { if (PSDB.DeletePSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()) != true) { MessageBox.Show("Someone has deleted or changed that record in the database. Click OK to refresh the data displayed here.", "Concurrency error"); dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } else { MessageBox.Show("You have deleted \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + ".", "Success!"); if (PSDB.GetPS(productFilterCondition, supplierFilterCondition).Count > 0) { dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } else { dgvPS.DataSource = PSDB.GetPS("", ""); } } } } //If some packages already contain this product and supplier, //inform user that deleting this product and supplier will also //delete it from those packages. Confirm if user wishes to proceed. else { frmPSDeleteUpdate secondForm = new frmPSDeleteUpdate(); secondForm.mainFormPS = this; secondForm.isDeleteAndNotUpdate = true; DialogResult result = secondForm.ShowDialog(); if (result == DialogResult.OK) { if (PPSDB.DeletePPSWithPSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()) != true) { MessageBox.Show("Someone has deleted or changed that product(s) in the package(s).", "Concurrency error"); } if (PSDB.DeletePSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()) != true) { MessageBox.Show("Someone has deleted or changed that record in the database. Click OK to refresh the data displayed here.", "Concurrency error"); dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } else { MessageBox.Show("You have deleted \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + ".", "Success!"); if (PSDB.GetPS(productFilterCondition, supplierFilterCondition).Count > 0) { dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } else { dgvPS.DataSource = PSDB.GetPS("", ""); } } } } } //If user clicks a button next to record in column index 1, which is the Update button, //update the global variables for the Add/Modify form dialog to access, //then create Add/Modify form dialog. else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.ColumnIndex == 1) { dgvPS.Rows[e.RowIndex].Selected = true; currentlyDGVSelectedProductName = dgvPS.SelectedCells[2].Value.ToString(); currentlyDGVSelectedSupplierName = dgvPS.SelectedCells[3].Value.ToString(); frmPSAddModify secondForm = new frmPSAddModify(); secondForm.mainForm = this; DialogResult result = secondForm.ShowDialog(); //If update was successful, update products DGV. if (result == DialogResult.OK) { dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition); } } }
public MainWindow() { InitializeComponent(); MonthlyStats = new ObservableCollection <MonthlyStat>(); EventDictionary = new Dictionary <string, Event>(); CustomerComplaints = new ObservableCollection <CustomerComplaint>(); using (var db = new PSDB()) { var avgStats = db.MonthlyStats.Where(s => s.Year == DateTime.Now.Year - 1).ToList(); var avgStat = new MonthlyStat(); foreach (MonthlyStat s in avgStats) { avgStat.Inventory_Actual += ((s.Inventory_Actual) == null ? 0 : s.Inventory_Actual); avgStat.Inventory_Average += ((s.Inventory_Average) == null ? 0 : s.Inventory_Average); avgStat.Inventory_Target += ((s.Inventory_Target) == null ? 0 : s.Inventory_Target); avgStat.LPC_Actual += ((s.LPC_Actual) == null ? 0 : s.LPC_Actual); avgStat.LPC_Target += ((s.LPC_Target) == null ? 0 : s.LPC_Target); avgStat.NQC_Actual += ((s.NQC_Actual) == null ? 0 : s.NQC_Actual); avgStat.NQC_Target += ((s.NQC_Target) == null ? 0 : s.NQC_Target); avgStat.OEE_Actual += ((s.OEE_Actual) == null ? 0 : s.OEE_Actual); avgStat.OEE_Target += ((s.OEE_Target) == null ? 0 : s.OEE_Target); } avgStat.Inventory_Actual /= avgStats.Count; avgStat.Inventory_Average /= avgStats.Count; avgStat.Inventory_Target /= avgStats.Count; avgStat.LPC_Actual /= avgStats.Count; avgStat.LPC_Target /= avgStats.Count; avgStat.NQC_Actual /= avgStats.Count; avgStat.NQC_Target /= avgStats.Count; avgStat.OEE_Actual /= avgStats.Count; avgStat.OEE_Target /= avgStats.Count; avgStat.Month = (DateTime.Now.Year - 1).ToString() + "-Avg"; MonthlyStats.Add(avgStat); var stats = from s in db.MonthlyStats where s.Year == DateTime.Now.Year select s; var events = from e in db.Events select e; foreach (MonthlyStat m in stats) { MonthlyStats.Add(m); } foreach (Event e in events) { EventDictionary.Add(e.Tag, e); } var complaints = db.CustomerComplaints.ToList(); foreach (CustomerComplaint c in complaints) { CustomerComplaints.Add(c); } } Slides = new Queue <UserControl>(); SlideChange = new Timer(5000); SlideChange.AutoReset = true; SlideChange.Elapsed += SlideChange_Elapsed; AndonStatus = new AndonStatus(); AccidentDurationDisplay = new AccidentDurationDisplay(EventDictionary["LastAccidentDate"].Timestamp); CustomerComplaintDuration = new CustomerComplaintDuration(EventDictionary["CustomerComplaintDate"].Timestamp); CustomerComplaintStatus = new CustomerComplaintStatus(); ChartControl = new ChartControl(MonthlyStats); CustomerComplaintStatus.StatusGrid.DataContext = CustomerComplaints; Slides.Enqueue(AccidentDurationDisplay); Slides.Enqueue(CustomerComplaintDuration); Slides.Enqueue(ChartControl); Slides.Enqueue(CustomerComplaintStatus); BaseGrid.Children.Add(AndonStatus); }