private void dtgv_header_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                if (listplanShipment != null)
                {
                    string productKey   = dtgv_header.Rows[e.RowIndex].Cells[0].Value.ToString();
                    var    PlanShipment = listplanShipment[productKey];
                    dtgv_content.DataSource = PlanShipment;
                    //  settingdatagridview(dtgv_content);
                }
                if (dtgv_header.Columns[e.ColumnIndex].Name == "SemiFinishedGoods")
                {
                    string product = dtgv_header.Rows[e.RowIndex].Cells["product"].Value.ToString();
                    string SemiFGs = dtgv_header.Rows[e.RowIndex].Cells["SemiFinishedGoods"].Value.ToString();

                    GetSemiFinishedgoods     getSemiFinishedgoods = new GetSemiFinishedgoods();
                    List <SemiFinishedGoods> semiFinishedGoods    = getSemiFinishedgoods.ListGetSemiFinishedGoods(cb_Department.SelectedItem.ToString(), product, 1);
                    for (int i = 0; i < semiFinishedGoods.Count; i++)
                    {
                        var semigroupbyItem = ListSemiFinishedGoods.Where(d => d.Item == semiFinishedGoods[i].Item).ToList();
                        //if (semigroupbyItem.Count > 1)
                        //    ;
                        semiFinishedGoods[i].QtyNeed = ListSemiFinishedGoods.Where(d => d.Item == semiFinishedGoods[i].Item).Select(d => d.QtyNeed).Sum();
                    }

                    SemiFinishedGoodsForm semiFinishedGoodsForm = new SemiFinishedGoodsForm(semiFinishedGoods);
                    semiFinishedGoodsForm.Show();
                }
                else if (dtgv_header.Columns[e.ColumnIndex].Name == "StockInWarehouse")
                {
                    string product = dtgv_header.Rows[e.RowIndex].Cells["product"].Value.ToString();
                    List <ItemsInINVMC> itemsInINVMCs   = new List <ItemsInINVMC>();
                    GetStockinINVMC     getStockinINVMC = new GetStockinINVMC();
                    itemsInINVMCs = getStockinINVMC.GetItemsInINVMCs("", product);
                    StockInWarehouseShow inWarehouseShow = new StockInWarehouseShow(itemsInINVMCs);
                    inWarehouseShow.Show();
                }
            }
        }
        public Dictionary <string, PlanningItem> GetPlanningReportbyDept(string dept, List <OrderVariable> orders)
        {
            Dictionary <string, PlanningItem> keyValuePairs = new Dictionary <string, PlanningItem>();
            List <List <OrderVariable> >      listOders     = new List <List <OrderVariable> >();

            listOders = ListOrdervariables(orders);

            try
            {
                foreach (var order in listOders)
                {
                    PlanningItem pLanning = new PlanningItem();

                    GetSemiFinishedgoods getSemiFinishedgoods = new GetSemiFinishedgoods();
                    pLanning.KeyProduct = order[0].Product;
                    pLanning.Unit       = order[0].Unit;
                    //  List<Accessory> ListAccessories = getAccessory.GetAccessories(pLanning.KeyProduct);

                    // base on product to defind Dept

                    if (order[0].Product.Contains("BMH") && order[0].DDH.Contains("B"))
                    {
                        pLanning.Client = "MH";
                    }
                    else if (order[0].Product.Contains("BWT") && order[0].DDH.Contains("B"))
                    {
                        pLanning.Client = "WT";
                    }
                    else if (order[0].Product.Contains("BFF") && order[0].DDH.Contains("B"))
                    {
                        pLanning.Client = "FF";
                    }
                    else if (order[0].Product.Contains("P25") || order[0].Product.Contains("P40") || order[0].Product.Contains("P259"))
                    {
                        pLanning.Client = "JAMAK";
                    }
                    else if (order[0].Product.Contains("P05") || order[0].Product.Contains("P111"))
                    {
                        pLanning.Client = "MH";
                    }
                    else if (order[0].Product.Contains("P117"))
                    {
                        pLanning.Client = "PTC";
                    }
                    else if (order[0].DDH.Contains("A"))
                    {
                        pLanning.Client = order[0].Product.Split('-').Count() > 0 ? order[0].Product.Split('-')[1] : "";
                    }
                    else
                    {
                        pLanning.Client = order[0].Product.Replace(order[0].ProductName, "").Substring(1);
                    }
                    // Define Shiment Plan of production
                    pLanning.shipmentPlans    = new List <ShipmentPlan>();
                    pLanning.needProduceQties = new List <NeedProduceQty>();
                    foreach (var or in order)
                    {
                        ShipmentPlan shipment = new ShipmentPlan();
                        shipment.ClientRequestDate = or.ClientRequestDate;
                        shipment.ClientCode        = or.ClientOrder;
                        shipment.DeliveryPlanQty   = or.DeliveryQty;
                        shipment.NeedQty           = or.ClientOrderQty;
                        shipment.RemainDay         = (or.ClientRequestDate - DateTime.Now.Date).Days;
                        shipment.NeedQtyPerDay     = shipment.NeedQty / shipment.RemainDay;
                        shipment.OrderCode         = or.DDH;
                        pLanning.shipmentPlans.Add(shipment);

                        NeedProduceQty need = new NeedProduceQty();
                        need.ClientRequestDate = or.ClientRequestDate;
                        need.NeedQty           = or.ClientOrderQty;
                        need.RemainDay         = (or.ClientRequestDate - DateTime.Now.Date).Days;
                        need.NeedQtyPerDay     = need.NeedQty / need.RemainDay;
                        pLanning.needProduceQties.Add(need);
                    }
                    pLanning.TotalQty = pLanning.shipmentPlans.Select(d => d.NeedQty).Sum();

                    pLanning.SemiFinishedGoods = new List <SemiFinishedGoods>();
                    if (dept == "B01-MH")
                    {
                        var StockSFT = getSemiFinishedgoods.GetStockGoodsONSFT(dept, pLanning.KeyProduct);
                        pLanning.SemiFinishedGoods.Add(StockSFT);
                    }
                    else if (dept == "B01-FF")
                    {
                        var StockSFT = getSemiFinishedgoods.GetStockGoodsONSFT(dept, pLanning.KeyProduct);
                        pLanning.SemiFinishedGoods.Add(StockSFT);
                    }
                    else if (dept == "A01-Gia Dung")
                    {
                        pLanning.SemiFinishedGoods = getSemiFinishedgoods.ListGetSemiFinishedGoods(dept, pLanning.KeyProduct, pLanning.TotalQty);
                    }
                    else if (dept == "A01-PTC")
                    {
                        pLanning.SemiFinishedGoods = getSemiFinishedgoods.ListGetSemiFinishedGoods(dept, pLanning.KeyProduct, pLanning.TotalQty);
                    }

                    keyValuePairs.Add(pLanning.KeyProduct, pLanning);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(keyValuePairs);
        }