/// \brief This method UpdateCMP for user /// \details <b>Details</b> /// This method will update CMP database /// \return void public void UpdateCMP(ContractMarketPlace cmp) { using (var myConn = new MySqlConnection(connectionStringLocal)) { const string sqlStatement = @" UPDATE contract_market_place SET jobType = @jobType, quantity = @quantity, origin = @origin, destination = @destination, vanType = @vanType WHERE customerID = @customerID, contractID = @contractID; "; var myCommand = new MySqlCommand(sqlStatement, myConn); myCommand.Parameters.AddWithValue("@customerID", cmp.customerID); myCommand.Parameters.AddWithValue("@contractID", cmp.contractID); myCommand.Parameters.AddWithValue("@jobType", cmp.jobType); myCommand.Parameters.AddWithValue("@quantity", cmp.quantity); myCommand.Parameters.AddWithValue("@origin", cmp.origin); myCommand.Parameters.AddWithValue("@destination", cmp.destination); myCommand.Parameters.AddWithValue("@vanType", cmp.vanType); myConn.Open(); myCommand.ExecuteNonQuery(); } }
/// \brief This method DeleteCMP for user /// \details <b>Details</b> /// This method will delete CMP for selecting customerID and contractID /// \return void public void DeleteCMP(ContractMarketPlace cmp) { using (var myConn = new MySqlConnection(connectionStringLocal)) { const string sqlStatement = @" DELETE FROM contract_market_place WHERE customerID = @customerID AND contractID = @contractID;"; var myCommand = new MySqlCommand(sqlStatement, myConn); myCommand.Parameters.AddWithValue("@customerID", cmp.customerID); myCommand.Parameters.AddWithValue("@contractID", cmp.contractID); myConn.Open(); myCommand.ExecuteNonQuery(); } }
/// \brief This method GetLastCustomerId for user /// \details <b>Details</b> /// This method will get GetLastCustomerId from database /// \return void public string GetLastCustomerId(ContractMarketPlace cmp) { string value = ""; using (var myConn = new MySqlConnection(connectionStringLocal)) { const string sqlStatement = @"SELECT customerID FROM contract_market_place ORDER BY customerID DESC LIMIT 1; "; var myCommand = new MySqlCommand(sqlStatement, myConn); myConn.Open(); myCommand.ExecuteNonQuery(); value = (string)myCommand.ExecuteScalar(); } return(value); }
/// \brief This method InsertCMP for user /// \details <b>Details</b> /// This method will insert data into CMP /// \return void public void InsertCMP(ContractMarketPlace cmp) { using (var myConn = new MySqlConnection(connectionStringLocal)) { const string sqlStatement = @" INSERT INTO contract_market_place (customerID, contractID, jobType, quantity, origin, destination, vanType) VALUES (@customerID, @contractID, @jobType, @quantity, @origin, @destination, @vanType); " ; var myCommand = new MySqlCommand(sqlStatement, myConn); myCommand.Parameters.AddWithValue("@customerID", cmp.customerID); myCommand.Parameters.AddWithValue("@contractID", cmp.contractID); myCommand.Parameters.AddWithValue("@jobType", cmp.jobType); myCommand.Parameters.AddWithValue("@quantity", cmp.quantity); myCommand.Parameters.AddWithValue("@origin", cmp.origin); myCommand.Parameters.AddWithValue("@destination", cmp.destination); myCommand.Parameters.AddWithValue("@vanType", cmp.vanType); myConn.Open(); myCommand.ExecuteNonQuery(); } }
public void btn_Send_Order(object sender, RoutedEventArgs e) { if (currentStatus == "CHANGE") { Order order = new Order(); if (boxFrom.Items.Count == 0) { MessageBox.Show("No Original City"); } else if (boxTo.Items.Count == 0) { MessageBox.Show("No Destination City"); } else if (txtVanType.Text == "") { MessageBox.Show("Please insert van type"); } else if (txtPallet.Text == "") { MessageBox.Show("Please insert pallet"); } else if (Convert.ToDouble(txtPallet.Text) > 1000) { MessageBox.Show("Pallet should be lower than 1000 lbs"); } else if ((boxFTL.IsChecked ?? false) || (boxLTL.IsChecked ?? false)) { // Job Type if (boxFTL.IsChecked ?? false) { order.jobType = 0; } else if (boxLTL.IsChecked ?? false) { order.jobType = 1; } // OrderID order.orderID = txtOrderID.Text; // ContractID Contract contract = new Contract(); order.contractID = contract.GetLastId(); // Customer ID Customer customer = new Customer(); order.customerID = customer.GetCustomerIDbyName(currentCustomerName); // Quantity order.quantity = Convert.ToInt32(txtPallet.Text); // Van Type order.vanType = Convert.ToInt32(txtVanType.Text); // Order Date order.orderDate = txtOrderDate.Text; // Original City ID order.originalCityID = order.GetOriginalID(boxFrom.SelectedItem.ToString()); // Destination City ID order.desCityID = order.GetDestinateID(boxTo.SelectedItem.ToString()); // Command order.command = "INSERT"; // Order Status order.orderStatus = "ACTIVE"; // CarrierID Carrier carrier = new Carrier(); order.carrierID = carrier.GetCarrierIDbyDepotCity(order.originalCityID); if (MessageBox.Show("Confirm the Order?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff } else { // Save to DB order.Save(); MessageBox.Show("Order Successful\nOrder Details:\nOrderID:" + order.orderID + "\nOrder Date: " + order.orderDate + "\nFrom: " + boxFrom.SelectedItem.ToString() + "\nTo: " + boxTo.SelectedItem.ToString() + "\nQuantity: " + order.quantity + "\nVan Type: " + order.vanType + "\nJob Type: " + order.jobType); generateOrderInvoice(order); } MessageBox.Show("Order Invoice generated"); } else if (((bool)boxFTL.IsChecked == false) && ((bool)boxLTL.IsChecked == false)) { MessageBox.Show("No Job Type Selection!!!"); } } else if (currentStatus == "NOT CHANGE") { Order order = new Order(); // OrderID order.orderID = txtOrderID.Text; // ContractID ContractMarketPlace cmp = new ContractMarketPlace(); order.contractID = cmp.GetContractIDbyCustomerName(currentCustomerName); // Customer ID Customer customer = new Customer(); order.customerID = customer.GetCustomerIDbyName(currentCustomerName); // Quantity order.quantity = Convert.ToInt32(txtPallet.Text); // Job Type if (boxFTL.IsChecked ?? false) { order.jobType = 0; } else if (boxLTL.IsChecked ?? false) { order.jobType = 1; } // Van Type order.vanType = Convert.ToInt32(txtVanType.Text); // Order Date order.orderDate = txtOrderDate.Text; // Original City ID order.originalCityID = order.GetOriginalID(txtOriginalCity.Text); // Destination City ID order.desCityID = order.GetDestinateID(txtDestinationCity.Text); // Command order.command = "INSERT"; // Order Status order.orderStatus = "ACTIVE"; // CarrierID Carrier carrier = new Carrier(); order.carrierID = carrier.GetCarrierIDbyDepotCity(order.originalCityID); if (MessageBox.Show("Confirm the Order?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff } else { // Save to DB order.Save(); MessageBox.Show("Order Successful\nOrder Details:\nOrderID:" + order.orderID + "\nOrder Date: " + order.orderDate + "\nFrom: " + txtOriginalCity.Text + "\nTo: " + txtDestinationCity.Text + "\nQuantity: " + order.quantity + "\nVan Type: " + order.vanType + "\nJob Type: " + order.jobType); generateOrderInvoice(order); } MessageBox.Show("Order Invoice generated"); } }
/// \brief This method btn_Next_Click /// \details <b>Details</b> /// This method will set up DB for get data from CMP table and insert into local DB /// \return void private void btn_Next_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are you sure to continue?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff } else { if (txtClientName.Text == null || txtDestination.Text == null || txtOrigin.Text == null || txtJobType.Text == null || txtQuantity.Text == null || txtVanType.Text == null) { MessageBox.Show("Please check all information!!"); } else { // Check if it is existing customer if (customer.GetCustomerIDbyName(txtClientName.Text) != null) { if (MessageBox.Show("Existing Customer Founded! Continue?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff } else { // do yes stuff // Navigation To Add CustomerDetails UserControl usc = null; status = "EXIST"; usc = new CustomerAdd(txtClientName.Text, customer.GetCustomerIDbyName(txtClientName.Text), txtOrigin.Text, txtDestination.Text, txtQuantity.Text, txtJobType.Text, txtVanType.Text, status); GridCMP.Children.Add(usc); } } else { // if missing, show warning if (txtEndDate.SelectedDate == null) { MessageBox.Show("You must choose the End Date for the Contract"); } else { /* =============================================== CONTRACT ========================================================== */ contract = new Contract(); // Contract Start Date contract.startDate = contract.NewContractDate(); // Contract completeStatus contract.completeStatus = "UNPAID"; // Contract command contract.command = "INSERT"; // Check if the contractID is exist, if not create a new contractID if (contract.contractID != contract.GetLastId() && contract.contractID != null || contract.GetLastId() == null) { contract.contractID = contract.NewContractID(1); } // If exist, get the last contract ID and increase it by 1 else if (contract.contractID == contract.GetLastId() || contract.contractID == null) { string buffer = contract.GetLastId(); // Get the last character in the last OrderID string last = buffer.Substring(buffer.Length - 3); // Convert it into INT int temp = Convert.ToInt32(last); // Add by 1 temp += 1; //Delete the last character of the buffer string newBuffer = RemoveLastChar(buffer); // Add with new temp contract.contractID = newBuffer + String.Format("{0:D3}", temp); } // Get the Date for the End Date contract.endDate = txtEndDate.SelectedDate.Value.Date.ToString("yyyy-MM-dd"); // Check if client name is missing if (txtClientName.Text != null) { contract.initiateBy = "BUYER"; } /* =============================================== CONTRACT MARKET PLACE ========================================================== */ cmp = new ContractMarketPlace(); // CMP contractID cmp.contractID = contract.contractID; // CMP jobType cmp.jobType = Convert.ToInt32(txtJobType.Text); // CMP Quantity cmp.quantity = Convert.ToInt32(txtQuantity.Text); // CMP Origin cmp.origin = txtOrigin.Text; // CMP Destination cmp.destination = txtDestination.Text; // CMP VanType cmp.vanType = Convert.ToInt32(txtVanType.Text); // CMP CustomerID if (cmp.customerID != cmp.GetLastCusID() && cmp.customerID != null || cmp.GetLastCusID() == null) { cmp.customerID = cmp.NewCustomerID(1); } else if (cmp.customerID == cmp.GetLastCusID() || cmp.customerID == null) { string buffer = cmp.GetLastCusID(); // Get the last character in the last OrderID string last = buffer.Substring(buffer.Length - 3); // Convert it into INT int temp = Convert.ToInt32(last); // Add by 1 temp += 1; //Delete the last character of the buffer string newBuffer = RemoveLastChar(buffer); // Add with new temp cmp.customerID = newBuffer + String.Format("{0:D3}", temp); } // CMP Command cmp.command = "INSERT"; // Save to Database (Contract and CMP Table) cmp.Save(); contract.Save(); // Navigation To Add CustomerDetails UserControl usc = null; status = "NEW"; usc = new CustomerAdd(txtClientName.Text, cmp.customerID, txtOrigin.Text, txtDestination.Text, txtQuantity.Text, txtJobType.Text, txtVanType.Text, status); GridCMP.Children.Add(usc); } } } } }