예제 #1
0
        public bool RemoveDetail(POVendorsDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(false);
            };

            bool result;

            try
            {
                result = RemoveDetail(data, oConn);
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                return(false);
            }

            ConnManager.CloseConn(oConn);

            return(result);
        }
예제 #2
0
        public POVendorsDetail AddDetail(POVendorsDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            };

            data.POVDetailCreatedDate = DateTime.Now;
            string sql = "INSERT INTO POVendorsDetails ({0}) VALUES ({1}) " +
                         "SELECT SCOPE_IDENTITY()";

            EnumExtension.setListValues(data, "POVDetailId", ref sql);

            SqlTransaction oTX = oConn.BeginTransaction();

            SqlCommand cmd = new SqlCommand(sql, oConn, oTX);

            int keyGenerated = 0;

            try
            {
                keyGenerated = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                cmd.Dispose();
                oTX.Rollback();
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            }

            oTX.Commit();
            cmd.Dispose();

            POVendorsDetail returnData = GetDetail(keyGenerated, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
예제 #3
0
        private bool RemoveDetail(POVendorsDetail data, SqlConnection oConn)
        {
            string sql = "DELETE FROM POVendorsDetails " +
                         " WHERE (POVDetailId = @id)";

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(data.POVDetailId);

            int number = Convert.ToInt32(cmd.ExecuteNonQuery());

            if (number > 0)
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        public POVendorsDetail GetDetail(int id, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            };

            POVendorsDetail data = GetDetail(id, oConn);

            ConnManager.CloseConn(oConn);

            return(data);
        }
예제 #5
0
        public POVendorsDetail UpdateDetail(POVendorsDetail data, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            };

            data.POVDetailModifiedDate = DateTime.Now;
            string sql = "UPDATE POVendorsDetails SET {0} WHERE POVDetailId = @id";

            EnumExtension.setUpdateValues(data, "POVDetailId", ref sql);

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(data.POVDetailId);
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            }

            POVendorsDetail returnData = GetDetail(data.POVDetailId, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
예제 #6
0
        public bool Pay(int VendorId, string UserId, Payment Paid, ref string msg)
        {
            decimal       amount = 0, amountNB = 0, currencyRate = 0;
            string        reference = "";
            PaymentVendor payHeader = new PaymentVendor();

            payHeader.PayVendorCreatedBy   = UserId;
            payHeader.PayVendorCreatedDate = DateTime.Now;

            // Add into database pay Header
            payHeader = repPayHead.Add(payHeader, ref msg);

            //Insert into database details
            foreach (var pov in Paid.PaidDetail)
            {
                PaymentVendorDetail payDetail = new PaymentVendorDetail();
                payDetail.PayModeID                   = pov.PayModeID;
                payDetail.PayVendorId                 = payHeader.PayVendorId;
                payDetail.PayVendorDetailAmount       = pov.PayVendorDetailAmount;
                payDetail.PayVendorDetailAmountNB     = pov.PayVendorDetailAmountNB;
                payDetail.PayVendorDetailCurrencyRate = pov.PayVendorDetailCurrencyRate;
                payDetail.PayVendorDetailReference    = pov.PayVendorDetailReference;
                payDetail.AccountID                   = pov.AccountID;
                payDetail.PayVendorDetailDate         = pov.PayVendorDetailDate;
                payDetail.PayVendorDetailComments     = pov.PayVendorDetailComments;

                amount      += pov.PayVendorDetailAmount;
                amountNB    += pov.PayVendorDetailAmountNB;
                currencyRate = pov.PayVendorDetailCurrencyRate;
                reference   += "/" + pov.PayVendorDetailReference;

                payDetail = repPayDetail.Add(payDetail, ref msg);
            }

            // insert details to pay
            decimal thisPaid = 0, thisPaidNB = 0;

            foreach (var pov in Paid.POVList)
            {
                thisPaid   = pov.x_InvoiceVendorBalance.GetValueOrDefault();
                thisPaidNB = pov.x_InvoiceVendorBalanceNB.GetValueOrDefault();

                POVendorsDetail povDetail = new POVendorsDetail();
                povDetail.POVDetailAmount        = -thisPaid;
                povDetail.POVDetailAmountNB      = -thisPaidNB;
                povDetail.POVDetailCreatedBy     = UserId;
                povDetail.POVDetailCreatedDate   = DateTime.Now;
                povDetail.POVDetailCurrencyRate  = currencyRate;
                povDetail.POVDetailDate          = DateTime.Now;
                povDetail.POVDetailPaymentNumber = !string.IsNullOrEmpty(reference) ? reference.Substring(1) : reference;
                povDetail.POVId         = pov.POVId;
                povDetail.POVDetailType = "PB";
                povDetail.PayVendorId   = payHeader.PayVendorId;

                povDetail = repPOV.AddDetail(povDetail, ref msg);
            }

            foreach (var file in Paid.Files)
            {
                IDictionary <string, object> data = new Dictionary <string, object>();
                data["AttachId"]    = file.AttachId;
                data["AttachDirty"] = false;
                data["PayVendorId"] = payHeader.PayVendorId;
                repAtt.Update(data, UserId, ref msg);
            }
            //msg = String.Format("{0:#,###.00} and {1:#,###.00}", amount, amountNB);
            return(true);
        }