Example #1
0
        public bool Remove(PurchaseOrderVendor 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 = Remove(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);
        }
Example #2
0
        public PurchaseOrderVendor Add(PurchaseOrderVendor data, User currentUser, 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.POVCreatedDate = DateTime.Now;
            string sql = "INSERT INTO PurchaseOrdersVendors ({0}) VALUES ({1}) " +
                         "SELECT SCOPE_IDENTITY()";

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

            SqlTransaction oTX = oConn.BeginTransaction();

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

            int keyGenerated = 0;

            try
            {
                keyGenerated = Convert.ToInt32(cmd.ExecuteScalar());
                if (data.POVType == "PO")
                {
                    cmd.Dispose();
                    cmd.CommandText = String.Format("UPDATE QuoteHeader SET QHeaderOC='{1}' WHERE QHeaderId={0}", data.QHeaderId, data.POVPaymentNumber);
                    cmd.ExecuteNonQuery();
                }
            }
            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();

            PurchaseOrderVendor returnData = Get(keyGenerated, currentUser.UserId, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
Example #3
0
        public PurchaseOrderVendor Update(IDictionary <String, object> data, User currentUser, 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;
            };
            string userId = (currentUser != null) ? currentUser.UserId : "";
            int    id     = Convert.ToInt32(data["POVId"]);

            if (data.ContainsKey("x_Selected"))
            {
                handleSelected(currentUser, id, (bool)data["x_Selected"], oConn, ref msgError);
                PurchaseOrderVendor pov = Get(id, userId, oConn);
                ConnManager.CloseConn(oConn);
                return(pov);
            }

            data.Add("POVModifiedDate", DateTime.Now);
            string sql = "UPDATE PurchaseOrdersVendors SET {0} WHERE POVId = @id";

            EnumExtension.SetValuesForUpdate(data, "POVId", ref sql);

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;

            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);
            }

            PurchaseOrderVendor returnData = Get(id, userId, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
Example #4
0
        private bool Remove(PurchaseOrderVendor data, SqlConnection oConn)
        {
            string sql = "DELETE FROM PurchaseOrdersVendors " +
                         " WHERE (POVId = {0})";

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

            SqlCommand cmd = new SqlCommand(sql, oConn);

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

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

            return(false);
        }
Example #5
0
        public PurchaseOrderVendor Get(int id, User currentUser, 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);
            };

            PurchaseOrderVendor data = Get(id, currentUser.UserId, oConn);

            ConnManager.CloseConn(oConn);

            return(data);
        }