public SavingState SaveSrPaymentDetails(DetailPaymentInfo paymentInfo)
        {
            SavingState svState = SavingState.Failed;

            /// paymentInfo.Id is SrId
            if (paymentInfo != null && !string.IsNullOrEmpty(paymentInfo.Id) && paymentInfo.PaymentDate != null && !paymentInfo.PaymentDate.Equals(DateTime.MinValue))
            {
                DbCommand thisCommand = null;
                try
                {
                    thisCommand             = GenericDataAccess.CreateCommand();
                    thisCommand.CommandType = CommandType.Text;
                    /// if new payment
                    if (!IsPaymentInfoExist(paymentInfo.Id, paymentInfo.CompanyId, paymentInfo.PaymentDate))
                    {
                        thisCommand.CommandText = "INSERT INTO IM_SR_DSR_PAYMENT_DETAILS (PaymentId, SrId, CompanyId, PaymentDate, ThousendCount, FiveHundredCount, OneHundredCount, FiftyCount, TwentyCount, TenCount, FiveCount, TwoCount, OneCount, TotalPayment) VALUES(@PaymentId, @SrId, @CompanyId, @PaymentDate, @ThousendCount, @FiveHundredCount, @OneHundredCount, @FiftyCount, @TwentyCount, @TenCount, @FiveCount, @TwoCount, @OneCount, @TotalPayment)";
                        CreateParameter.AddParam(thisCommand, "@PaymentId", Guid.NewGuid().ToString(), DbType.String);
                    }
                    else
                    {
                        thisCommand.CommandText = "UPDATE IM_SR_DSR_PAYMENT_DETAILS SET PaymentDate = @PaymentDate, ThousendCount = @ThousendCount, FiveHundredCount = @FiveHundredCount, OneHundredCount = @OneHundredCount, FiftyCount = @FiftyCount, TwentyCount = @TwentyCount, TenCount = @TenCount, FiveCount = @FiveCount, TwoCount = @TwoCount, OneCount = @OneCount, TotalPayment = @TotalPayment WHERE SrId = @SrId AND CompanyId = @CompanyId AND PaymentDate = @PaymentDate";
                    }

                    CreateParameter.AddParam(thisCommand, "@SrId", paymentInfo.Id, DbType.String);
                    CreateParameter.AddParam(thisCommand, "@CompanyId", paymentInfo.CompanyId, DbType.String);
                    CreateParameter.AddParam(thisCommand, "@PaymentDate", paymentInfo.PaymentDate, DbType.DateTime);
                    CreateParameter.AddParam(thisCommand, "@ThousendCount", paymentInfo.ThousendCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@FiveHundredCount", paymentInfo.FiveHundredCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@OneHundredCount", paymentInfo.OneHundredCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@FiftyCount", paymentInfo.FiftyCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@TwentyCount", paymentInfo.TwentyCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@TenCount", paymentInfo.TenCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@FiveCount", paymentInfo.FiveCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@TwoCount", paymentInfo.TwoCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@OneCount", paymentInfo.OneCount, DbType.Int32);
                    CreateParameter.AddParam(thisCommand, "@TotalPayment", Math.Round(paymentInfo.TotalPayment, 2), DbType.Decimal);

                    GenericDataAccess.ExecuteNonQuery(thisCommand);
                    thisCommand.Parameters.Clear();

                    svState = SavingState.Success;
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower().Contains("duplicate key"))
                    {
                        svState = SavingState.DuplicateExists;
                    }
                }
                finally
                {
                    if (thisCommand != null && thisCommand.Connection.State != ConnectionState.Closed)
                    {
                        thisCommand.Connection.Close();
                    }
                }
            }
            return(svState);
        }
Example #2
0
        private void btnDoneDetailPayment_Click(object sender, EventArgs e)
        {
            //totalPayment = numTotal.Value;
            detailPaymentDone = new DetailPaymentInfo();
            detailPaymentDone.ThousendCount    = (int)numThouSend.Value;
            detailPaymentDone.FiveHundredCount = (int)numFiveHundred.Value;
            detailPaymentDone.OneHundredCount  = (int)numHundred.Value;
            detailPaymentDone.FiftyCount       = (int)numFifty.Value;
            detailPaymentDone.TwentyCount      = (int)numTwenty.Value;
            detailPaymentDone.TenCount         = (int)numTen.Value;
            detailPaymentDone.FiveCount        = (int)numFive.Value;
            detailPaymentDone.TwoCount         = (int)numTwo.Value;
            detailPaymentDone.OneCount         = (int)numOne.Value;
            detailPaymentDone.TotalPayment     = (int)numTotal.Value;

            this.DialogResult = DialogResult.OK;
        }
        private DetailPaymentInfo MapPayment(DbDataReader dr)
        {
            DetailPaymentInfo detailPaymentInfo = new DetailPaymentInfo();

            detailPaymentInfo.PaymentId   = NullHandler.GetString(dr["PaymentId"]);
            detailPaymentInfo.Id          = NullHandler.GetString(dr["SrId"]);
            detailPaymentInfo.CompanyId   = NullHandler.GetString(dr["CompanyId"]);
            detailPaymentInfo.PaymentDate = NullHandler.GetDateTime(dr["PaymentDate"]);

            detailPaymentInfo.ThousendCount    = NullHandler.GetInt32(dr["ThousendCount"]);
            detailPaymentInfo.FiveHundredCount = NullHandler.GetInt32(dr["FiveHundredCount"]);
            detailPaymentInfo.OneHundredCount  = NullHandler.GetInt32(dr["OneHundredCount"]);
            detailPaymentInfo.FiftyCount       = NullHandler.GetInt32(dr["FiftyCount"]);
            detailPaymentInfo.TwentyCount      = NullHandler.GetInt32(dr["TwentyCount"]);
            detailPaymentInfo.TenCount         = NullHandler.GetInt32(dr["TenCount"]);
            detailPaymentInfo.FiveCount        = NullHandler.GetInt32(dr["FiveCount"]);
            detailPaymentInfo.TwoCount         = NullHandler.GetInt32(dr["TwoCount"]);
            detailPaymentInfo.OneCount         = NullHandler.GetInt32(dr["OneCount"]);

            detailPaymentInfo.TotalPayment = NullHandler.GetDecimal(dr["TotalPayment"]);

            return(detailPaymentInfo);
        }