private void addActDetails()
        {
            if (lstBoxFabCost.Items.Count != 0 && lstBoxAccCostPI.Items.Count != 0 && cmbCurrency.SelectedIndex != -1)
            {
                ActualCostHandle actCostHandle = new ActualCostHandle();
                FOBActualCostDAO daoObject = new FOBActualCostDAO();
                string cmx = cmbCurrency.Text;
                
                double total = actCostHandle.calTotalCost(lstBoxFabCost, lstBoxAccCostPI);

                if (daoObject.addActualCost(total, cmx))
                {
                    string ActCostId = daoObject.getLastActualCostId();
                    bool getverificatio1 = false, getverificatio2 = false;
                    AccessoryCostData accCostData = new AccessoryCostData();
                    FabricCostData fabCostData = new FabricCostData();

                    int size = lstBoxAccCostPI.Items.Count;

                    for (int i = 0; i < size; i++)
                    {
                        accCostData.Unit = actCostdao.getuntype(lstBoxAccType.Items[i].ToString());
                        //accCostData.Unit = actCostHandle.getUnitType(lstBoxAccType.Items[i].ToString());
                        accCostData.Amount = Convert.ToDouble(lstBoxAccAmt.Items[i].ToString());
                        accCostData.Type = lstBoxAccType.Items[i].ToString();
                        accCostData.Cost = Convert.ToDouble(lstBoxAccCostPI.Items[i].ToString());
                        accCostData.WeightPItem = Convert.ToDouble(lstBoxAccWPI.Items[i].ToString());
                        accCostData.AcostID = ActCostId;
                        accCostData.Chg = Convert.ToDouble(lstBoxAccCostForH.Items[i].ToString());

                        getverificatio1 = daoObject.addAccessoryCost(accCostData);

                    }
                    size = lstBoxFabCost.Items.Count;
                    for (int i = 0; i < size; i++)
                    {
                        fabCostData.Type = lstBoxFabType.Items[i].ToString();
                        fabCostData.Amount = Convert.ToDouble(lstBoxFabComsup.Items[i].ToString());
                        fabCostData.Cost = Convert.ToDouble(lstBoxFabCost.Items[i].ToString());
                        fabCostData.CostPyard = Convert.ToDouble(lstBoxFabCPY.Items[i].ToString());
                        fabCostData.ACostID = ActCostId;

                        getverificatio2 = daoObject.addFabricCost(fabCostData);
                    }

                    if (getverificatio1 && getverificatio2 && daoObject.updateStock(cmbSelectItem.Text.ToString().Split('|')[1], ActCostId))
                    {
                        _context.SaveChanges();
                        _context.ActualCosts.Load();

                        this.actualCostDataGrid.Items.Refresh();
                        actCostdao.updateSearchComboBox(cmbEditAcost);
                        actCostdao.getTotal(ActCostId, lblCmDisplay, lblActCost_Display, true);
                        populateItemCombo();
                        clearAcc();
                        MessageBox.Show("Successfully Added", "Successful", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                }
                else
                { }
            }
            else if (cmbCurrency.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select CM", "Select", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Please Add values to the Fabrics and Accessories", "Empty fileds available", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void editActAccCost()
        {
            FabricCostData fabdata = new FabricCostData();
            AccessoryCostData accdata = new AccessoryCostData();
            ActualCostHandle actCostHandle = new ActualCostHandle();
            bool chk1 = true;
            bool chk2 = true;
            bool chk3 = true;
            bool chk4 = true;
            foreach (string w in fabIDtoRem)
            {
                if (!actCostdao.deleteFromFab(w))
                    chk1 = false;
            }
            foreach (string w in accIDtoRem)
            {
                if (!actCostdao.deleteFromAcc(w))
                    chk2 = false;
            }



            for (int i = 0; i < lstBoxFabCostID.Items.Count; i++)
            {
                if (lstBoxFabCostID.Items[i].ToString() == "XXXX")
                {


                    fabdata.Type = lstBoxFabType.Items[i].ToString();
                    fabdata.Amount = Convert.ToDouble(lstBoxFabComsup.Items[i].ToString());
                    fabdata.Cost = Convert.ToDouble(lstBoxFabCost.Items[i].ToString());
                    fabdata.CostPyard = Convert.ToDouble(lstBoxFabCPY.Items[i].ToString());
                    fabdata.ACostID = cmbEditAcost.Text;

                    if (!actCostdao.addFabricCost(fabdata))
                        chk3 = false;
                }
            }//for loop for addign fabrics in the edit part ends

            for (int i = 0; i < lstBoxAccCostID.Items.Count; i++)
            {
                if (lstBoxAccCostID.Items[i].ToString() == "XXXX")
                {
                    accdata.Unit = actCostdao.getuntype(lstBoxAccType.Items[i].ToString());
                    //accdata.Unit = actCostHandle.getUnitType(lstBoxAccType.Items[i].ToString());
                    accdata.Amount = Convert.ToDouble(lstBoxAccAmt.Items[i].ToString());
                    accdata.Type = lstBoxAccType.Items[i].ToString();
                    accdata.Cost = Convert.ToDouble(lstBoxAccCostPI.Items[i].ToString());
                    accdata.WeightPItem = Convert.ToDouble(lstBoxAccWPI.Items[i].ToString());
                    accdata.AcostID = cmbEditAcost.Text;
                    accdata.Chg = Convert.ToDouble(lstBoxAccCostForH.Items[i].ToString());

                    if (!actCostdao.addAccessoryCost(accdata))
                        chk4 = false;

                }
            }//for loop for adding acc in the edit part ends

            double totalx = actCostHandle.calTotalCost(lstBoxFabCost, lstBoxAccCostPI);
            //MessageBox.Show(actCostdao.editActCost(cmbEditAcost.Text.ToString(), totalx, cmbCurrency.Text).ToString()+"|"+ chk1.ToString()+"|"+chk2.ToString()+"|"+chk3.ToString()+"|"+chk4.ToString());
            if (actCostdao.editActCost(cmbEditAcost.Text.ToString(), totalx, cmbCurrency.Text) && chk1 && chk2 && chk3 && chk4)
            {
                MessageBox.Show("Successfully Edited", "Successful", MessageBoxButton.OK, MessageBoxImage.Information);
                _context.ActualCosts.Load();

                this.actualCostDataGrid.Items.Refresh();
                string actcostid = cmbEditAcost.Text;
                clearAll();
                cmbEditAcost.SelectedItem = actcostid;
                loadData(false);
                actCostdao.getTotal(cmbEditAcost.Text, lblCmDisplay, lblActCost_Display, false);

            }
            else
                MessageBox.Show("Faild to Edit", "Faild", MessageBoxButton.OK, MessageBoxImage.Exclamation);
        }
        //this method add data to accessoryCost table
        public bool addAccessoryCost(AccessoryCostData data)
        {
            try
            {
               
                    AccessoryCost actCost = new AccessoryCost();
                    
                    actCost.Type = data.Type;
                    actCost.Amount = (float)data.Amount;
                    actCost.Cost = (decimal)data.Cost;
                    actCost.ACostID = data.AcostID;
                    actCost.wieghtPitem = (float)data.WeightPItem;
                    actCost.Unit = data.Unit;
                    actCost.costPerHundredgms = (float)data.Chg;

                   _context.AccessoryCosts.Add(actCost);
                   int done = _context.SaveChanges();

                   
                   if (done != -1)
                    return true;
                   else
                       return false;
                  
                   
                
            }
            catch (Exception e)
            {

                addException(e, "addAccessoryCost()");
                return false;
            }
        }