示例#1
0
        private bool saveDataTransaction()
        {
            string         sqlCommand = "";
            int            numRows;
            bool           result        = false;
            MySqlException internalEX    = null;
            int            selectedMonth = 0;

            DS.beginTransaction();

            try
            {
                DS.mySqlConnect();

                // CHECK FOR CURRENT ENTRY
                sqlCommand = "SELECT COUNT(1) FROM MASTER_SALES_TARGET WHERE TARGET_YEAR = " + periodeTahunCombo.Text + " AND TARGET_MONTH = " + periodeBulanCombo.SelectedIndex + 1;
                numRows    = Convert.ToInt32(DS.getDataSingleValue(sqlCommand));

                if (numRows > 0)
                {
                    // UPDATE DATA SALES TARGET
                    sqlCommand = "UPDATE MASTER_SALES_TARGET SET SALES_COMMISSION = " + commissionValue.Text + ", TARGET_AMOUNT = " + targetPenjualanTextBox.Text + " WHERE TARGET_YEAR = " + periodeTahunCombo.Text + " AND TARGET_MONTH = " + selectedMonth;
                }
                else
                {
                    // INSERT NEW DATA SALES TARGET
                    selectedMonth = periodeBulanCombo.SelectedIndex + 1;
                    sqlCommand    = "INSERT INTO MASTER_SALES_TARGET (TARGET_MONTH, TARGET_YEAR, TARGET_AMOUNT, SALES_COMMISSION) VALUES (" + selectedMonth + ", " + periodeTahunCombo.Text + ", " + targetPenjualanTextBox.Text + ", " + commissionValue.Text + ")";
                }

                if (!DS.executeNonQueryCommand(sqlCommand, ref internalEX))
                {
                    throw internalEX;
                }

                DS.commit();
                result = true;
            }
            catch (Exception EX)
            {
                result = false;
            }
            finally
            {
                DS.mySqlClose();
            }

            return(result);
        }
        private bool saveDataTransaction(int mode)
        {
            bool           result     = false;
            string         sqlCommand = "";
            MySqlException internalEX = null;
            string         HQIP       = HQIP1.Text.Trim() + "." + HQIP2.Text.Trim() + "." + HQIP3.Text.Trim() + "." + HQIP4.Text.Trim();;
            String         branchID   = BranchIDTextbox.Text;
            String         no_faktur  = "";
            int            id         = 2;

            DS.beginTransaction();

            try
            {
                DS.mySqlConnect();

                switch (mode)
                {
                case 1:
                    sqlCommand = "INSERT INTO SYS_CONFIG (ID, NO_FAKTUR, BRANCH_ID, HQ_IP4) " +
                                 "VALUES (2, '', '" + branchID + "', '" + HQIP + "')";
                    options = gutil.INS;
                    break;

                case 2:
                    sqlCommand = "UPDATE SYS_CONFIG SET " +
                                 "BRANCH_ID = " + branchID + ", " +
                                 "HQ_IP4 = '" + HQIP + "' " +
                                 "WHERE ID = " + id;
                    options = gutil.UPD;
                    break;
                }

                if (!DS.executeNonQueryCommand(sqlCommand, ref internalEX))
                {
                    throw internalEX;
                }

                DS.commit();
                result = true;
            }
            catch (Exception e)
            {
                try
                {
                    DS.rollBack();
                }
                catch (MySqlException ex)
                {
                    if (DS.getMyTransConnection() != null)
                    {
                        gutil.showDBOPError(ex, "ROLLBACK");
                    }
                }

                gutil.showDBOPError(e, "INSERT");
                result = false;
            }
            finally
            {
                DS.mySqlClose();
            }

            return(result);
        }