コード例 #1
0
        public bool RemoveHeader(QuoteHeader 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 = RemoveHeader(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
        private void InsertCustomClearence(QuoteHeader quote, SqlConnection oConn)
        {
            try
            {
                CustomsClearence cc = new CustomsClearence();
                cc.CClearenceCreatedBy    = quote.QHeaderModifiedBy ?? quote.QHeaderCreatedBy;
                cc.CClearenceCreatedDate  = DateTime.Now;
                cc.CClearenceCurrencyCode = "USD";
                cc.CClearenceCurrencyRate = quote.QHeaderCurrencyRate;
                cc.CClearenceDate         = quote.QHeaderCreatedDate;
                cc.CClearenceMode         = 0;
                cc.QHeaderId = quote.QHeaderId;

                string sql = "INSERT INTO CustomsClearence ({0}) VALUES ({1}) " +
                             "SELECT SCOPE_IDENTITY()";

                EnumExtension.setListValues(cc, "CClearenceId", ref sql);

                SqlCommand cmd = new SqlCommand(sql, oConn);

                int keyGenerated = 0;
                keyGenerated = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            }
        }
コード例 #3
0
        public QuoteHeader GetHeader(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);
            };

            QuoteHeader data = GetHeader(id, oConn);

            // Check if this Quote General Charges
            var generalCharges = generalChargesRepo.GetListByQuote(data.QHeaderId);

            if (generalCharges.Count == 0)
            {
                loadGeneralCharges(data);
            }

            ConnManager.CloseConn(oConn);

            return(data);
        }
コード例 #4
0
        public QuoteHeader UpdateHeader(QuoteHeader 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;
            };

            QuoteHeader oldData = GetHeader(data.QHeaderId, oConn);

            data.QHeaderModifiedDate = DateTime.Now;
            string sql = "UPDATE QuoteHeader SET {0} WHERE QHeaderId = " + data.QHeaderId.ToString();

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

            SqlCommand cmd = new SqlCommand(sql, oConn);

            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);
                LogManager.Write("SQL: " + Environment.NewLine + "\t " + sql);
                msgError = ex.Message;
                return(null);
            }

            QuoteHeader returnData = GetHeader(data.QHeaderId, oConn);

            if (oldData.QHeaderCost != returnData.QHeaderCost)
            {
                RecalcItemCost(returnData, oConn);
            }

            if (customsClearenceRepo.GetByQuote(returnData.QHeaderId, 0) == null)
            {
                InsertCustomClearence(returnData, oConn);
            }

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
コード例 #5
0
        public QuoteHeader AddHeader(QuoteHeader 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.QHeaderCreatedDate = DateTime.Now;
            string sql = "INSERT INTO QuoteHeader ({0}) VALUES ({1}) " +
                         "SELECT SCOPE_IDENTITY()";


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


            SqlCommand cmd = new SqlCommand(sql, oConn);

            int keyGenerated = 0;

            try
            {
                keyGenerated = Convert.ToInt32(cmd.ExecuteScalar());
            }
            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);
            }

            QuoteHeader returnData = GetHeader(keyGenerated, oConn);

            InsertCustomClearence(returnData, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
コード例 #6
0
        private bool RemoveHeader(QuoteHeader data, SqlConnection oConn)
        {
            string sql = "DELETE FROM QuoteHeader " +
                         " WHERE (QHeaderId = {0})";

            sql = String.Format(sql, data.QHeaderId);

            SqlCommand cmd = new SqlCommand(sql, oConn);

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

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

            return(false);
        }
コード例 #7
0
        private void RecalcItemCost(QuoteHeader data, SqlConnection oConn)
        {
            string sql = "Select QDetailId,QDetailLineTotal,QDetailQty FROM QuoteDetails " +
                         " WHERE (QHeaderId = {0})";

            sql = String.Format(sql, data.QHeaderId);

            SqlCommand cmd = new SqlCommand(sql, oConn);

            SqlDataReader reader = cmd.ExecuteReader();

            cmd.Dispose();

            if (reader.HasRows)
            {
                int     detailId;
                decimal lineTotal;
                decimal qty;

                while (reader.Read())
                {
                    detailId  = reader.GetInt32(0);
                    lineTotal = reader.GetDecimal(1);
                    qty       = reader.GetDecimal(2);

                    decimal factor   = (Convert.ToDecimal(data.QHeaderTotal) != 0) ? lineTotal / Convert.ToDecimal(data.QHeaderTotal) : 0;
                    decimal lineCost = Math.Round(Convert.ToDecimal(data.QHeaderCost) * factor, 2);
                    decimal unitCost = Math.Round(lineCost / qty, 2);

                    string strLineCost = lineCost.ToString().Replace(',', '.');
                    string strUnitCost = unitCost.ToString().Replace(',', '.');

                    sql = "update x set x.QDetailLineCost = {0}, x.QDetailCost = {1} from QuoteDetails x where QDetailId={2}";
                    sql = String.Format(sql, strLineCost, strUnitCost, detailId);

                    cmd = new SqlCommand(sql, oConn);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                }
            }

            reader.Close();
        }
コード例 #8
0
        private void loadGeneralCharges(QuoteHeader data)
        {
            var list = chargesDescRepo.GetList();

            if (list.Count == 0)
            {
                return;
            }

            foreach (var item in list)
            {
                var gcharge = new GeneralCharge();

                gcharge.ChargeDescId       = item.ChargeDescId;
                gcharge.QHeaderId          = data.QHeaderId;
                gcharge.GChargeFactor      = item.ChargeDefaultFactor;
                gcharge.GChargeCreatedDate = data.QHeaderCreatedDate;
                gcharge.GChargeCreatedBy   = data.QHeaderCreatedBy;

                generalChargesRepo.Add(gcharge);
            }
        }