/// <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(SelReceiveproductContract selreceiveproduct, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET SaleStaffID={0},Code={1},InvoiceID={2},CustomerID={3},StoreID={4},CreateDate=convert(datetime,{5},103),Description={6},Total={7},TotalReturn={8},Discount={9},OrderNum={10} WHERE ID=" + selreceiveproduct.Id.ToString(), (selreceiveproduct.Salestaffid != null? selreceiveproduct.Salestaffid.ToString() : "null").ToString(), (selreceiveproduct.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(selreceiveproduct.Code.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Invoiceid != null? selreceiveproduct.Invoiceid.ToString() : "null").ToString(), (selreceiveproduct.Customerid != null? selreceiveproduct.Customerid.ToString() : "null").ToString(), (selreceiveproduct.Storeid != null? selreceiveproduct.Storeid.ToString() : "null").ToString(), (selreceiveproduct.Createdate != null? "'" + SQLHelper.RejectInjection(selreceiveproduct.Createdate.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(selreceiveproduct.Description.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Total.Trim() != String.Empty ? selreceiveproduct.Total.ToString() : "null").ToString(), (selreceiveproduct.Totalreturn.Trim() != String.Empty ? selreceiveproduct.Totalreturn.ToString() : "null").ToString(), (selreceiveproduct.Discount.Trim() != String.Empty ? selreceiveproduct.Discount.ToString() : "null").ToString(), (selreceiveproduct.Ordernum.Trim() != String.Empty ? selreceiveproduct.Ordernum.ToString() : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(selreceiveproduct.Id.ToString()); }
/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(SelReceiveproductContract selreceiveproduct, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Sel_ReceiveProduct VALUES ({0},{1},{2},{3},{4},convert(datetime,{5},103),{6},{7},{8},{9},{10})", (selreceiveproduct.Salestaffid != null? selreceiveproduct.Salestaffid.ToString() : "null").ToString(), (selreceiveproduct.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(selreceiveproduct.Code.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Invoiceid != null? selreceiveproduct.Invoiceid.ToString() : "null").ToString(), (selreceiveproduct.Customerid != null? selreceiveproduct.Customerid.ToString() : "null").ToString(), (selreceiveproduct.Storeid != null? selreceiveproduct.Storeid.ToString() : "null").ToString(), (selreceiveproduct.Createdate != null? "'" + SQLHelper.RejectInjection(selreceiveproduct.Createdate.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(selreceiveproduct.Description.ToString()) + "'" : "null").ToString(), (selreceiveproduct.Total.Trim() != String.Empty ? selreceiveproduct.Total.ToString() : "null").ToString(), (selreceiveproduct.Totalreturn.Trim() != String.Empty ? selreceiveproduct.Totalreturn.ToString() : "null").ToString(), (selreceiveproduct.Discount.Trim() != String.Empty ? selreceiveproduct.Discount.ToString() : "null").ToString(), (selreceiveproduct.Ordernum.Trim() != String.Empty ? selreceiveproduct.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(""); }
override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.selreceiveproductContract = (SelReceiveproductContract)(instants[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; } }
public HttpResponseMessage Save(string recvProductJson, string recvProductDetailsJson) { string recvProductId = ""; string errMessage = ""; SelReceiveproductContract recvProductDTO = JsonConvert.DeserializeObject <SelReceiveproductContract>(recvProductJson); SelReceiveproductDetailContract[] suppReturnDetailDTOs = JsonConvert.DeserializeObject <SelReceiveproductDetailContract[]>(recvProductDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(recvProductDTO); if (recvProductDTO.Id > 0) { recvProductId = recvProductDT.Update(recvProductDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { recvProductId = recvProductDT.Insert(recvProductDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(recvProductId) > 0) { foreach (SelReceiveproductDetailContract invoiceDetailDTO in suppReturnDetailDTOs) { invoiceDetailDTO.Receiveproductid = Converter.ToInt32(recvProductId); rvcProductDetailDT.Insert(invoiceDetailDTO, tran); StoreModel.ReceiveProduct(recvProductDTO, invoiceDetailDTO, tran); } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : recvProductId)); }
public HttpResponseMessage Save(string selreceiveproductJson) { string errMessage = string.Empty; try { SelReceiveproductContract selreceiveproduct = JsonConvert.DeserializeObject <SelReceiveproductContract>(selreceiveproductJson); businessRule.RegistInstants(selreceiveproduct); if (selreceiveproduct.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(selreceiveproduct))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(selreceiveproduct))); } 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 SelReceiveproductRule ValidateInstant(SelReceiveproductContract dto) { return(this); }