private void Item_Click(object sender, MenuEventArgs args)
        {
            switch (args.formID)
            {
            case "FRM001":
                BudgetControlForm frm1 = new BudgetControlForm(true);
                frm1.Show();
                break;

            case "FRM008":
                BudgetControlForm frm9 = new BudgetControlForm(false);
                frm9.Show();
                break;

            case "FRM004":
                POEntryForm frm2 = new POEntryForm(null);
                frm2.Show();
                break;

            case "FRM005":
                POReceiptForm frm3 = new POReceiptForm();
                frm3.Show();
                break;

            case "FRM006":
                MaterialIssueForm frm4 = new MaterialIssueForm();
                frm4.Show();
                break;

            case "butPOBalance":
                POBalanceInquiry frm5 = new POBalanceInquiry();
                frm5.Show();
                break;

            case "FRM002":
                RequisitionEntryForm frm6 = new RequisitionEntryForm();
                frm6.Show();
                break;

            case "FRM003":
                RequisitionFinalForm frm7 = new RequisitionFinalForm();
                frm7.Show();
                break;

            case "FRM007":
                MaterialReturnForm frm8 = new MaterialReturnForm();
                frm8.Show();
                break;

            case "FRM009":
                RequisitionConfirmForm frm10 = new RequisitionConfirmForm();
                frm10.Show();
                break;

            default:
                break;
            }
        }
        private void Menu_Click(object sender, EventArgs e)
        {
            Button but = sender as Button;

            switch (but.Name)
            {
            case "butBudgetCtrl":
                BudgetControlForm frm1 = new BudgetControlForm(true);
                frm1.Show();
                break;

            case "butPurchaseOrder1":
                POEntryForm frm2 = new POEntryForm(null);
                frm2.Show();
                break;

            case "butPOReceiving":
                POReceiptForm frm3 = new POReceiptForm();
                frm3.Show();
                break;

            case "butMaterialIssue":
                MaterialIssueForm frm4 = new MaterialIssueForm();
                frm4.Show();
                break;

            case "butPOBalance":
                POBalanceInquiry frm5 = new POBalanceInquiry();
                frm5.Show();
                break;

            case "butRequisition":
                RequisitionEntryForm frm6 = new RequisitionEntryForm();
                frm6.Show();
                break;

            case "butRequisitionFinaly":
                RequisitionFinalForm frm7 = new RequisitionFinalForm();
                frm7.Show();
                break;

            case "butMaterialReturn":
                MaterialReturnForm frm8 = new MaterialReturnForm();
                frm8.Show();
                break;

            default:
                break;
            }
        }
        private void ConvertPO_Click(object sender, EventArgs e)
        {
            //_view.RefreshLinesGird();
            bool   jobProcess = false;
            int    vendorId   = 0;
            string poTypeCode = string.Empty;

            if (_view.linesSelected.Count == 0)
            {
                return;
            }

            var reqLines = _view.linesSelected;

            //Validation multiple Vendors
            var resVendors = reqLines.GroupBy(x => x.VendorId)
                             .Select(group => new { Vendor = group.Key, lines = group.ToList() })
                             .ToList();

            if (resVendors.Count > 1)
            {
                MessageBox.Show("Lines seleted more than one Vendors, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                vendorId = resVendors.FirstOrDefault().Vendor;
            }

            //Validation multiple Line Type
            var resTypes = reqLines.GroupBy(x => x.LineType)
                           .Select(group => new { LineType = group.Key, lines = group.ToList() })
                           .ToList();

            if (resTypes.Count > 1)
            {
                MessageBox.Show("Lines seleted more than one Type, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                //Set PO Type Code.
                poTypeCode = resTypes.FirstOrDefault().LineType;

                var costs = _repoProj.GetCostGropAll();
                var str   = (from c in _view.linesSelected
                             select new { costCode = c.CostCode }).ToArray();

                var query = costs.Where(x => str.Any(a => a.costCode == x.CostCode)).ToList()
                            .GroupBy(p => p.MakingFlag)
                            .Select(group => new { makings = group.Key, glines = group.ToList() })
                            .ToList();
                if (query.Count > 1)
                {
                    MessageBox.Show("Lines seleted more than one Type, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    //Set PO Job Process Flag.
                    jobProcess = query.ToList().FirstOrDefault().makings;
                }
                //var jobProcessCosts = costs.Where(x => costs)
            }

            var resUnConfirm = reqLines.Where(x => !x.FinalConfirmFlag).ToList();

            if (resUnConfirm.Count > 0)
            {
                MessageBox.Show("Some lines seleted is not Confirm price.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            POHeaderModel head = new POHeaderModel();

            head.ProjectId      = _view.projectParam.Id;
            head.ProjectNum     = _view.projectParam.ProjectNum;
            head.JobFlag        = jobProcess;
            head.TypeLookupCode = poTypeCode;
            head.VendorId       = vendorId;
            head.PODate         = DateTime.Now;
            head.Status         = "OPEN";
            head.StatusCode     = "OPEN";
            head.BuyerId        = _view.EpiSession.User.Id;
            head.BuyerName      = _view.EpiSession.User.UserName;

            string typeLookup = string.Empty;

            if (head.TypeLookupCode == "STANDARD")
            {
                typeLookup = "PURCHASE_PO";
            }
            else if (head.TypeLookupCode == "MAKING")
            {
                if (head.JobFlag)
                {
                    typeLookup = "PURCHASE_PD";
                }
                else
                {
                    typeLookup = "PURCHASE_PO";
                }
            }
            //Combind Vendor Detail.
            head = CombindVendor(head);

            head.SubTotal   = _view.linesSelected.Sum(x => x.ExtendedAmount);
            head.PoNum      = _repoPO.GetDocNoByType(typeLookup);
            head.PoHeaderId = _repoPO.InsertPO(head);

            //Validate to Add Line
            if (head.PoHeaderId != 0)
            {
                try
                {
                    if (_view.linesSelected != null)
                    {
                        //List<POLineModel> list = _view.poLine;
                        foreach (RequisitionLineModel item in _view.linesSelected)
                        {
                            POLineModel pol = new POLineModel();
                            pol.PoHeaderId      = head.PoHeaderId;
                            pol.LastUpdatedBy   = _view.EpiSession.User.Id;
                            pol.CreatedBy       = _view.EpiSession.User.Id;
                            pol.RefProjectId    = _view.projectParam.Id;
                            pol.RefProjectNum   = _view.projectParam.ProjectNum;
                            pol.LastUpdateDate  = DateTime.Now;
                            pol.CreationDate    = DateTime.Now;
                            pol.Status          = "OPEN";
                            pol.BalloonNo       = item.BalloonNo;
                            pol.ItemCode        = item.ItemCode;
                            pol.Quantity        = item.Quantity;
                            pol.ItemDescription = item.ItemDescription;
                            pol.Spec            = item.SpecModel;
                            pol.BrandMaterail   = item.BrandMaterail;
                            pol.CostCode        = item.CostCode;
                            pol.BOM             = item.BomNo;
                            pol.Suplier         = item.SuplierSymbol;
                            pol.UnitPrice       = item.FinalUnitPrice;
                            pol.DueDate         = item.DueDate;
                            pol.ECN             = item.EcnNo;
                            pol.CSR             = item.CsrNo;
                            pol.Uom             = item.Uom;
                            pol.LeadTime        = item.LeadTime;
                            pol.LoadBomDate     = item.LoadBomDate;

                            int lineId = _repoPO.InsertPOLine(pol);
                            if (lineId != 0)
                            {
                                item.PurchasedFlag     = true;
                                item.PurchasedQuantity = item.Quantity;
                                item.PoLineId          = lineId;
                                item.PoHeaderId        = head.PoHeaderId;
                                _repository.UpdatePRLine(item);
                            }
                        }

                        //Update Purchased flag in Requisition Header
                        var grpHeads = _view.linesSelected.GroupBy(item => item.RequisitionHeaderId)
                                       .Select(group => new { reqHeaderId = group.Key, ReqLines = group.ToList() })
                                       .ToList();
                        foreach (var req in grpHeads)
                        {
                            _repository.UpdatePurchasedFlag(req.reqHeaderId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("PO Lines is Error! " + Environment.NewLine
                                    + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Filter(null, null);
                MessageBox.Show(string.Format("Convert to PO Number : {0} complete.", head.PoNum), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                POEntryForm POfrm = new POEntryForm(head);
                POfrm.Show();
            }
        }