protected void btnSubmit_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["usernameLoginSystem"].Value; int id = Convert.ToInt32(ViewState["ID"]); var pv = ProductVariableController.GetByID(id); if (pv != null) { string parentSKU = ViewState["productsku"].ToString(); int productID = ViewState["productid"].ToString().ToInt(0); bool isHidden = chkIsHidden.Checked; string SKU = ViewState["SKU"].ToString(); double Stock = Convert.ToDouble(pv.Stock); double Regular_Price = Convert.ToDouble(pRegular_Price.Text); double CostOfGood = Convert.ToDouble(pCostOfGood.Text); double RetailPrice = Convert.ToDouble(pRetailPrice.Text); int StockStatus = Convert.ToInt32(pv.StockStatus); bool ManageStock = true; //Phần thêm ảnh đại diện sản phẩm string path = "/uploads/images/"; string ProductImage = ListProductThumbnail.Value; if (ProductThumbnailImage.UploadedFiles.Count > 0) { foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles) { var o = path + productID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); try { f.SaveAs(Server.MapPath(o)); ProductImage = o; } catch { } } } if (ProductImage != ListProductThumbnail.Value) { if (File.Exists(Server.MapPath(ListProductThumbnail.Value))) { File.Delete(Server.MapPath(ListProductThumbnail.Value)); } } ProductVariableController.Update(id, productID, parentSKU, SKU, Stock, StockStatus, Regular_Price, CostOfGood, RetailPrice, ProductImage, ManageStock, isHidden, currentDate, username, Convert.ToInt32(pv.SupplierID), pv.SupplierName, Convert.ToDouble(pMinimumInventoryLevel.Text), Convert.ToDouble(pMaximumInventoryLevel.Text)); PJUtils.ShowMessageBoxSwAlert("Cập nhật thuộc tính thành công", "s", true, Page); } }
public void LoadData() { int productvariableid = Request.QueryString["productvariableid"].ToInt(0); if (productvariableid > 0) { var pv = ProductVariableController.GetByID(productvariableid); if (pv != null) { ViewState["productvariableid"] = productvariableid; ViewState["ProductvariableSKU"] = pv.SKU; ltrBack.Text = "<a href=\"/gia-tri-thuoc-tinh-san-pham.aspx?productvariableid=" + productvariableid + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>"; } } }
public void LoadData() { List <tbl_ProductVariableValue> a = new List <tbl_ProductVariableValue>(); int productvariableid = Request.QueryString["productvariableid"].ToInt(0); if (productvariableid > 0) { var pv = ProductVariableController.GetByID(productvariableid); if (pv != null) { ltrBack.Text = "<a href=\"/thuoc-tinh-san-pham?id=" + pv.ProductID + "\" class=\"btn primary-btn h45-btn\">Trở về</a>"; lblCategoryName.Text = "Giá trị thuộc tính sản phẩm"; ltrAddnew.Text = "<a href=\"/them-gia-tri-thuoc-tinh?productvariableid=" + productvariableid + "\" class=\"h45-btn btn\" style=\"background-color: #ff3f4c\">Thêm mới</a>"; } a = ProductVariableValueController.GetByProductVariableID(productvariableid); pagingall(a); } }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { var pvv = ProductVariableValueController.GetByID(id); if (pvv != null) { ViewState["ID"] = id; int productvariableid = Convert.ToInt32(pvv.ProductVariableID); if (productvariableid > 0) { int variableID = 0; var variablevalue = VariableValueController.GetByID(Convert.ToInt32(pvv.VariableValueID)); if (variablevalue != null) { variableID = Convert.ToInt32(variablevalue.VariableID); } ddlVariable.SelectedValue = variableID.ToString(); var vv = VariableValueController.GetByVariableIDIsHidden(Convert.ToInt32(variableID), false); ddlVariableValue.Items.Clear(); ddlVariableValue.Items.Insert(0, new ListItem("-- Chọn --", "0")); ddlVariableValue.DataSource = vv; ddlVariableValue.DataBind(); ddlVariableValue.SelectedValue = pvv.VariableValueID.ToString(); chkIsHidden.Checked = Convert.ToBoolean(pvv.IsHidden); var pv = ProductVariableController.GetByID(productvariableid); if (pv != null) { ViewState["productvariableid"] = productvariableid; ViewState["ProductvariableSKU"] = pv.SKU; ltrBack.Text = "<a href=\"/gia-tri-thuoc-tinh-san-pham?productvariableid=" + productvariableid + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>"; } } } } }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { var pv = ProductVariableController.GetByID(id); if (pv != null) { ViewState["ID"] = id; ViewState["SKU"] = pv.SKU; chkIsHidden.Checked = Convert.ToBoolean(pv.IsHidden); lblSKU.Text = pv.SKU; pRegular_Price.Text = pv.Regular_Price.ToString(); pCostOfGood.Text = pv.CostOfGood.ToString(); pRetailPrice.Text = pv.RetailPrice.ToString(); pMinimumInventoryLevel.Text = pv.MinimumInventoryLevel.ToString(); pMaximumInventoryLevel.Text = pv.MaximumInventoryLevel.ToString(); if (pv.Image != null) { ListProductThumbnail.Value = pv.Image; ProductThumbnail.ImageUrl = pv.Image; } int productid = Convert.ToInt32(pv.ProductID); if (productid > 0) { var product = ProductController.GetByID(productid); if (product != null) { ViewState["productid"] = productid; ViewState["productsku"] = product.ProductSKU; ltrBack.Text = "<a href=\"/thuoc-tinh-san-pham?id=" + product.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>"; } } } } }
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); } } } }
protected void btnOrder_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 == 2) { int OrderID = ViewState["ID"].ToString().ToInt(0); if (OrderID > 0) { var order = OrderController.GetByID(OrderID); if (order != null) { int ExcuteStatusOld = Convert.ToInt32(order.ExcuteStatus); string OrderNote = txtOrderNote.Text; // Xử lý nhập kho khi chuyển hoàn if (ExcuteStatusOld != 4) { var orderDetails = OrderDetailController.GetByOrderID(order.ID); foreach (tbl_OrderDetail product in orderDetails) { int parentID = 0; if (product.ProductID != 0) { parentID = product.ProductID.Value; } else { parentID = ProductVariableController.GetByID(product.ProductVariableID.Value).ProductID.Value; } StockManagerController.Insert( new tbl_StockManager { AgentID = product.AgentID, ProductID = product.ProductID, ProductVariableID = product.ProductVariableID, Quantity = product.Quantity, QuantityCurrent = 0, Type = 1, NoteID = "Nhập kho do chuyển hoàn đơn " + product.OrderID, OrderID = product.OrderID, Status = 13, SKU = product.SKU, CreatedDate = currentDate, CreatedBy = product.CreatedBy, MoveProID = 0, ParentID = parentID }); } } bool updateOrder = OrderController.UpdateExcuteStatus4(order.ID, username, OrderNote); if (updateOrder == true) { Response.Redirect("/thong-tin-don-hang-chuyen-hoan?id=" + order.ID); } else { PJUtils.ShowMessageBoxSwAlertCallFunction("Đã xảy ra lỗi", "s", true, "payAllClicked()", Page); } } } } } }
public void InserOrder1(string AgentAPIID, string AgentAPICode, int OrderType, string CustomerName, string CustomerPhone, string CustomerEmail, string CustomerAddress, double TotalPrice, int PaymentStatus, int ExcuteStatus, List <ProductOrder> ListProduct, string CreatedBy, string username, string password) { var rs = new ResponseClass(); if (Login(username, password)) { DateTime currentDate = DateTime.Now; var agent = AgentController.GetByAPICodeID(AgentAPIID, AgentAPICode); if (agent != null) { int AgentID = agent.ID; int CustomerID = 0; string AdditionFee = "0"; string DisCount = "0"; var checkphone = CustomerController.GetByPhone(CustomerPhone); if (checkphone != null) { CustomerID = checkphone.ID; } else { string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, CreatedBy, false, "", "", "", "", ""); if (kq.ToInt(0) > 0) { CustomerID = kq.ToInt(0); } } bool IsHidden = false; int Wayin = 2; var ret = OrderController.Insert(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, TotalPrice.ToString(), TotalPrice.ToString(), PaymentStatus, ExcuteStatus, IsHidden, Wayin, currentDate, CreatedBy, 0, 0, "0", 0, 0, DateTime.Now.ToString(), 0, 0, 0, 0, "", 0, 1); int OrderID = ret.ID; if (OrderID > 0) { if (ListProduct.Count > 0) { foreach (var p in ListProduct) { int ProductID = 0; int ProductVariableID = 0; int ID = p.ID; string SKU = p.SKU; int producttype = p.ProductType; if (producttype == 1) { ProductID = ID; ProductVariableID = 0; } else { ProductID = 0; ProductVariableID = ID; } string ProductVariableName = p.ProductVariableName; string ProductVariableValue = p.ProductVariableValue; double Quantity = Convert.ToDouble(p.Quantity); string ProductName = p.ProductName; string ProductImageOrigin = p.ProductImageOrigin; double ProductPrice = p.Price; string ProductVariableSave = p.ProductVariableDescription; if (ExcuteStatus == 2 && PaymentStatus == 3) { OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, ProductPrice, 1, 0, producttype, currentDate, CreatedBy, true); if (producttype == 1) { StockManagerController.Insert( new tbl_StockManager() { AgentID = AgentID, ProductID = ProductID, ProductVariableID = 0, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = String.Empty, OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = CreatedBy, MoveProID = 0, ParentID = ProductID }); } else { int parentID = 0; string parentSKU = ""; var productV = ProductVariableController.GetByID(ProductVariableID); 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 = ProductVariableID, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = String.Empty, OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = CreatedBy, MoveProID = 0, ParentID = parentID, }); } } else { OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, ProductPrice, 1, 0, producttype, currentDate, CreatedBy, false); } } } rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS); rs.Status = APIUtils.ResponseMessage.Success.ToString(); rs.Message = "Tạo mới đơn hàng thành công"; } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound); rs.Status = APIUtils.ResponseMessage.Error.ToString(); rs.Message = "Có lỗi trong quá trình tạo mới đơn hàng, vui lòng thử lại sau."; } } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound); rs.Status = APIUtils.ResponseMessage.Error.ToString(); rs.Message = "Không tồn tại thông tin đại lý"; } } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED); rs.Status = APIUtils.ResponseMessage.Fail.ToString(); } Context.Response.ContentType = "application/json"; Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented)); Context.Response.Flush(); Context.Response.End(); }
public void InserOrderDetail(string AgentAPIID, string AgentAPICode, int OrderID, int ID, string SKU, int ProductType, string ProductVariableName, string ProductVariableValue, double Quantity, string ProductName, string ProductImageOrigin, double ProductPrice, string ProductVariableSave, int ExcuteStatus, int PaymentStatus, string CreatedBy, string username, string password) { var rs = new ResponseClass(); if (Login(username, password)) { DateTime currentDate = DateTime.Now; var agent = AgentController.GetByAPICodeID(AgentAPIID, AgentAPICode); if (agent != null) { int AgentID = agent.ID; int ProductID = 0; int ProductVariableID = 0; if (ProductType == 1) { ProductID = ID; ProductVariableID = 0; } else { ProductID = 0; ProductVariableID = ID; } if (ExcuteStatus == 2 && PaymentStatus == 3) { OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, true); if (ProductType == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ProductID, ProductVariableID = 0, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = String.Empty, OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = CreatedBy, MoveProID = 0, ParentID = ProductID }); } else { int parentID = 0; string parentSKU = ""; var productV = ProductVariableController.GetByID(ProductVariableID); 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 = ProductVariableID, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = String.Empty, OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = CreatedBy, MoveProID = 0, ParentID = parentID }); } } else { OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, false); } rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS); rs.Status = APIUtils.ResponseMessage.Success.ToString(); rs.Message = "Tạo mới đơn hàng thành công"; } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound); rs.Status = APIUtils.ResponseMessage.Error.ToString(); rs.Message = "Không tồn tại thông tin đại lý"; } } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED); rs.Status = APIUtils.ResponseMessage.Fail.ToString(); } Context.Response.ContentType = "application/json"; Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented)); Context.Response.Flush(); Context.Response.End(); }
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) { 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[] items = list.Split(';'); if (items.Length - 1 > 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; var variable = ProductVariableController.GetByID(ID); if (variable != null) { parentID = Convert.ToInt32(variable.ProductID); } 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]); } // IN MÃ VẠCH string barcodeValue = ""; string productPrint = ""; string barcodeImage = ""; string[] value = hdfBarcode.Value.Split(';'); if (value.Count() > 1) { 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]; barcodeImage = "/uploads/barcodes/" + barcodeValue + ".png"; 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>"; } } 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) { File.Delete(filePath); } // in mã vạch ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printBarcode() });", true); } else { PJUtils.ShowMessageBoxSwAlert("Nhập kho thành công!", "s", true, Page); } } } }
private void _updateProductVariation(tbl_Account acc) { if (String.IsNullOrEmpty(hdfVariableListInsert.Value)) { var strFunction = ""; strFunction = "HoldOn.close();"; strFunction = "swal({title: 'Lỗi', text: 'Quá trình cập nhật biến thể đã xảy ra lỗi', type: 'error'});"; JavaScript.BeforePageLoad(Page).ExecuteCustomScript(strFunction); return; } var productID = ViewState["ID"].ToString().ToInt(0); var productSKU = ViewState["SKU"].ToString(); var uploadPath = "/uploads/images/"; var imageDefault = "/App_Themes/Ann/image/placeholder.png"; #region Xóa biến thể var variationRemovalList = JsonConvert.DeserializeObject <List <string> >(hdfVariationRemovalList.Value); foreach (var sku in variationRemovalList) { ProductVariableController.removeByVariationSKU(sku); } #endregion #region Cập nhật biến thể var productVariationUpdateList = JsonConvert.DeserializeObject <List <ProductVariationUpdateModel> >(hdfVariableListInsert.Value); if (uploadVariationImage.HasFiles) { foreach (var file in uploadVariationImage.PostedFiles) { var fileName = file.FileName; var imageName = _uploadImage(productID, file); productVariationUpdateList .Where(x => x.image == uploadPath + fileName) .Select(x => { x.image = uploadPath + imageName; return(x); }); } } foreach (var item in productVariationUpdateList) { var now = DateTime.Now; // Kiểm tra sản phẩm biến thể có tồn tại hay không để thực hiện insert hoặc update var productVariation = ProductVariableController.GetByID(item.productVariationID); var image = String.Empty; if (item.image != imageDefault) { image = item.image.Replace(uploadPath, String.Empty); } if (productVariation != null) { // Thực hiện update biến thể var productVariationID = ProductVariableController.Update( ID: productVariation.ID, ProductID: productID, ParentSKU: productSKU, SKU: item.sku, Stock: Convert.ToDouble(productVariation.Stock), StockStatus: Convert.ToInt32(productVariation.StockStatus), Regular_Price: item.regularPrice, CostOfGood: item.costOfGood, RetailPrice: item.retailPrice, Image: image, ManageStock: true, IsHidden: false, ModifiedDate: now, ModifiedBy: acc.Username, SupplierID: Convert.ToInt32(productVariation.SupplierID), SupplierName: productVariation.SupplierName, MinimumInventoryLevel: item.minimumInventoryLevel, MaximumInventoryLevel: item.maximumInventoryLevel ); // Xóa tất cả giá trị của biến thể để cập nhật lại ProductVariableValueController.DeleteByProductVariableID(productVariation.ID); // Khởi tạo biến thể cho sản phẩm con _createVariationValue(new VariationValueUpdateModel() { productVariationID = Convert.ToInt32(productVariationID), productVariationSKU = item.sku, variationValueID = item.variationValueID, variationName = item.variationName, variationValueName = item.variationValueName, isHidden = false, createdDate = now, createdBy = acc.Username }); } else { // Tạo sản phẩm biến thể mới var productVariationID = ProductVariableController.Insert( ProductID: productID, ParentSKU: productSKU, SKU: item.sku, Stock: 0, StockStatus: item.stockStatus, Regular_Price: item.regularPrice, CostOfGood: item.costOfGood, RetailPrice: item.retailPrice, Image: image, ManageStock: true, IsHidden: false, CreatedDate: now, CreatedBy: acc.Username, SupplierID: ddlSupplier.SelectedValue.ToInt(0), SupplierName: ddlSupplier.SelectedItem.ToString(), MinimumInventoryLevel: item.minimumInventoryLevel, MaximumInventoryLevel: item.maximumInventoryLevel); // Khởi tạo biến thể cho sản phẩm con _createVariationValue(new VariationValueUpdateModel() { productVariationID = Convert.ToInt32(productVariationID), productVariationSKU = item.sku, variationValueID = item.variationValueID, variationName = item.variationName, variationValueName = item.variationValueName, isHidden = false, createdDate = now, createdBy = acc.Username }); } } #endregion }
protected void btnOrder_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 == 2) { // Change user string OrderNote = ""; if (username != hdfUsernameCurrent.Value) { OrderNote = "Được tính tiền giúp bởi " + username; username = hdfUsernameCurrent.Value; } int AgentID = Convert.ToInt32(acc.AgentID); int OrderType = hdfOrderType.Value.ToInt(); string AdditionFee = "0"; string DisCount = "0"; int CustomerID = 0; string CustomerPhone = txtPhone.Text.Trim().Replace(" ", ""); string CustomerName = txtFullname.Text.Trim(); string Nick = txtNick.Text.Trim(); string CustomerEmail = ""; string CustomerAddress = txtAddress.Text.Trim(); var checkCustomer = CustomerController.GetByPhone(CustomerPhone); if (checkCustomer != null) { CustomerID = checkCustomer.ID; string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2); } else { string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", Nick); if (kq.ToInt(0) > 0) { CustomerID = kq.ToInt(0); } } string totalPrice = hdfTotalPrice.Value.ToString(); string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value; int PaymentStatus = 3; int ExcuteStatus = 2; int PaymentType = 1; int ShippingType = 1; bool IsHidden = false; int WayIn = 1; double DiscountPerProduct = Convert.ToDouble(pDiscount.Value); double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value); string FeeShipping = pFeeShip.Value.ToString(); double GuestPaid = Convert.ToDouble(pGuestPaid.Value); double GuestChange = Convert.ToDouble(totalPrice) - GuestPaid; string OtherFeeName = txtOtherFeeName.Text; double OtherFeeValue = Convert.ToDouble(pOtherFee.Value); var ret = OrderController.InsertOnSystem(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, DiscountPerProduct, TotalDiscount, FeeShipping, GuestPaid, GuestChange, PaymentType, ShippingType, OrderNote, DateTime.Now, OtherFeeName, OtherFeeValue, 1); int OrderID = ret.ID; if (OrderID > 0) { ProductPOS POS = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value); List <tbl_OrderDetail> orderDetails = new List <tbl_OrderDetail>(); List <tbl_StockManager> stockManager = new List <tbl_StockManager>(); foreach (ProductGetOut item in POS.productPOS) { orderDetails.Add( new tbl_OrderDetail() { AgentID = AgentID, OrderID = OrderID, SKU = item.SKU, ProductID = item.ProductType == 1 ? item.ProductID : 0, ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID, ProductVariableDescrition = item.ProductVariableSave, Quantity = item.QuantityInstock, Price = item.Giabanle, Status = 1, DiscountPrice = 0, ProductType = item.ProductType, CreatedDate = currentDate, CreatedBy = username, IsCount = true } ); int parentID = item.ProductID; var variable = ProductVariableController.GetByID(item.ProductVariableID); if (variable != null) { parentID = Convert.ToInt32(variable.ProductID); } stockManager.Add( new tbl_StockManager() { AgentID = AgentID, ProductID = item.ProductType == 1 ? item.ProductID : 0, ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID, Quantity = item.QuantityInstock, QuantityCurrent = 0, Type = 2, NoteID = "Xuất kho bán POS", OrderID = OrderID, Status = 3, SKU = item.SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID } ); } OrderDetailController.Insert(orderDetails); StockManagerController.Insert(stockManager); string refund = Request.Cookies["refund"].Value; if (refund != "1") { string[] RefundID = refund.Split('|'); var update = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID); var updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username); } Response.Cookies["refund"].Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(Response.Cookies["refund"]); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printInvoice(" + OrderID + ") });", true); } } } }
protected void btnOrder_Click(object sender, EventArgs e) { try { DateTime currentDate = DateTime.Now; string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 2) { #region Lấy thông tin khởi tạo Order // Change user string UserHelp = ""; if (username != hdfUsernameCurrent.Value) { UserHelp = username; username = hdfUsernameCurrent.Value; } int AgentID = Convert.ToInt32(acc.AgentID); int OrderType = hdfOrderType.Value.ToInt(); string AdditionFee = "0"; string DisCount = "0"; int CustomerID = 0; string CustomerPhone = Regex.Replace(txtPhone.Text.Trim(), @"[^\d]", ""); string CustomerName = txtFullname.Text.Trim().ToLower().ToTitleCase(); string CustomerEmail = ""; string CustomerAddress = txtAddress.Text.Trim().ToTitleCase(); int ProvinceID = hdfProvinceID.Value.ToInt(0); int DistrictID = hdfDistrictID.Value.ToInt(0); int WardID = hdfWardID.Value.ToInt(0); var checkCustomer = CustomerController.GetByPhone(CustomerPhone); string kq = ""; #region Cập nhật thông tin khách hàng if (checkCustomer != null) { CustomerID = checkCustomer.ID; kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", checkCustomer.CustomerLevelID.Value, checkCustomer.Status.Value, checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.Nick, checkCustomer.Avatar, checkCustomer.ShippingType.Value, checkCustomer.PaymentType.Value, checkCustomer.TransportCompanyID.Value, checkCustomer.TransportCompanySubID.Value, checkCustomer.CustomerPhone2, ProvinceID, DistrictID, WardID); } else { kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", "", 0, 0, 0, 0, "", ProvinceID, DistrictID, WardID); if (kq.ToInt(0) > 0) { CustomerID = kq.ToInt(0); } } #endregion string totalPrice = hdfTotalPrice.Value.ToString(); string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value; int PaymentStatus = 3; int ExcuteStatus = 2; int PaymentType = 1; int ShippingType = 1; bool IsHidden = false; int WayIn = 1; double DiscountPerProduct = Convert.ToDouble(pDiscount.Value); double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value); string FeeShipping = pFeeShip.Value.ToString(); double GuestPaid = Convert.ToDouble(pGuestPaid.Value); double GuestChange = Convert.ToDouble(totalPrice) - GuestPaid; var couponID = hdfCouponID.Value.ToInt(0); var couponValue = hdfCouponValue.Value.ToDecimal(0); tbl_Order order = new tbl_Order() { AgentID = AgentID, OrderType = OrderType, AdditionFee = AdditionFee, DisCount = DisCount, CustomerID = CustomerID, CustomerName = CustomerName, CustomerPhone = CustomerPhone, CustomerAddress = CustomerAddress, CustomerEmail = CustomerEmail, TotalPrice = totalPrice, TotalPriceNotDiscount = totalPriceNotDiscount, PaymentStatus = PaymentStatus, ExcuteStatus = ExcuteStatus, IsHidden = IsHidden, WayIn = WayIn, CreatedDate = currentDate, CreatedBy = username, DiscountPerProduct = DiscountPerProduct, TotalDiscount = TotalDiscount, FeeShipping = FeeShipping, GuestPaid = GuestPaid, GuestChange = GuestChange, PaymentType = PaymentType, ShippingType = ShippingType, OrderNote = String.Empty, DateDone = DateTime.Now, OtherFeeName = String.Empty, OtherFeeValue = 0, PostalDeliveryType = 1, UserHelp = UserHelp, CouponID = couponID, CouponValue = couponValue }; var ret = OrderController.InsertOnSystem(order); int OrderID = ret.ID; #endregion #region Khởi tạo Other Fee if (!String.IsNullOrEmpty(hdfOtherFees.Value)) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var fees = serializer.Deserialize <List <Fee> >(hdfOtherFees.Value); if (fees != null) { foreach (var fee in fees) { fee.OrderID = ret.ID; fee.CreatedBy = acc.ID; fee.CreatedDate = DateTime.Now; fee.ModifiedBy = acc.ID; fee.ModifiedDate = DateTime.Now; } FeeController.Update(ret.ID, fees); } } #endregion #region Cập nhật Coupon if (order.CouponID.HasValue && order.CouponID.Value > 0) { CouponController.updateStatusCouponCustomer(CustomerID, order.CouponID.Value, false); } #endregion if (OrderID > 0) { #region Khởi tạo chi tiết đơn hàng ProductPOS POS = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value); List <tbl_OrderDetail> orderDetails = new List <tbl_OrderDetail>(); List <tbl_StockManager> stockManager = new List <tbl_StockManager>(); // Reverser POS.productPOS.Reverse(); foreach (ProductGetOut item in POS.productPOS) { orderDetails.Add( new tbl_OrderDetail() { AgentID = AgentID, OrderID = OrderID, SKU = item.SKU, ProductID = item.ProductType == 1 ? item.ProductID : 0, ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID, ProductVariableDescrition = item.ProductVariableSave, Quantity = item.QuantityInstock, Price = item.Giabanle, Status = 1, DiscountPrice = 0, ProductType = item.ProductType, CreatedDate = currentDate, CreatedBy = username, IsCount = true } ); int parentID = item.ProductID; var variable = ProductVariableController.GetByID(item.ProductVariableID); if (variable != null) { parentID = Convert.ToInt32(variable.ProductID); } stockManager.Add( new tbl_StockManager() { AgentID = AgentID, ProductID = item.ProductType == 1 ? item.ProductID : 0, ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID, Quantity = item.QuantityInstock, QuantityCurrent = 0, Type = 2, NoteID = "Xuất kho bán POS", OrderID = OrderID, Status = 3, SKU = item.SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID } ); } OrderDetailController.Insert(orderDetails); #endregion // Cập nhật lại sô lượng và giá vố vào đơn hàng OrderController.updateQuantityCOGS(OrderID); // Cập nhật lại thông tin kho hàng StockManagerController.Insert(stockManager); #region Khởi tạo đơn hàng đổi trả string refund = hdSession.Value; if (refund != "1") { string[] RefundID = refund.Split('|'); var update = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID); var updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username); } #endregion // Hoàn thành khởi tạo đơn hàng nên gán lại giá trị trang lúc ban đầu hdStatusPage.Value = "Create"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { HoldOn.close(); printInvoice(" + OrderID + ") });", true); } } } } catch (Exception) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { handleErrorSubmit(); });", true); } }
protected void btnOrder_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 == 2) { int AgentID = Convert.ToInt32(acc.AgentID); int OrderType = hdfOrderType.Value.ToInt(); string AdditionFee = "0"; string DisCount = "0"; int CustomerID = 0; string CustomerPhone = txtPhone.Text.Trim().Replace(" ", ""); string CustomerName = txtFullname.Text.Trim(); string Nick = txtNick.Text.Trim(); string CustomerAddress = txtAddress.Text.Trim(); string Zalo = txtZalo.Text.Trim(); string Facebook = txtFacebook.Text.Trim(); int PaymentStatus = hdfPaymentStatus.Value.ToInt(1); int ExcuteStatus = hdfExcuteStatus.Value.ToInt(1); int PaymentType = hdfPaymentType.Value.ToInt(1); int ShippingType = hdfShippingType.Value.ToInt(1); var checkCustomer = CustomerController.GetByPhone(CustomerPhone); if (checkCustomer != null) { CustomerID = checkCustomer.ID; string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2); } else { string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, "", 0, 0, currentDate, username, false, Zalo, Facebook, "", "", Nick, "", ShippingType, PaymentType); if (kq.ToInt(0) > 0) { CustomerID = kq.ToInt(); } } var Customer = CustomerController.GetByID(CustomerID); int TransportCompanyID = 0; int TransportCompanySubID = 0; if (Customer.ShippingType == ShippingType) { TransportCompanyID = Convert.ToInt32(Customer.TransportCompanyID); TransportCompanySubID = Convert.ToInt32(Customer.TransportCompanySubID); } string totalPrice = hdfTotalPrice.Value.ToString(); string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value; double DiscountPerProduct = Convert.ToDouble(pDiscount.Value); double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value); string FeeShipping = pFeeShip.Value.ToString(); string OtherFeeName = txtOtherFeeName.Text; double OtherFeeValue = Convert.ToDouble(pOtherFee.Value); bool IsHidden = false; int WayIn = 1; string datedone = ""; if (ExcuteStatus == 2) { datedone = DateTime.Now.ToString(); } var ret = OrderController.Insert(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress, "", totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, Convert.ToDouble(pDiscount.Value), TotalDiscount, FeeShipping, PaymentType, ShippingType, datedone, 0, 0, TransportCompanyID, TransportCompanySubID, OtherFeeName, OtherFeeValue, 1); int OrderID = ret.ID; double totalQuantity = 0; if (OrderID > 0) { string list = hdfListProduct.Value; string[] items = list.Split(';'); if (items.Length - 1 > 0) { for (int i = 0; i < items.Length - 1; i++) { var item = items[i]; string[] itemValue = item.Split(','); int ProductID = itemValue[0].ToInt(); int ProductVariableID = itemValue[11].ToInt(); string SKU = itemValue[1].ToString(); int ProductType = itemValue[2].ToInt(); // Tìm parentID int parentID = ProductID; var variable = ProductVariableController.GetByID(ProductVariableID); if (variable != null) { parentID = Convert.ToInt32(variable.ProductID); } 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]; double Price = Convert.ToDouble(itemValue[9]); string ProductVariableSave = itemValue[10]; OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, Price, 1, 0, ProductType, currentDate, username, true); StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ProductID, ProductVariableID = ProductVariableID, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = "Xuất kho khi tạo đơn", OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID, }); totalQuantity += Quantity; } } string refund = Request.Cookies["refundt"].Value; if (refund != "1") { string[] RefundID = refund.Split('|'); var update = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID); var updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username); } Response.Cookies["refundt"].Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(Response.Cookies["refundt"]); PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng thành công", "s", true, "redirectTo(" + OrderID + ")", Page); } } } }
protected void btnDelete_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 1) { int AgentID = Convert.ToInt32(acc.AgentID); int ID = hdfMPDID.Value.ToInt(0); if (ID > 0) { var mpd = MoveProDetailController.GetByID(ID); if (mpd != null) { if (mpd.IsCount == true) { if (mpd.ProductType == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = Convert.ToDouble(mpd.QuantiySend), QuantityCurrent = 0, Type = 1, NoteID = "Nhập lại sản phẩm khi xóa khỏi đợt chuyển hàng", OrderID = 0, Status = 6, SKU = mpd.SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = Convert.ToInt32(mpd.MoveProID), 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 = Convert.ToDouble(mpd.QuantiySend), QuantityCurrent = 0, Type = 1, NoteID = "Nhập lại sản phẩm khi xóa khỏi đợt chuyển hàng", OrderID = 0, Status = 6, SKU = mpd.SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = Convert.ToInt32(mpd.MoveProID), ParentID = parentID }); } } MoveProDetailController.Delete(ID); PJUtils.ShowMessageBoxSwAlert("Xóa 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) { if (acc.RoleID == 0 || acc.RoleID == 1) { int mpID = ViewState["ID"].ToString().ToInt(0); var mp = MoveProController.GetByID(mpID); if (mp != null) { int AgentID = Convert.ToInt32(acc.AgentID); int AgentIDReceive = hdfAgentID.Value.ToInt(0); string agentSendname = ""; string agentReceivename = ""; var agentSend = AgentController.GetByID(AgentID); if (agentSend != null) { agentSendname = agentSend.AgentName; } var agentReceive = AgentController.GetByID(AgentIDReceive); if (agentReceive != null) { agentReceivename = agentReceive.AgentName; } string list = hdfvalue.Value; string note = hdfNote.Value; int moveProStatus = hdfStatus.Value.ToInt(0); MoveProController.UpdateStatus(mpID, moveProStatus, currentDate, username); string[] items = list.Split(';'); if (items.Length - 1 > 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]; int mpdid = itemValue[9].ToInt(0); if (mpdid > 0) { var mpdetail = MoveProDetailController.GetByID(mpdid); if (mpdetail != null) { if (moveProStatus == 3) { if (producttype == 1) { StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = ID, ProductVariableID = 0, Quantity = Quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = 0, Status = 7, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = mpID, 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 = 1, NoteID = note, OrderID = 0, Status = 7, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = mpID, ParentID = parentID }); } MoveProDetailController.UpdateQuantityReceive(mpdid, Quantity, currentDate, username); } else { MoveProDetailController.UpdateQuantityReceive(mpdid, Quantity, currentDate, username); } } } } } PJUtils.ShowMessageBoxSwAlert("Cập nhật nhận hàng 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 btnOrder_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 2) { int AgentID = Convert.ToInt32(acc.AgentID); int OrderType = hdfOrderType.Value.ToInt(); string AdditionFee = "0"; string DisCount = "0"; int CustomerID = 0; string CustomerPhone = Regex.Replace(txtPhone.Text.Trim(), @"[^\d]", ""); string CustomerName = txtFullname.Text.Trim().ToLower().ToTitleCase(); string Nick = txtNick.Text.Trim(); string CustomerAddress = txtAddress.Text.Trim().ToTitleCase(); string Zalo = ""; string Facebook = txtFacebook.Text.Trim(); int PaymentStatus = ddlPaymentStatus.SelectedValue.ToInt(); int ExcuteStatus = ddlExcuteStatus.SelectedValue.ToInt(); int PaymentType = ddlPaymentType.SelectedValue.ToInt(); int ShippingType = ddlShippingType.SelectedValue.ToInt(); int ProvinceID = hdfProvinceID.Value.ToInt(0); int DistrictID = hdfDistrictID.Value.ToInt(0); int WardID = hdfWardID.Value.ToInt(0); int TransportCompanyID = ddlTransportCompanyID.SelectedValue.ToInt(0); int TransportCompanySubID = hdfTransportCompanySubID.Value.ToInt(0); var checkCustomer = CustomerController.GetByPhone(CustomerPhone); if (checkCustomer != null) { CustomerID = checkCustomer.ID; string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", checkCustomer.CustomerLevelID.Value, checkCustomer.Status.Value, checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, Nick, checkCustomer.Avatar, checkCustomer.ShippingType.Value, checkCustomer.PaymentType.Value, checkCustomer.TransportCompanyID.Value, checkCustomer.TransportCompanySubID.Value, checkCustomer.CustomerPhone2, ProvinceID, DistrictID, WardID); } else { string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, "", 0, 0, currentDate, username, false, Zalo, Facebook, "", Nick, "", ShippingType, PaymentType, TransportCompanyID, TransportCompanySubID, "", ProvinceID, DistrictID, WardID); if (kq.ToInt(0) > 0) { CustomerID = kq.ToInt(); } } string totalPrice = hdfTotalPrice.Value.ToString(); string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value; double DiscountPerProduct = Convert.ToDouble(pDiscount.Value); double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value); string FeeShipping = pFeeShip.Value.ToString(); bool IsHidden = false; int WayIn = 1; string datedone = ""; if (ExcuteStatus == 2) { datedone = DateTime.Now.ToString(); } var couponID = hdfCouponID.Value.ToInt(0); var couponValue = hdfCouponValue.Value.ToDecimal(0); var orderNew = new tbl_Order() { AgentID = AgentID, OrderType = OrderType, AdditionFee = AdditionFee, DisCount = DisCount, CustomerID = CustomerID, CustomerName = CustomerName, CustomerPhone = CustomerPhone, CustomerAddress = CustomerAddress, CustomerEmail = String.Empty, TotalPrice = totalPrice, TotalPriceNotDiscount = totalPriceNotDiscount, PaymentStatus = PaymentStatus, ExcuteStatus = ExcuteStatus, IsHidden = IsHidden, WayIn = WayIn, CreatedDate = currentDate, CreatedBy = username, DiscountPerProduct = Convert.ToDouble(pDiscount.Value), TotalDiscount = TotalDiscount, FeeShipping = FeeShipping, PaymentType = PaymentType, ShippingType = ShippingType, GuestPaid = 0, GuestChange = 0, TransportCompanyID = TransportCompanyID, TransportCompanySubID = TransportCompanySubID, OtherFeeName = String.Empty, OtherFeeValue = 0, PostalDeliveryType = 1, CouponID = couponID, CouponValue = couponValue }; if (!String.IsNullOrEmpty(datedone)) { orderNew.DateDone = Convert.ToDateTime(datedone); } var ret = OrderController.Insert(orderNew); // Insert Other Fee if (!String.IsNullOrEmpty(hdfOtherFees.Value)) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var fees = serializer.Deserialize <List <Fee> >(hdfOtherFees.Value); if (fees != null) { foreach (var fee in fees) { fee.OrderID = ret.ID; fee.CreatedBy = acc.ID; fee.CreatedDate = DateTime.Now; fee.ModifiedBy = acc.ID; fee.ModifiedDate = DateTime.Now; } FeeController.Update(ret.ID, fees); } } // Insert Transfer Bank var bankID = ddlBank.SelectedValue.ToInt(0); if (bankID != 0) { BankTransferController.Create(ret, bankID, acc); } // Inactive code coupon if (orderNew.CouponID.HasValue && orderNew.CouponID.Value > 0) { CouponController.updateStatusCouponCustomer(CustomerID, orderNew.CouponID.Value, false); } int OrderID = ret.ID; if (OrderID > 0) { var orderDetails = new List <tbl_OrderDetail>(); var stockManager = new List <tbl_StockManager>(); string list = hdfListProduct.Value; var items = list.Split(';').Where(x => !String.IsNullOrEmpty(x)).ToList(); if (items.Count > 0) { items.Reverse(); } foreach (var item in items) { string[] itemValue = item.Split(','); int ProductID = itemValue[0].ToInt(); int ProductVariableID = itemValue[11].ToInt(); string SKU = itemValue[1].ToString(); int ProductType = itemValue[2].ToInt(); // Tìm parentID int parentID = ProductID; var variable = ProductVariableController.GetByID(ProductVariableID); if (variable != null) { parentID = Convert.ToInt32(variable.ProductID); } 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]; double Price = Convert.ToDouble(itemValue[9]); string ProductVariableSave = itemValue[10]; orderDetails.Add(new tbl_OrderDetail() { AgentID = AgentID, OrderID = OrderID, SKU = SKU, ProductID = ProductID, ProductVariableID = ProductVariableID, ProductVariableDescrition = ProductVariableSave, Quantity = Quantity, Price = Price, Status = 1, DiscountPrice = 0, ProductType = ProductType, CreatedDate = currentDate, CreatedBy = username, IsCount = true }); stockManager.Add( new tbl_StockManager { AgentID = AgentID, ProductID = ProductID, ProductVariableID = ProductVariableID, Quantity = Quantity, QuantityCurrent = 0, Type = 2, NoteID = "Xuất kho khi tạo đơn", OrderID = OrderID, Status = 3, SKU = SKU, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID, }); } OrderDetailController.Insert(orderDetails); OrderController.updateQuantityCOGS(OrderID); StockManagerController.Insert(stockManager); string refund = hdSession.Value; if (refund != "1") { string[] RefundID = refund.Split('|'); var update = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID); var updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username); } PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng thành công", "s", true, "redirectTo(" + OrderID + ")", Page); } } } }