private bool insertDataToHQ(Data_Access DAccess) { bool result = false; string sqlCommand = ""; MySqlException internalEX = null; string roInvoice = ""; int branchIDFrom = 0; int branchIDTo = 0; string roDateTime = ""; double roTotal = 0; string roDateExpired = ""; DateTime selectedRODate; DateTime expiredRODate; string messageContent = ""; string selectedDate = RODateTimePicker.Value.ToShortDateString(); selectedRODate = RODateTimePicker.Value; expiredRODate = selectedRODate.AddDays(Convert.ToDouble(durationTextBox.Text)); roInvoice = ROinvoiceTextBox.Text; branchIDFrom = selectedBranchFromID; branchIDTo = selectedBranchToID; roDateTime = String.Format(culture, "{0:dd-MM-yyyy}", Convert.ToDateTime(selectedDate)); roDateExpired = String.Format(culture, "{0:dd-MM-yyyy}", expiredRODate); roTotal = globalTotalValue; DAccess.beginTransaction(Data_Access.HQ_SERVER); try { //DAccess.mySqlConnect(); // SAVE HEADER TABLE sqlCommand = "INSERT INTO REQUEST_ORDER_HEADER (RO_INVOICE, RO_BRANCH_ID_FROM, RO_BRANCH_ID_TO, RO_DATETIME, RO_TOTAL, RO_EXPIRED, RO_ACTIVE) VALUES " + "('" + roInvoice + "', " + branchIDFrom + ", " + branchIDTo + ", STR_TO_DATE('" + roDateTime + "', '%d-%m-%Y'), " + gUtil.validateDecimalNumericInput(roTotal) + ", STR_TO_DATE('" + roDateExpired + "', '%d-%m-%Y'), 1)"; gUtil.saveSystemDebugLog(globalConstants.MENU_REQUEST_ORDER, "INSERT REQUEST ORDER ["+roInvoice+"] TO HQ"); if (!DAccess.executeNonQueryCommand(sqlCommand, ref internalEX)) throw internalEX; // SAVE DETAIL TABLE for (int i = 0; i < detailRequestOrderDataGridView.Rows.Count; i++) { if (null != detailRequestOrderDataGridView.Rows[i].Cells["productID"].Value) { sqlCommand = "INSERT INTO REQUEST_ORDER_DETAIL (RO_INVOICE, PRODUCT_ID, PRODUCT_BASE_PRICE, RO_QTY, RO_SUBTOTAL) VALUES " + "('" + roInvoice + "', '" + detailRequestOrderDataGridView.Rows[i].Cells["productID"].Value.ToString() + "', " + Convert.ToDouble(detailRequestOrderDataGridView.Rows[i].Cells["hpp"].Value) + ", " + Convert.ToDouble(detailRequestOrderDataGridView.Rows[i].Cells["qty"].Value) + ", " + gUtil.validateDecimalNumericInput(Convert.ToDouble(detailRequestOrderDataGridView.Rows[i].Cells["subTotal"].Value)) + ")"; gUtil.saveSystemDebugLog(globalConstants.MENU_REQUEST_ORDER, "INSERT DETAIL REQUEST ORDER [" + detailRequestOrderDataGridView.Rows[i].Cells["productID"].Value.ToString() + ", " + Convert.ToDouble(detailRequestOrderDataGridView.Rows[i].Cells["hpp"].Value) + ", " + Convert.ToDouble(detailRequestOrderDataGridView.Rows[i].Cells["qty"].Value) + "] TO HQ"); if (!DAccess.executeNonQueryCommand(sqlCommand, ref internalEX)) throw internalEX; } } // INSERT INTO HQ MESSAGING TABLE messageContent = "REQUEST ORDER [" + roInvoice + "] EXPIRED PADA TGL " + roDateExpired; sqlCommand = "INSERT INTO MASTER_MESSAGE (STATUS, MODULE_ID, IDENTIFIER_NO, MSG_DATETIME_CREATED, MSG_CONTENT) " + "VALUES " + "(0, " + globalConstants.MENU_REQUEST_ORDER + ", '" + roInvoice + "', STR_TO_DATE('" + roDateTime + "', '%d-%m-%Y'), '" + messageContent + "')"; gUtil.saveSystemDebugLog(globalConstants.MENU_REQUEST_ORDER, "INSERT TO HQ MESSAGING TABLE"); if (!DAccess.executeNonQueryCommand(sqlCommand, ref internalEX)) throw internalEX; DAccess.commit(); result = true; } catch (Exception e) { gUtil.saveSystemDebugLog(globalConstants.MENU_REQUEST_ORDER, "EXCEPTION THROWN ["+e.Message+"]"); try { DAccess.rollBack(); } catch (MySqlException ex) { if (DAccess.getMyTransConnection() != null) { gUtil.showDBOPError(ex, "ROLLBACK"); } } gUtil.showDBOPError(e, "INSERT"); result = false; } finally { DAccess.mySqlClose(); } return result; }
private bool updateDataToHQ(Data_Access DAccess) { bool result = false; string sqlCommand = ""; MySqlException internalEX = null; string pmInvoice = ""; pmInvoice = noMutasiTextBox.Text; DAccess.beginTransaction(Data_Access.HQ_SERVER); try { // UPDATE PM DATA AT HQ sqlCommand = "UPDATE PRODUCTS_MUTATION_HEADER SET PM_RECEIVED = 1 WHERE PM_INVOICE = '" + pmInvoice + "'"; gUtil.saveSystemDebugLog(globalConstants.MENU_PENERIMAAN_BARANG, "ATTEMPT TO UPDATE PRODUCTS MUTATION HEADER TO INDICATE RECEIVED [" + pmInvoice + "]"); if (!DAccess.executeNonQueryCommand(sqlCommand, ref internalEX)) throw internalEX; DAccess.commit(); result = true; } catch (Exception e) { gUtil.saveSystemDebugLog(globalConstants.MENU_PENERIMAAN_BARANG, "EXCEPTION THROWN ["+e.Message+"]"); try { DAccess.rollBack(); } catch (MySqlException ex) { if (DAccess.getMyTransConnection() != null) { gUtil.showDBOPError(ex, "ROLLBACK"); } } gUtil.showDBOPError(e, "INSERT"); result = false; } finally { DAccess.mySqlClose(); } return result; }