protected void btnImport_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 1) { int AgentID = Convert.ToInt32(acc.AgentID); string list = hdfvalue.Value; string note = hdfNote.Value; string[] items = list.Split(';'); if (items.Length - 1 > 0) { int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 2, currentDate, username).ToInt(0); if (SessionInOutID > 0) { for (int i = 0; i < items.Length - 1; i++) { //list += id + "," + sku + "," + producttype + "," + productnariablename + "," + productvariablevalue + "," + quantity + "|"; var item = items[i]; string[] itemValue = item.Split(','); int ID = itemValue[0].ToInt(); string SKU = itemValue[1]; int producttype = itemValue[2].ToInt(); string ProductVariableName = itemValue[3]; string ProductVariableValue = itemValue[4]; double Quantity = Convert.ToDouble(itemValue[5]); string ProductName = itemValue[6]; string ProductImageOrigin = itemValue[7]; string ProductVariable = itemValue[8]; string noteeach = itemValue[9]; double QuantityInStock = Convert.ToDouble(itemValue[10]); if (!string.IsNullOrEmpty(noteeach)) { noteeach = "Cập nhật số lượng sản phẩm khi kiểm kho ngày: " + string.Format("0:dd/MM/yyyy", currentDate); } if (Quantity > QuantityInStock) { double slIn = Quantity - QuantityInStock; if (producttype == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = slIn, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = 1, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = ID }); } else { int parentID = 0; string parentSKU = ""; var productV = ProductVariableController.GetByID(ID); if (productV != null) { parentSKU = productV.ParentSKU; } if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = slIn, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = 1, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID }); } } else if (Quantity < QuantityInStock) { double slOut = QuantityInStock - Quantity; if (producttype == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = slOut, QuantityCurrent = 0, Type = 2, NoteID = noteeach, OrderID = 0, Status = 2, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = ID }); } else { int parentID = 0; string parentSKU = ""; var productV = ProductVariableController.GetByID(ID); if (productV != null) { parentSKU = productV.ParentSKU; } if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = slOut, QuantityCurrent = 0, Type = 2, NoteID = noteeach, OrderID = 0, Status = 2, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID }); } } } PJUtils.ShowMessageBoxSwAlert("Kiểm kho thành công", "s", true, Page); } } } } }
protected void btnImport_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 1) { int AgentID = Convert.ToInt32(acc.AgentID); string list = hdfvalue.Value; string note = "Xuất kho bằng chức năng xuất kho"; if (hdfNote.Value != "") { note = hdfNote.Value; } string[] items = list.Split(';'); if (items.Length - 1 > 0) { int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 2, currentDate, username).ToInt(0); if (SessionInOutID > 0) { for (int i = 0; i < items.Length - 1; i++) { var item = items[i]; string[] itemValue = item.Split(','); int ID = itemValue[0].ToInt(); string SKU = itemValue[1]; int producttype = itemValue[2].ToInt(); string ProductVariableName = itemValue[3]; string ProductVariableValue = itemValue[4]; double Quantity = Convert.ToDouble(itemValue[5]); string ProductName = itemValue[6]; string ProductImageOrigin = itemValue[7]; string ProductVariable = itemValue[8]; if (producttype == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = note, OrderID = 0, Status = 2, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = ID, }); } else { int parentID = 0; string parentSKU = ""; var productV = ProductVariableController.GetByID(ID); if (productV != null) { parentSKU = productV.ParentSKU; } if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = note, OrderID = 0, Status = 2, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID, }); } } PJUtils.ShowMessageBoxSwAlert("Xuất kho thành công", "s", true, Page); } } } } }
protected void btnImport_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int AgentID = Convert.ToInt32(acc.AgentID); string list = hdfvalue.Value; string note = "Nhập kho bằng chức năng nhập kho"; if (hdfNote.Value != "") { note = hdfNote.Value; } string jsonurl = ""; string[] items = list.Split(';'); if (items.Length - 1 > 0) { int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 1, currentDate, username).ToInt(0); if (SessionInOutID > 0) { for (int i = 0; i < items.Length - 1; i++) { var item = items[i]; string[] itemValue = item.Split(','); int ID = itemValue[0].ToInt(); string SKU = itemValue[1]; int producttype = itemValue[2].ToInt(); string ProductVariableName = itemValue[3]; string ProductVariableValue = itemValue[4]; double Quantity = Convert.ToDouble(itemValue[5]); string ProductName = itemValue[6]; string ProductImageOrigin = itemValue[7]; string ProductVariable = itemValue[8]; var productV = ProductVariableController.GetByID(ID); string parentSKU = ""; parentSKU = productV.ParentSKU; if (producttype == 1) { ProductController.UpdateStockStatus(parentSKU, 1, false, currentDate, username); StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = Quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = 1, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = ID }); } else { int parentID = 0; if (productV != null) { if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = Quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = 1, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID }); } ProductVariableController.UpdateStockStatus(ID, 1, false, currentDate, username); double total = PJUtils.TotalProductQuantityInstock(AgentID, itemValue[1]); if (i == items.Length - 2) { jsonurl += "{\"id\":\"" + itemValue[0] + "\"," + "\"stock\":\"" + total + "\"}]"; } else { jsonurl += "[{\"id\":\"" + itemValue[0] + "\"," + "\"stock\":\"" + total + "\"},"; } } } var domain = WhiteDomainController.GetAll(); if (domain != null) { foreach (var item in domain) { var httpWebRequest = (HttpWebRequest)WebRequest.Create("" + item.Domain + ""); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"key\":\"asdasdasd\"," + "\"list_stock\":" + jsonurl + "}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } } } string barcodeValue = ""; string productPrint = ""; string barcodeImage = ""; string[] value = hdfBarcode.Value.Split(';'); if (value.Count() > 1) { var temps = new List <String>(); productPrint += "<div class=\"qcode\">"; for (int i = 0; i < value.Length - 1; i++) { string[] list2 = value[i].Split(','); int quantity = list2[1].ToInt(); for (int j = 0; j < quantity; j++) { barcodeValue = list2[0]; var imageName = String.Format("{0}{1}.png", DateTime.UtcNow.ToString("yyyyMMddHHmmss"), Guid.NewGuid()); barcodeImage = "/uploads/barcodes/" + imageName; System.Drawing.Image barCode = PJUtils.MakeBarcodeImage(barcodeValue, 2, true); barCode.Save(HttpContext.Current.Server.MapPath("" + barcodeImage + ""), ImageFormat.Png); productPrint += "<div class=\"item\">"; productPrint += "<div class=\"img\"><img src=\"data:image/png;base64, " + Convert.ToBase64String(File.ReadAllBytes(Server.MapPath("" + barcodeImage + ""))) + "\"></div>"; productPrint += "<div><h1>" + barcodeValue + "</h1></div>"; productPrint += "</div>"; temps.Add(imageName); } } productPrint += "</div>"; string html = ""; html += productPrint; ltrprint.Text = html; // Delete barcode image after print string[] filePaths = Directory.GetFiles(Server.MapPath("/uploads/barcodes/")); foreach (string filePath in filePaths) { foreach (var item in temps) { if (filePath.EndsWith(item)) { File.Delete(filePath); } } } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printBarcode() });", true); } else { PJUtils.ShowMessageBoxSwAlert("Nhập kho thành công!", "s", true, Page); } } } }