public void Save(string connectionString, ItemCategorySetup objItemCategorySetup)
 {
     try
     {
         var storedProcedureComandTest = "exec [spInitiatematCategoryList] " +
                                         objItemCategorySetup.CompanyID + "," +
                                         objItemCategorySetup.BranchID + "," +
                                         objItemCategorySetup.CategoryTypeID + "," +
                                         objItemCategorySetup.ItemCategoryID + ",'" +
                                         objItemCategorySetup.CategoryName + "'," +
                                         objItemCategorySetup.ParentCategoryID + "," +
                                         objItemCategorySetup.StartingItemCode + "," +
                                         objItemCategorySetup.EndingItemCode + "," +
                                         objItemCategorySetup.SeqNo + "," +
                                         objItemCategorySetup.TierNo + "," +
                                         objItemCategorySetup.CurrentBalance + ",'" +
                                         objItemCategorySetup.DataUsed + "','" +
                                         objItemCategorySetup.EntryUserName + "'";
         clsDataManipulation.StoredProcedureExecuteNonQuery(connectionString, storedProcedureComandTest);
     }
     catch (SqlException msgException)
     {
         throw msgException;
     }
     catch (Exception msgException)
     {
         throw msgException;
     }
 }
        public string SQLForAccountType(ItemCategorySetup objItemCategorySetup)
        {
            string sqlString = null;

            sqlString = @"SELECT B.AccountNo,B.AccountName FROM accCOAAccountTypeSetup A INNER JOIN accCOAHeadSetup B ON A.AccountTypeID = B.AccountTypeID
                                WHERE  A.KnownValueID = " + objItemCategorySetup.KnownValueID + " AND A.CompanyID = " + objItemCategorySetup.CompanyID + " AND A.BranchID = " + objItemCategorySetup.BranchID + "";
            return(sqlString);
        }
        protected void TreeViewCategory_SelectedNodeChanged(object sender, EventArgs e)
        {
            try
            {
                _objItemCategorySetup = new ItemCategorySetup();
                _objItemCategorySetup.ItemCategoryID = Convert.ToInt32(TreeViewCategory.SelectedNode.Value);

                var parentID = TreeViewCategory.SelectedNode.Parent == null ? _objItemCategorySetup.ItemCategoryID : Convert.ToInt32(TreeViewCategory.SelectedNode.Parent.Value);
                var childID  = 0;
                if (TreeViewCategory.SelectedNode.ChildNodes.Count > 0)
                {
                    childID = Convert.ToInt32(TreeViewCategory.SelectedNode.ChildNodes[0].Value.ToString());
                }



                int countIDDigit      = Convert.ToInt32(_objItemCategorySetup.ItemCategoryID.ToString().Length.ToString());
                int countChildIDDigit = Convert.ToInt32(childID.ToString().Length.ToString());
                if (countIDDigit == 9)
                {
                    ddlParentCategory.SelectedValue = _objItemCategorySetup.ItemCategoryID.ToString();
                    ddlCategory.SelectedValue       = _objItemCategorySetup.ItemCategoryID.ToString();
                    CheckBoxAddItem.Enabled         = true;
                    txtCategoryName.Focus();
                    txtCategoryName.Enabled  = true;
                    PanelItemDetails.Visible = false;
                    btnUpdate.Visible        = false;
                    if (countChildIDDigit == 8)
                    {
                        txtCategoryName.Enabled = false;
                    }
                }
                else
                {
                    ddlParentCategory.SelectedValue = parentID.ToString();
                    ddlCategory.SelectedValue       = parentID.ToString();
                    txtCategoryName.Enabled         = false;
                    CheckBoxAddItem.Enabled         = false;
                    PanelItemDetails.Visible        = true;
                    LoadDropDownListData(ddlItemTypeIDUpdate, ddlUnitUpdate, ddlBreakupUnitUpdate, ddlItemUsageIDUpdate, ddlRelatedSupplierUpdate, ddlSalesAccountNoUpdate,
                                         ddlStockAccountNoUpdate, ddlCOGSAccountNoUpdate, ddlSalesReturnAccountUpdate);
                    _objItemSetup        = new ItemSetup();
                    _objItemSetup.ItemID = Convert.ToInt32(TreeViewCategory.SelectedNode.Value);
                    Session["itemID"]    = _objItemSetup.ItemID;
                    ShowItemDetails(_objItemSetup);
                    btnUpdate.Visible = true;
                }
            }
            catch (Exception msgException)
            {
                clsTopMostMessageBox.Show(msgException.Message);
            }
        }
 internal DataTable CheckItem(string connectionString, ItemCategorySetup objItemCategorySetup)
 {
     try
     {
         DataTable dtItem    = null;
         string    sqlString = "SELECT * FROM matMaterialSetup WHERE DataUsed = 'A' AND ItemCategoryID = " + objItemCategorySetup.ItemCategoryID + " OR ItemID = " + objItemCategorySetup.ItemCategoryID + "";
         dtItem = clsDataManipulation.GetData(connectionString, sqlString);
         return(dtItem);
     }
     catch (SqlException msgException)
     {
         throw msgException;
     }
     catch (Exception msgException)
     {
         throw msgException;
     }
 }
        private void LoadDropDownListData(DropDownList targetDDLItemTypeID, DropDownList targetDDLUnit, DropDownList targetDDBreakupUnit, DropDownList targetDDItemUsageID,
                                          DropDownList targetDDRelatedSupplier, DropDownList targetDDSalesAccountNo, DropDownList targetDDStockAccountNo, DropDownList targetDDCOGSAccountNo,
                                          DropDownList targetDDSalesReturnAccount)
        {
            try
            {
                ItemTypeSetupController objItemTypeSetupController = new ItemTypeSetupController();
                _objCompanySetup           = new CompanySetup();
                _objCompanySetup.CompanyID = Convert.ToInt32(Session["company"].ToString());
                _objBranchSetup            = new BranchSetup();
                _objBranchSetup.BranchID   = Convert.ToInt32(Session["branch"].ToString());
                ClsDropDownListController.LoadDropDownList(_connectionString, objItemTypeSetupController.ItemTypeSql(_objCompanySetup, _objBranchSetup), targetDDLItemTypeID, "ItemType", "ItemTypeID");
                UnitSetupController objUnitSetupController = new UnitSetupController();
                ClsDropDownListController.LoadDropDownList(_connectionString, objUnitSetupController.UnitSql(_objCompanySetup, _objBranchSetup), targetDDLUnit, "Unit", "UnitID");
                ClsDropDownListController.LoadDropDownList(_connectionString, objUnitSetupController.UnitSql(_objCompanySetup, _objBranchSetup), targetDDBreakupUnit, "Unit", "UnitID");
                ItemUsageSetupController objItemUsageSetupController = new ItemUsageSetupController();
                ClsDropDownListController.LoadDropDownList(_connectionString, objItemUsageSetupController.ItemUsageSql(_objCompanySetup, _objBranchSetup), targetDDItemUsageID, "ItemUsage", "ItemUsageID");
                SuppliersController objSuppliersController = new SuppliersController();
                ClsDropDownListController.LoadDropDownList(_connectionString, objSuppliersController.SQLGetAllSuppliers(_objCompanySetup, _objBranchSetup), targetDDRelatedSupplier, "FullName", "ContactID");
                _objItemSetupController         = new ItemSetupController();
                _objItemCategorySetup           = new ItemCategorySetup();
                _objItemCategorySetup.CompanyID = _objCompanySetup.CompanyID;
                _objItemCategorySetup.BranchID  = _objBranchSetup.BranchID;

                _objItemCategorySetup.KnownValueID = Convert.ToInt32(EnumCollections.eTransactionType.eSalesTrans);
                ClsDropDownListController.LoadDropDownList(_connectionString, _objItemSetupController.SQLForAccountType(_objItemCategorySetup), targetDDSalesAccountNo, "AccountName", "AccountNo");
                _objItemCategorySetup.KnownValueID = Convert.ToInt32(EnumCollections.eTransactionType.eStock);
                ClsDropDownListController.LoadDropDownList(_connectionString, _objItemSetupController.SQLForAccountType(_objItemCategorySetup), targetDDStockAccountNo, "AccountName", "AccountNo");
                _objItemCategorySetup.KnownValueID = Convert.ToInt32(EnumCollections.eTransactionType.eCOGS);
                ClsDropDownListController.LoadDropDownList(_connectionString, _objItemSetupController.SQLForAccountType(_objItemCategorySetup), targetDDCOGSAccountNo, "AccountName", "AccountNo");
                _objItemCategorySetup.KnownValueID = Convert.ToInt32(EnumCollections.eTransactionType.eSalesReturn);
                ClsDropDownListController.LoadDropDownList(_connectionString, _objItemSetupController.SQLForAccountType(_objItemCategorySetup), targetDDSalesReturnAccount, "AccountName", "AccountNo");
            }
            catch (Exception msgException)
            {
                throw msgException;
            }
        }
        private void AddValuesToCategory()
        {
            try
            {
                _objItemCategorySetup                = new ItemCategorySetup();
                _objItemCategorySetup.CompanyID      = Convert.ToInt32(Session["company"].ToString());
                _objItemCategorySetup.BranchID       = Convert.ToInt32(Session["branch"].ToString());
                _objItemCategorySetup.CategoryTypeID = Convert.ToInt32(ddlProductType.SelectedValue);
                _objItemCategorySetup.ItemCategoryID = CreateCategoryID();
                _objItemCategorySetup.CategoryName   = txtCategoryName.Text == string.Empty ? null : txtCategoryName.Text;

                _objItemCategorySetup.ParentCategoryID = ddlParentCategory.SelectedValue == "-1" ? Convert.ToInt32("1" + _objItemCategorySetup.CompanyID.ToString() + _objItemCategorySetup.BranchID.ToString()) :
                                                         Convert.ToInt32(ddlParentCategory.SelectedValue);
                _objItemCategorySetup.StartingItemCode = 0;
                _objItemCategorySetup.EndingItemCode   = 0;
                _objItemCategorySetup.SeqNo            = Convert.ToInt32(Session["sequenceNumber"].ToString());
                _objItemCategorySetup.TierNo           = Convert.ToInt32(Session["tierNumber"].ToString());
                _objItemCategorySetup.CurrentBalance   = 0;
                _objItemCategorySetup.DataUsed         = "A";
                _objItemCategorySetup.EntryUserName    = Session["entryUserCode"].ToString();
                _objItemCategorySetupController        = new ItemCategorySetupController();
                _objItemCategorySetupController.Save(_connectionString, _objItemCategorySetup);
                ClearCategory();
                TreeViewCategory.Nodes.Clear();
                PopulateRootLevel();
                LoadCategory(ddlCategory);
                LoadCategory(ddlParentCategory);
            }
            catch (SqlException msgException)
            {
                throw msgException;
            }
            catch (Exception msgException)
            {
                throw msgException;
            }
        }