public static string Exchange(StoExchangeContract storeExchangeDTO, StoExchangeDetailContract storeExchangeDetailDTO, SqlTransaction tran) { try { CatProductStoreContract productStoreDTO = new CatProductStoreContract(); string storeCond = "StoreID=" + storeExchangeDTO.Fromstoreid + " AND ProductId=" + storeExchangeDetailDTO.Productid; DataTable fromStoreProductTable = productStoreDT.GetByCond(storeCond, " OrderNum ASC"); var totalQuantity = fromStoreProductTable.Compute("SUM(Quantity)", ""); if (Converter.ToInt32(totalQuantity) < Converter.ToInt32(storeExchangeDetailDTO.Quantity)) { return(string.Format("Lỗi: Số lượng trong không đủ để chuyển.")); } else if (storeExchangeDTO.Fromstoreid == storeExchangeDTO.Tostoreid) { return(""); } else { int tmpQuantity = 0; foreach (DataRow row in fromStoreProductTable.Rows) { tmpQuantity += Converter.ToInt32(row["Quantity"]); if (tmpQuantity < Converter.ToInt32(storeExchangeDetailDTO.Quantity)) { productStoreDTO.Importcode = row["ImportCode"].ToString(); productStoreDTO.Importdate = row["ImportDate"].ToString(); productStoreDTO.Storeid = storeExchangeDTO.Tostoreid; productStoreDTO.Productid = storeExchangeDetailDTO.Productid; productStoreDTO.Inventory = row["Quantity"].ToString(); productStoreDTO.Quantity = row["Quantity"].ToString(); productStoreDTO.Price = row["Price"].ToString(); productStoreDTO.Ordernum = row["OrderNum"].ToString(); productStoreDT.Insert(productStoreDTO, tran); productStoreDT.Update(new string[] { "Quantity" }, new string[] { "0" }, "ID=" + row["ID"].ToString(), tran); } else { int exchangedQuantity = Converter.ToInt32(row["Quantity"]) - (tmpQuantity - Converter.ToInt32(storeExchangeDetailDTO.Quantity)); int rowNewQuantity = Converter.ToInt32(row["Quantity"]) - exchangedQuantity; productStoreDTO.Importcode = row["ImportCode"].ToString(); productStoreDTO.Importdate = row["ImportDate"].ToString(); productStoreDTO.Storeid = storeExchangeDTO.Tostoreid; productStoreDTO.Productid = storeExchangeDetailDTO.Productid; productStoreDTO.Inventory = exchangedQuantity.ToString(); productStoreDTO.Quantity = exchangedQuantity.ToString(); productStoreDTO.Price = row["Price"].ToString(); productStoreDTO.Ordernum = row["OrderNum"].ToString(); productStoreDT.Insert(productStoreDTO, tran); productStoreDT.Update(new string[] { "Quantity" }, new string[] { rowNewQuantity.ToString() }, "ID=" + row["ID"].ToString(), tran); break; } } } } catch (Exception e) { throw e; } return(""); }
/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(StoExchangeDetailContract stoexchangedetail, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Sto_Exchange_Detail VALUES ({0},{1},{2},{3},{4},convert(datetime,{5},103))", (stoexchangedetail.Exchangeid != null? stoexchangedetail.Exchangeid.ToString() : "null").ToString(), (stoexchangedetail.Productid != null? stoexchangedetail.Productid.ToString() : "null").ToString(), (stoexchangedetail.Quantity.Trim() != String.Empty ? stoexchangedetail.Quantity.ToString() : "null").ToString(), (stoexchangedetail.Ordernum.Trim() != String.Empty ? stoexchangedetail.Ordernum.ToString() : "null").ToString(), (stoexchangedetail.Deleted != null? "'" + SQLHelper.RejectInjection(stoexchangedetail.Deleted.ToString()) + "'" : "null").ToString(), (stoexchangedetail.Deletedon != null? "'" + SQLHelper.RejectInjection(stoexchangedetail.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(""); }
override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.stoexchangedetailContract = (StoExchangeDetailContract)(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(StoExchangeDetailContract stoexchangedetail, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET ExchangeID={0},ProductID={1},Quantity={2},OrderNum={3},Deleted={4},DeletedOn=convert(datetime,{5},103) WHERE ID=" + stoexchangedetail.Id.ToString(), (stoexchangedetail.Exchangeid != null? stoexchangedetail.Exchangeid.ToString() : "null").ToString(), (stoexchangedetail.Productid != null? stoexchangedetail.Productid.ToString() : "null").ToString(), (stoexchangedetail.Quantity.Trim() != String.Empty ? stoexchangedetail.Quantity.ToString() : "null").ToString(), (stoexchangedetail.Ordernum.Trim() != String.Empty ? stoexchangedetail.Ordernum.ToString() : "null").ToString(), (stoexchangedetail.Deleted != null? "'" + SQLHelper.RejectInjection(stoexchangedetail.Deleted.ToString()) + "'" : "null").ToString(), (stoexchangedetail.Deletedon != null? "'" + SQLHelper.RejectInjection(stoexchangedetail.Deletedon.ToString()) + "'" : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(stoexchangedetail.Id.ToString()); }
public HttpResponseMessage Save(string stoexchangedetailJson) { string errMessage = string.Empty; try { StoExchangeDetailContract stoexchangedetail = JsonConvert.DeserializeObject <StoExchangeDetailContract>(stoexchangedetailJson); businessRule.RegistInstants(stoexchangedetail); if (stoexchangedetail.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(stoexchangedetail))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(stoexchangedetail))); } 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 StoExchangeDetailRule ValidateInstant(StoExchangeDetailContract dto) { return(this); }