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

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

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

            try
            { SelReceiveproductDetailContract selreceiveproductdetail = JsonConvert.DeserializeObject <SelReceiveproductDetailContract>(selreceiveproductdetailJson);
              businessRule.RegistInstants(selreceiveproductdetail);
              if (selreceiveproductdetail.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(selreceiveproductdetail)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(selreceiveproductdetail)));
                  }
                  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."));
            }
        }
Beispiel #5
0
 public SelReceiveproductDetailRule ValidateInstant(SelReceiveproductDetailContract dto)
 {
     return(this);
 }
Beispiel #6
0
 public static void ReceiveProduct(SelReceiveproductContract receiveProductDTO, SelReceiveproductDetailContract receiveProductDetailDTO, SqlTransaction tran)
 {
     try
     {
         SelInvoiceDT invoiceDT = new SelInvoiceDT();
         DataTable    dtInvoice = invoiceDT.GetByID(receiveProductDTO.Invoiceid.ToString());
         if (dtInvoice != null && dtInvoice.Rows.Count > 0)
         {
             string invoiceCode = dtInvoice.Rows[0]["Code"].ToString();
             returnStore(invoiceCode, (int)receiveProductDTO.Storeid, (int)receiveProductDetailDTO.Productid, receiveProductDetailDTO.Quantity, tran);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }