Exemplo n.º 1
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                string username = Request.Cookies["usernameLoginSystem"].Value;
                var    acc      = AccountController.GetByUsername(username);
                if (acc != null)
                {
                    int agentIDReceive = Convert.ToInt32(acc.AgentID);
                    var mp             = MoveProController.GetByIDAndAgentIDReceive(ID, agentIDReceive);
                    if (mp != null)
                    {
                        ViewState["ID"] = ID;
                        int    agentIDSend      = Convert.ToInt32(mp.AgentIDSend);
                        string agentSendname    = "";
                        string agentReceivename = "";

                        var agentSend = AgentController.GetByID(agentIDSend);
                        if (agentSend != null)
                        {
                            agentSendname = agentSend.AgentName;
                        }
                        var agentReceive = AgentController.GetByID(agentIDReceive);
                        if (agentReceive != null)
                        {
                            agentReceivename = agentReceive.AgentName;
                        }
                        ltrAgentReceive.Text = agentReceivename;
                        ltrAgentSend.Text    = agentSendname;



                        int mpStatus = Convert.ToInt32(mp.Status);
                        ltrNote.Text = mp.Note;

                        if (mpStatus < 3)
                        {
                            ltrbutton1.Text = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a>";
                            ltrbutton2.Text = "<div class=\"float-right\"><a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a></div>";
                        }
                        #region LoadDDL
                        //Lấy trạng thái
                        StringBuilder htmlStatus = new StringBuilder();
                        htmlStatus.Append("<select id=\"moveProStatus\" class=\"form-control\" style=\"width: 20%; display: inline-block\">");
                        if (mpStatus == 2)
                        {
                            htmlStatus.Append("<option value=\"2\" selected>Đã chuyển</option>");
                            htmlStatus.Append("<option value=\"3\">Đã hoàn tất</option>");
                        }
                        else if (mpStatus == 3)
                        {
                            htmlStatus.Append("<option value=\"2\">Đã chuyển</option>");
                            htmlStatus.Append("<option value=\"3\" selected>Đã hoàn tất</option>");
                        }
                        htmlStatus.Append("</select>");
                        ltrMoProStatus.Text = htmlStatus.ToString();

                        //Lấy nhà cung cấp
                        //var supplier = SupplierController.GetAllWithIsHidden(false);
                        //StringBuilder htmlSupplier = new StringBuilder();
                        //htmlSupplier.Append("<select id=\"supplierList\" class=\"form-control\" style=\"width: 20%; float: left; margin-right: 10px\">");
                        //htmlSupplier.Append("<option value=\"0\">Tất cả nhà cung cấp</option>");
                        //if (supplier.Count > 0)
                        //{
                        //    foreach (var s in supplier)
                        //    {
                        //        htmlSupplier.Append("<option value=\"" + s.ID + "\">" + s.SupplierName + "</option>");
                        //    }
                        //}
                        //htmlSupplier.Append("</select>");
                        //ltrSupplier.Text = htmlSupplier.ToString();
                        #endregion
                        #region Lấy danh sách sản phẩm
                        var    mpDetail = MoveProDetailController.GetByMoveProID(ID);
                        string html     = "";
                        if (mpDetail.Count > 0)
                        {
                            string listSKU = "";
                            foreach (var item in mpDetail)
                            {
                                listSKU += item.SKU + "|";
                                int ProductType       = Convert.ToInt32(item.ProductType);
                                int ProductID         = Convert.ToInt32(item.ProductID);
                                int ProductVariableID = Convert.ToInt32(item.ProductVariableID);

                                string SKU                        = item.SKU;
                                double QuantityInstock            = 0;
                                string ProductImageOrigin         = "";
                                string ProductVariable            = "";
                                string ProductName                = "";
                                int    PID                        = 0;
                                string ProductVariableName        = "";
                                string ProductVariableValue       = "";
                                string ProductVariableSave        = "";
                                double QuantityMainInstock        = 0;
                                string ProductImage               = "";
                                string QuantityMainInstockString  = "";
                                string QuantityInstockString      = "";
                                string productVariableDescription = item.ProductVariableDescription;
                                string SupplierName               = item.SupplierName;
                                if (ProductType == 1)
                                {
                                    PID = ProductID;
                                    var product = ProductController.GetBySKU(SKU);
                                    if (product != null)
                                    {
                                        double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU);

                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                        QuantityInstock       = total;
                                        QuantityInstockString = string.Format("{0:N0}", total);

                                        var img = ProductImageController.GetFirstByProductID(product.ID);
                                        if (img != null)
                                        {
                                            ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                        }
                                        else
                                        {
                                            ProductImage       = "";
                                            ProductImageOrigin = "";
                                        }


                                        ProductVariable = variable;
                                        ProductName     = product.ProductTitle;

                                        QuantityMainInstock       = mainstock;
                                        QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                        ProductVariableSave       = item.ProductVariableDescription;

                                        ProductVariableName  = variablename;
                                        ProductVariableValue = variablevalue;
                                    }
                                }
                                else
                                {
                                    PID = ProductVariableID;
                                    var productvariable = ProductVariableController.GetBySKU(SKU);
                                    if (productvariable != null)
                                    {
                                        SKU = productvariable.SKU.Trim().ToUpper();
                                        double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU);


                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        string[] vs = productVariableDescription.Split('|');
                                        if (vs.Length - 1 > 0)
                                        {
                                            for (int i = 0; i < vs.Length - 1; i++)
                                            {
                                                string[] items = vs[i].Split(':');
                                                variable      += items[0] + ":" + items[1] + "<br/>";
                                                variablename  += items[0] + "|";
                                                variablevalue += items[1] + "|";
                                            }
                                        }

                                        double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                        QuantityInstock       = total;
                                        QuantityInstockString = string.Format("{0:N0}", total);
                                        ProductImage          = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />";
                                        ProductImageOrigin    = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small);

                                        ProductVariable = variable;
                                        var product1 = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                        if (product1 != null)
                                        {
                                            ProductName = product1.ProductTitle;
                                        }

                                        QuantityMainInstock       = mainstock;
                                        QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                        ProductVariableSave       = item.ProductVariableDescription;

                                        ProductVariableName  = variablename;
                                        ProductVariableValue = variablevalue;
                                    }
                                }
                                html += "<tr class=\"product-result\" data-mpdid=\"" + item.ID + "\" data-quantityinstock=\"" + QuantityInstock
                                        + "\" data-productimageorigin=\"" + ProductImageOrigin
                                        + "\" data-productvariable=\"" + ProductVariableSave
                                        + "\" data-productname=\"" + ProductName
                                        + "\" data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType
                                        + "\" data-id=\"" + item.ID + "\" data-productnariablename=\"" + ProductVariableName
                                        + "\" data-productvariablevalue =\"" + ProductVariableValue + "\">";
                                html += "   <td>" + ProductImage + "";
                                html += "   <td>" + ProductName + "</td>";
                                html += "   <td>" + SKU + "</td>";
                                html += "   <td>" + SupplierName + "</td>";
                                html += "   <td>" + ProductVariable + "</td>";
                                html += "   <td>" + item.QuantiySend + "</td>";
                                html += "   <td style=\"width:20%;\"><input type=\"text\" min=\"0\" class=\"form-control in-quanlity\" style=\"width: 40%;margin: 0 auto;\" value=\"" + item.QuantityReceive + "\"  onkeyup=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>";
                                //html += "   <td><a href=\"javascript:;\" onclick=\"deleteRow($(this))\">Xóa</a></td>";
                                //html += "   <td></td>";
                                html += "</tr>";
                            }
                            ltrProducts.Text         = html;
                            hdfListProductSend.Value = listSKU;
                        }
                        #endregion
                    }
                }
            }
        }
Exemplo n.º 3
0
        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);
                    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);

                    string[] items = list.Split(';');
                    if (items.Length - 1 > 0)
                    {
                        string kq = MoveProController.Insert(AgentID, agentSendname, AgentIDReceive, agentReceivename, moveProStatus,
                                                             note, false, currentDate, username);

                        if (kq.ToInt(0) > 0)
                        {
                            int moveProID = kq.ToInt(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)
                                {
                                    int    supplierID   = 0;
                                    string supplierName = "";
                                    var    product      = ProductController.GetBySKU(SKU);
                                    if (product != null)
                                    {
                                        supplierID   = Convert.ToInt32(product.SupplierID);
                                        supplierName = product.SupplierName;
                                    }

                                    if (moveProStatus == 2)
                                    {
                                        StockManagerController.Insert(
                                            new tbl_StockManager {
                                            AgentID           = AgentID,
                                            ProductID         = ID,
                                            ProductVariableID = 0,
                                            Quantity          = Quantity,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = note,
                                            OrderID     = 0,
                                            Status      = 5,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = moveProID,
                                            ParentID    = ID
                                        });
                                        MoveProDetailController.Insert(moveProID, SKU, ID, 0, producttype, ProductVariable, Quantity, 0, "", supplierID,
                                                                       supplierName, "", "", ProductName, ProductImageOrigin, true, currentDate, username);
                                    }
                                    else
                                    {
                                        MoveProDetailController.Insert(moveProID, SKU, ID, 0, producttype, ProductVariable, Quantity, 0, "", supplierID,
                                                                       supplierName, "", "", ProductName, ProductImageOrigin, false, currentDate, username);
                                    }
                                }
                                else
                                {
                                    int    supplierID      = 0;
                                    string supplierName    = "";
                                    int    parentID        = 0;
                                    string parentSKU       = "";
                                    var    productvariable = ProductVariableController.GetBySKU(SKU);
                                    if (productvariable != null)
                                    {
                                        supplierID   = Convert.ToInt32(productvariable.SupplierID);
                                        supplierName = productvariable.SupplierName;
                                        parentSKU    = productvariable.ParentSKU;
                                    }
                                    if (!string.IsNullOrEmpty(parentSKU))
                                    {
                                        var product = ProductController.GetBySKU(parentSKU);
                                        if (product != null)
                                        {
                                            parentID = product.ID;
                                        }
                                    }

                                    if (moveProStatus == 2)
                                    {
                                        StockManagerController.Insert(
                                            new tbl_StockManager {
                                            AgentID           = AgentID,
                                            ProductID         = 0,
                                            ProductVariableID = ID,
                                            Quantity          = Quantity,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = note,
                                            OrderID     = 0,
                                            Status      = 5,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = moveProID,
                                            ParentID    = parentID,
                                        });
                                        MoveProDetailController.Insert(moveProID, SKU, 0, ID, producttype, ProductVariable, Quantity, 0, "", supplierID,
                                                                       supplierName, ProductVariableName, ProductVariableValue, ProductName, ProductImageOrigin, true, currentDate, username);
                                    }
                                    else
                                    {
                                        MoveProDetailController.Insert(moveProID, SKU, 0, ID, producttype, ProductVariable, Quantity, 0, "", supplierID,
                                                                       supplierName, ProductVariableName, ProductVariableValue, ProductName, ProductImageOrigin, false, currentDate, username);
                                    }
                                }
                            }
                            PJUtils.ShowMessageBoxSwAlert("Tạo lệnh chuyển hàng thành công", "s", true, Page);
                        }


                        //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];
                        //        if (producttype == 1)
                        //        {
                        //            StockManagerController.Insert(AgentID, ID, 0, "", "", Quantity, 0, 2, false, 1, note, 0,
                        //                SessionInOutID, 2, ProductName, SKU, ProductImageOrigin, ProductVariable, currentDate, username);
                        //        }
                        //        else
                        //        {
                        //            StockManagerController.Insert(AgentID, 0, ID, ProductVariableName, ProductVariableValue, Quantity, 0, 2,
                        //                false, 2, note, 0, SessionInOutID, 2, ProductName, SKU, ProductImageOrigin, ProductVariable, currentDate, username);
                        //        }
                        //    }
                        //    PJUtils.ShowMessageBoxSwAlert("Xuất hàng thành công", "s", true, Page);
                        //}
                    }
                }
            }
        }