Пример #1
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.catproductContract = (CatProductContract)(instants[0]);
     }
 }
Пример #2
0
        /// <summary>
        /// Cập nhật thông tin đối tượng
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public string Update(CatProductContract catproduct, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},UnitID={2},ColorID={3},SupplierID={4},ManufactureID={5},ProductTypeID={6},ProductGroupID={7},BranchID={8},Description={9},Blocked={10},IsComponent={11},Barcode={12},WarningNum={13},OrderNum={14}
                            WHERE ID=" + catproduct.Id.ToString(),
                                         (catproduct.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Code.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Name.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Unitid != null? catproduct.Unitid.ToString() : "null").ToString(),
                                         (catproduct.Colorid != null? catproduct.Colorid.ToString() : "null").ToString(),
                                         (catproduct.Supplierid != null? catproduct.Supplierid.ToString() : "null").ToString(),
                                         (catproduct.Manufactureid != null? catproduct.Manufactureid.ToString() : "null").ToString(),
                                         (catproduct.Producttypeid != null? catproduct.Producttypeid.ToString() : "null").ToString(),
                                         (catproduct.Productgroupid != null? catproduct.Productgroupid.ToString() : "null").ToString(),
                                         (catproduct.Branchid != null? catproduct.Branchid.ToString() : "null").ToString(),
                                         (catproduct.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Description.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Blocked != null? "'" + SQLHelper.RejectInjection(catproduct.Blocked.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Iscomponent != null? "'" + SQLHelper.RejectInjection(catproduct.Iscomponent.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Barcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Barcode.ToString()) + "'" : "null").ToString(),
                                         (catproduct.Warningnum.Trim() != String.Empty ? catproduct.Warningnum.ToString() : "null").ToString(),
                                         (catproduct.Ordernum.Trim() != String.Empty ? catproduct.Ordernum.ToString() : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(catproduct.Id.ToString());
        }
Пример #3
0
        public HttpResponseMessage SaveProduct(string productJson, string priceJson)
        {
            string         productId = "";
            SqlTransaction tran      = DataProvider.beginTrans();

            try
            {
                CatProductContract        product = JsonConvert.DeserializeObject <CatProductContract>(productJson);
                CatProductPriceContract[] prices  = JsonConvert.DeserializeObject <CatProductPriceContract[]>(priceJson);
                if (product.Id > 0)
                {
                    productId = productDT.Update(product, tran);
                }
                else
                {
                    productId = productDT.Insert(product, tran);
                }
                deleteOldPrice(productId, tran);
                foreach (CatProductPriceContract price in prices)
                {
                    price.Productid = Converter.ToInt32(productId);
                    priceDT.Insert(price, tran);
                }
                DataProvider.CommitTrans(tran);
            }
            catch (Exception e)
            {
                DataProvider.RollbackTrans(tran);
                ExceptionHandler.Log(e);
                return(null);
            }
            return(Request.CreateResponse <string>(HttpStatusCode.OK, productId));
        }
Пример #4
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(CatProductContract catproduct, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Cat_Product
                                        VALUES ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14})",

                                               (catproduct.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Code.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Name.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Unitid != null? catproduct.Unitid.ToString() : "null").ToString(),
                                               (catproduct.Colorid != null? catproduct.Colorid.ToString() : "null").ToString(),
                                               (catproduct.Supplierid != null? catproduct.Supplierid.ToString() : "null").ToString(),
                                               (catproduct.Manufactureid != null? catproduct.Manufactureid.ToString() : "null").ToString(),
                                               (catproduct.Producttypeid != null? catproduct.Producttypeid.ToString() : "null").ToString(),
                                               (catproduct.Productgroupid != null? catproduct.Productgroupid.ToString() : "null").ToString(),
                                               (catproduct.Branchid != null? catproduct.Branchid.ToString() : "null").ToString(),
                                               (catproduct.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Description.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Blocked != null? "'" + SQLHelper.RejectInjection(catproduct.Blocked.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Iscomponent != null? "'" + SQLHelper.RejectInjection(catproduct.Iscomponent.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Barcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproduct.Barcode.ToString()) + "'" : "null").ToString(),
                                               (catproduct.Warningnum.Trim() != String.Empty ? catproduct.Warningnum.ToString() : "null").ToString(),
                                               (catproduct.Ordernum.Trim() != String.Empty ? catproduct.Ordernum.ToString() : "null").ToString());

            query += " ; select SCOPE_IDENTITY();";
            if (tran == null)
            {
                dtResult = DataProvider.ExecuteQuery(query);
            }
            else
            {
                dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran);
            }
            if (dtResult != null && dtResult.Rows.Count > 0)
            {
                return(dtResult.Rows[0][0].ToString());
            }
            return("");
        }
Пример #5
0
        public HttpResponseMessage Save(string catproductJson)
        {
            string errMessage = string.Empty;

            try
            { CatProductContract catproduct = JsonConvert.DeserializeObject <CatProductContract>(catproductJson);
              businessRule.RegistInstants(catproduct);
              if (catproduct.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catproduct)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catproduct)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              } }
            catch (Exception e)
            {
                ExceptionHandler.Log(e);
                return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình."));
            }
        }
Пример #6
0
 public CatProductRule ValidateInstant(CatProductContract dto)
 {
     return(this);
 }