/// <summary> /// Adds a new receipt line to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { try { if (receiptIdInput.Text.Equals("") || productIdInput.Text.Equals("") || quantityInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); receiptIdInput.Focus(); return; } else if ((!Regex.IsMatch(receiptIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(productIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(quantityInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into all text boxes."); receiptIdInput.Focus(); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } ReceiptLineObject receiptLine; ReceiptObject receipt = businessLogicLayer.CheckReceiptsByID(int.Parse(receiptIdInput.Text)); ProductObject product = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text)); try { if (!int.Parse(receiptIdInput.Text).Equals(receipt.receipt_id)) { MessageBox.Show("The Receipt ID provided does not exist."); receiptIdInput.Focus(); return; } else if (!int.Parse(productIdInput.Text).Equals(product.product_id)) { MessageBox.Show("The Product ID provided does not exist."); productIdInput.Focus(); return; } else { receiptLine = businessLogicLayer.InsertNewReceiptLine(int.Parse(receiptIdInput.Text), int.Parse(productIdInput.Text), int.Parse(quantityInput.Text)); MessageBox.Show("The provided Receipt Line has been added to the system."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }
public object SaveReceipt(ReceiptObject ReceiptObj) { var result = new object(); if (ReceiptObj.FormMode == FormMode.Insert || ReceiptObj.FormMode == FormMode.Duplicate) { try { //insert thằng master lấy id var masterID = InsertEntity <Receipt>(ReceiptObj.Receipt); ReceiptObj.Receipt.ReceiptID = masterID; //gán id cho thằng detail, thực hiện insert for (int i = 0; i < ReceiptObj.ReceiptDetails.Count; i++) { ReceiptObj.ReceiptDetails[i].ReceiptID = masterID; var detailID = InsertEntity <ReceiptDetail>(ReceiptObj.ReceiptDetails[i]); ReceiptObj.ReceiptDetails[i].ReceiptDetailID = detailID; } result = masterID; } catch (Exception ex) { throw ex; } } else if (ReceiptObj.FormMode == FormMode.Update) { try { //update thằng master UpdateEntity <Receipt>(ReceiptObj.Receipt); //gán id cho thằng detail, thực hiện insert var masterID = ReceiptObj.Receipt.ReceiptID; DeleteReceiptDetail(masterID.ToString()); for (int i = 0; i < ReceiptObj.ReceiptDetails.Count; i++) { ReceiptObj.ReceiptDetails[i].ReceiptID = masterID; var detailID = InsertEntity <ReceiptDetail>(ReceiptObj.ReceiptDetails[i]); ReceiptObj.ReceiptDetails[i].ReceiptDetailID = detailID; } } catch (Exception ex) { throw ex; } } return(result); }
// POST: api/Unit public ServerResponse Post([FromBody] ReceiptObject ReceiptObj) { var res = new ServerResponse(); using (ReceiptBL ReceiptBL = new ReceiptBL()) { try { res.Data = ReceiptBL.SaveReceipt(ReceiptObj); } catch (Exception ex) { res.Success = false; } } return(res); }
/// <summary> /// Edits a receipt in the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (currentReceiptReferenceInput.Text.Equals("") || currentAccountIdInput.Text.Equals("") || currentWarehouseIdInput.Text.Equals("") || newReceiptReferenceInput.Text.Equals("") || newAccountIdInput.Text.Equals("") || newWarehouseIdInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); currentReceiptReferenceInput.Focus(); return; } else if ((!Regex.IsMatch(currentAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(currentWarehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newWarehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Account ID and Warehouse ID text boxes."); currentAccountIdInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if ((!DateTime.TryParseExact(currentExpectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) || (!DateTime.TryParseExact(newExpectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime))) { MessageBox.Show("Please input valid dates and times using the datetime pickers."); currentExpectedDateInput.Focus(); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } ReceiptObject receipt; ReceiptObject receiptAllCurrent = businessLogicLayer.CheckReceiptsAll(currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); ReceiptObject receiptCurrent = businessLogicLayer.CheckReceiptsByRefAndAccountID(currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text)); ReceiptObject receiptNew = businessLogicLayer.CheckReceiptsByRefAndAccountID(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(newWarehouseIdInput.Text)); try { if (!(currentReceiptReferenceInput.Text.ToLower().Equals(receiptAllCurrent.receipt_reference) && int.Parse(currentAccountIdInput.Text).Equals(receiptAllCurrent.account_id) && int.Parse(currentWarehouseIdInput.Text).Equals(receiptAllCurrent.warehouse_id) && DateTime.Parse(currentExpectedDateInput.Text).Equals(receiptAllCurrent.expected_date))) { MessageBox.Show("The Current Receipt provided does not exist."); currentReceiptReferenceInput.Focus(); return; } else if (!int.Parse(newAccountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The New Account ID provided does not exist."); newAccountIdInput.Focus(); return; } else if (!int.Parse(newWarehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The New Warehouse ID provided does not exist."); newWarehouseIdInput.Focus(); return; } else if (newReceiptReferenceInput.Text.ToLower().Equals(receiptNew.receipt_reference) && !newReceiptReferenceInput.Text.ToLower().Equals(receiptCurrent.receipt_reference) || int.Parse(newAccountIdInput.Text).Equals(receiptNew.account_id) && !int.Parse(newAccountIdInput.Text).Equals(receiptCurrent.account_id)) { MessageBox.Show("The Receipt Reference: " + newReceiptReferenceInput.Text + " already exists for Account: " + newAccountIdInput.Text); newReceiptReferenceInput.Focus(); return; } else if (receiptedDateInput.Value.HasValue.Equals(false)) { receipt = businessLogicLayer.EditCurrentReceiptNoRecDate(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text), int.Parse(newWarehouseIdInput.Text), DateTime.Parse(newExpectedDateInput.Text), currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); MessageBox.Show(currentReceiptReferenceInput.Text + " has been updated without a Receipted Date."); return; } else { receipt = businessLogicLayer.EditCurrentReceipt(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text), int.Parse(newWarehouseIdInput.Text), DateTime.Parse(newExpectedDateInput.Text), DateTime.Parse(receiptedDateInput.Text), currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); MessageBox.Show(currentReceiptReferenceInput.Text + " has been updated with a Receipt Date."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }
/// <summary> /// Adds a new receipt to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (receiptReferenceInput.Text.Equals("") || accountIdInput.Text.Equals("") || warehouseIdInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); receiptReferenceInput.Focus(); return; } else if ((!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(warehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Account ID and Warehouse ID text boxes."); accountIdInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if (!DateTime.TryParseExact(expectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) { MessageBox.Show("Please input a valid date and time using the datetime picker."); expectedDateInput.Focus(); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } ReceiptObject receipt = businessLogicLayer.CheckReceiptsByRefAndAccountID(receiptReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(warehouseIdInput.Text)); try { if (!int.Parse(accountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The Account ID provided does not exist."); accountIdInput.Focus(); return; } else if (!int.Parse(warehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The Warehouse ID provided does not exist."); warehouseIdInput.Focus(); return; } else if (receiptReferenceInput.Text.ToLower().Equals(receipt.receipt_reference) && int.Parse(accountIdInput.Text).Equals(receipt.account_id)) { MessageBox.Show("The Receipt Reference: " + receiptReferenceInput.Text + " already exists for Account: " + accountIdInput.Text); receiptReferenceInput.Focus(); return; } else { receipt = businessLogicLayer.InsertNewReceipt(receiptReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text), int.Parse(warehouseIdInput.Text), DateTime.Parse(expectedDateInput.Text)); MessageBox.Show(receiptReferenceInput.Text + " has been added to the system."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }