Пример #1
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(FinMoneyslipContract finmoneyslip, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Fin_MoneySlip
                                        VALUES ({0},{1},{2},{3},convert(datetime,{4},103),{5},{6},{7})",

                                               (finmoneyslip.Salestaffid != null? finmoneyslip.Salestaffid.ToString() : "null").ToString(),
                                               (finmoneyslip.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(finmoneyslip.Code.ToString()) + "'" : "null").ToString(),
                                               (finmoneyslip.Paymenttypeid != null? finmoneyslip.Paymenttypeid.ToString() : "null").ToString(),
                                               (finmoneyslip.Totalpay.Trim() != String.Empty ? finmoneyslip.Totalpay.ToString() : "null").ToString(),
                                               (finmoneyslip.Createdate != null? "'" + SQLHelper.RejectInjection(finmoneyslip.Createdate.ToString()) + "'" : "null").ToString(),
                                               (finmoneyslip.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(finmoneyslip.Description.ToString()) + "'" : "null").ToString(),
                                               (finmoneyslip.Type.Trim() != String.Empty ? finmoneyslip.Type.ToString() : "null").ToString(),
                                               (finmoneyslip.Ordernum.Trim() != String.Empty ? finmoneyslip.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("");
        }
Пример #2
0
        public HttpResponseMessage Save(string moneyslipJson, string moneyslipDetailJson)
        {
            SqlTransaction tran = DataProvider.beginTrans();

            try
            {
                FinMoneyslipContract moneyslipDTO = JsonConvert.DeserializeObject <FinMoneyslipContract>(moneyslipJson);
                int moneyslipId = moneyslipDTO.Id;
                if (moneyslipId == 0)
                {
                    {
                        moneyslipId = Converter.ToInt32(moneyslipDT.Insert(moneyslipDTO, tran));
                    }
                    if (moneyslipDTO.Type == "1")
                    {
                        SaveImportPayment(moneyslipId, moneyslipDetailJson, tran);
                    }
                    else if (moneyslipDTO.Type == "2")
                    {
                        SaveSuppReceipt(moneyslipId, moneyslipDetailJson, tran);
                    }
                }
                tran.Commit();
                return(Request.CreateResponse <string>(HttpStatusCode.OK, moneyslipId.ToString()));
            }
            catch (Exception e)
            {
                ExceptionHandler.Log(e);
                tran.Rollback();
                return(Request.CreateResponse <string>(HttpStatusCode.OK, "Lỗi: Không lưu thành công."));;
            }
        }
Пример #3
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.finmoneyslipContract = (FinMoneyslipContract)(instants[0]);
     }
 }
Пример #4
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(FinMoneyslipContract finmoneyslip, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET SaleStaffID={0},Code={1},PaymentTypeID={2},TotalPay={3},CreateDate=convert(datetime,{4},103),Description={5},Type={6},OrderNum={7}
                            WHERE ID=" + finmoneyslip.Id.ToString(),
                                         (finmoneyslip.Salestaffid != null? finmoneyslip.Salestaffid.ToString() : "null").ToString(),
                                         (finmoneyslip.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(finmoneyslip.Code.ToString()) + "'" : "null").ToString(),
                                         (finmoneyslip.Paymenttypeid != null? finmoneyslip.Paymenttypeid.ToString() : "null").ToString(),
                                         (finmoneyslip.Totalpay.Trim() != String.Empty ? finmoneyslip.Totalpay.ToString() : "null").ToString(),
                                         (finmoneyslip.Createdate != null? "'" + SQLHelper.RejectInjection(finmoneyslip.Createdate.ToString()) + "'" : "null").ToString(),
                                         (finmoneyslip.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(finmoneyslip.Description.ToString()) + "'" : "null").ToString(),
                                         (finmoneyslip.Type.Trim() != String.Empty ? finmoneyslip.Type.ToString() : "null").ToString(),
                                         (finmoneyslip.Ordernum.Trim() != String.Empty ? finmoneyslip.Ordernum.ToString() : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(finmoneyslip.Id.ToString());
        }
Пример #5
0
        public HttpResponseMessage Save(string finmoneyslipJson)
        {
            string errMessage = string.Empty;

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