/// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(FinSupplierreturnReceiptContract finsupplierreturnreceipt, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Fin_SupplierReturn_Receipt
                                        VALUES ({0},{1},{2},{3},convert(datetime,{4},103))",

                                               (finsupplierreturnreceipt.Receiptid != null? finsupplierreturnreceipt.Receiptid.ToString() : "null").ToString(),
                                               (finsupplierreturnreceipt.Supplierreturnid != null? finsupplierreturnreceipt.Supplierreturnid.ToString() : "null").ToString(),
                                               (finsupplierreturnreceipt.Supplierid != null? finsupplierreturnreceipt.Supplierid.ToString() : "null").ToString(),
                                               (finsupplierreturnreceipt.Total.Trim() != String.Empty ? finsupplierreturnreceipt.Total.ToString() : "null").ToString(),
                                               (finsupplierreturnreceipt.Incomedate != null? "'" + SQLHelper.RejectInjection(finsupplierreturnreceipt.Incomedate.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("");
        }
示例#2
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.finsupplierreturnreceiptContract = (FinSupplierreturnReceiptContract)(instants[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(FinSupplierreturnReceiptContract finsupplierreturnreceipt, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET ReceiptID={0},SupplierReturnID={1},SupplierID={2},Total={3},IncomeDate=convert(datetime,{4},103)
                            WHERE ID=" + finsupplierreturnreceipt.Id.ToString(),
                                         (finsupplierreturnreceipt.Receiptid != null? finsupplierreturnreceipt.Receiptid.ToString() : "null").ToString(),
                                         (finsupplierreturnreceipt.Supplierreturnid != null? finsupplierreturnreceipt.Supplierreturnid.ToString() : "null").ToString(),
                                         (finsupplierreturnreceipt.Supplierid != null? finsupplierreturnreceipt.Supplierid.ToString() : "null").ToString(),
                                         (finsupplierreturnreceipt.Total.Trim() != String.Empty ? finsupplierreturnreceipt.Total.ToString() : "null").ToString(),
                                         (finsupplierreturnreceipt.Incomedate != null? "'" + SQLHelper.RejectInjection(finsupplierreturnreceipt.Incomedate.ToString()) + "'" : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(finsupplierreturnreceipt.Id.ToString());
        }
        public HttpResponseMessage Save(string finsupplierreturnreceiptJson)
        {
            string errMessage = string.Empty;

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