public static string Export(string storeId, string exportCode, int quantity, string productId, SqlTransaction tran) { try { DataTable storeProductTable = productStoreDT.GetByCond("ProductID=" + productId + " AND StoreID = " + storeId + " AND Quantity >0 ", "OrderNum ASC", tran); int tmpQuantity = 0; var totalQuantity = storeProductTable.Compute("SUM(Quantity)", ""); if (Converter.ToInt32(totalQuantity) < quantity) { return("Lỗi: Sản phẩm trong kho không đủ để xuất"); } else { foreach (DataRow row in storeProductTable.Rows) { LogProductexportContract productExportDTO = new LogProductexportContract(); string storeProductId = row["ID"].ToString(); tmpQuantity += Converter.ToInt32(row["Quantity"]); if (tmpQuantity < quantity) { productExportDTO.Storeid = storeId; productExportDTO.Productid = productId; productExportDTO.Importcode = row["ImportCode"].ToString(); productExportDTO.Quantity = row["Quantity"].ToString(); productExportDTO.Exportdate = DateTime.Now.ToString("dd/MM/yyyy"); productExportDTO.Exportcode = exportCode; productExportDTO.Importprice = row["Price"].ToString(); productExportDTO.Exportprice = productId; productExportDT.Insert(productExportDTO, tran); productStoreDT.Update(new string[] { "Quantity" }, new string[] { "0" }, " ID=" + storeProductId, tran); } else { int exportQuantity = Converter.ToInt32(row["Quantity"]) - (tmpQuantity - quantity); int productStoreQuantity = Converter.ToInt32(row["Quantity"]) - exportQuantity; productExportDTO.Storeid = storeId; productExportDTO.Productid = productId; productExportDTO.Importcode = row["ImportCode"].ToString(); productExportDTO.Quantity = exportQuantity.ToString(); productExportDTO.Exportdate = DateTime.Now.ToString("dd/MM/yyyy"); productExportDTO.Exportcode = exportCode; productExportDTO.Importprice = row["Price"].ToString(); productExportDTO.Exportprice = productId; productExportDT.Insert(productExportDTO, tran); productStoreDT.Update(new string[] { "Quantity" }, new string[] { productStoreQuantity.ToString() }, " ID=" + storeProductId, tran); break; } } } } catch (Exception e) { throw e; } return(""); }
public HttpResponseMessage Save(string catproductstoreJson) { string errMessage = string.Empty; try { CatProductStoreContract catproductstore = JsonConvert.DeserializeObject <CatProductStoreContract>(catproductstoreJson); businessRule.RegistInstants(catproductstore); if (catproductstore.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catproductstore))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catproductstore))); } 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.")); } }