Example #1
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.buypodetailContract = (BuyPoDetailContract)(instants[0]);
     }
 }
Example #2
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(BuyPoDetailContract buypodetail, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Buy_PO_Detail
                                        VALUES ({0},{1},{2},{3},{4},{5},convert(datetime,{6},103))",

                                               (buypodetail.Poid != null? buypodetail.Poid.ToString() : "null").ToString(),
                                               (buypodetail.Productid != null? buypodetail.Productid.ToString() : "null").ToString(),
                                               (buypodetail.Quantity.Trim() != String.Empty ? buypodetail.Quantity.ToString() : "null").ToString(),
                                               (buypodetail.Price.Trim() != String.Empty ? buypodetail.Price.ToString() : "null").ToString(),
                                               (buypodetail.Ordernum.Trim() != String.Empty ? buypodetail.Ordernum.ToString() : "null").ToString(),
                                               (buypodetail.Deleted != null? "'" + SQLHelper.RejectInjection(buypodetail.Deleted.ToString()) + "'" : "null").ToString(),
                                               (buypodetail.Deletedon != null? "'" + SQLHelper.RejectInjection(buypodetail.Deletedon.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("");
        }
Example #3
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(BuyPoDetailContract buypodetail, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET POID={0},ProductID={1},Quantity={2},Price={3},OrderNum={4},Deleted={5},DeletedOn=convert(datetime,{6},103)
                            WHERE ID=" + buypodetail.Id.ToString(),
                                         (buypodetail.Poid != null? buypodetail.Poid.ToString() : "null").ToString(),
                                         (buypodetail.Productid != null? buypodetail.Productid.ToString() : "null").ToString(),
                                         (buypodetail.Quantity.Trim() != String.Empty ? buypodetail.Quantity.ToString() : "null").ToString(),
                                         (buypodetail.Price.Trim() != String.Empty ? buypodetail.Price.ToString() : "null").ToString(),
                                         (buypodetail.Ordernum.Trim() != String.Empty ? buypodetail.Ordernum.ToString() : "null").ToString(),
                                         (buypodetail.Deleted != null? "'" + SQLHelper.RejectInjection(buypodetail.Deleted.ToString()) + "'" : "null").ToString(),
                                         (buypodetail.Deletedon != null? "'" + SQLHelper.RejectInjection(buypodetail.Deletedon.ToString()) + "'" : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(buypodetail.Id.ToString());
        }
Example #4
0
        public HttpResponseMessage Save(string buypodetailJson)
        {
            string errMessage = string.Empty;

            try
            { BuyPoDetailContract buypodetail = JsonConvert.DeserializeObject <BuyPoDetailContract>(buypodetailJson);
              businessRule.RegistInstants(buypodetail);
              if (buypodetail.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(buypodetail)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(buypodetail)));
                  }
                  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."));
            }
        }
Example #5
0
 public BuyPoDetailRule ValidateInstant(BuyPoDetailContract dto)
 {
     return(this);
 }