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 GetProductPrice(string productId, string storeId) { try { CatProductStoreDT storeDT = new CatProductStoreDT(); DataTable dt = storeDT.GetByCond("ProductID=" + productId + " AND StoreID =" + storeId); return(Request.CreateResponse <string>(HttpStatusCode.OK, JsonConvert.SerializeObject(dt))); } catch (Exception e) { ExceptionHandler.Log(e); return(null); } }
public CatProductStoreRule IsExits(string cond, string message) { try { DataTable dt = dta.GetByCond(cond); if (dt != null && dt.Rows.Count > 0) { IsPassed = false; ErrMessage += message; } return(this); } catch (Exception e) { IsPassed = false; throw e; } }