private void SaveUnitType()
    {
        AlarmasABC.Core.Admin.UnitType _unitType = new AlarmasABC.Core.Admin.UnitType();

        ProcessUnitTypeNotQueries insert = new ProcessUnitTypeNotQueries(AlarmasABC.BLL.InvokeOperations.operations.INSERT);

        try
        {
            _unitType.TypeName = _txtTypeName.Text;
            string _comID = Session["trkCompany"].ToString();
            _unitType.ComID = int.Parse(_comID);

            insert.UnitType = _unitType;
            insert.invoke();

            clearControls();
            _lblMessage.ForeColor = System.Drawing.Color.Green;
            _lblMessage.Text = "Unit Type created Successfully.";

        }
        catch (Exception ex)
        {
            throw new Exception(" CompanyAdmin::UnitType:: " + ex.Message.ToString());
            _lblMessage.ForeColor = System.Drawing.Color.Red;
            _lblMessage.Text = "Unit Type create fail.";
        }
        finally
        {
            _unitType = null;
        }
    }
    protected void _rgrdtype_DeleteCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string _typeID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["typeID"].ToString();
        string _tName = ((Label)e.Item.FindControl("lbltypeName")).Text;
        if (!UnitExist(_typeID))
        {
            ProcessUnitTypeNotQueries delete = new ProcessUnitTypeNotQueries(AlarmasABC.BLL.InvokeOperations.operations.DELETE);

            AlarmasABC.Core.Admin.UnitType _unitType = new AlarmasABC.Core.Admin.UnitType();
            try
            {

                _unitType.TypeID = int.Parse(_typeID);

                delete.UnitType = _unitType;
                delete.invoke();

            }
            catch (Exception ex)
            {
                throw new Exception(" :: " + ex.Message);
            }

            finally
            {
                _unitType = null;
            }
        }
        else
        {
            _lblMessage.Text = "Unit category "+_tName+ " in use and can't be deleted";
        }
    }
    protected void _rgrdtype_UpdateCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string _typeID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["typeID"].ToString();
        string _typeName = (editedItem["typeName"].Controls[0] as TextBox).Text;

        AlarmasABC.Core.Admin.UnitType _unitType = new AlarmasABC.Core.Admin.UnitType();
        ProcessUnitTypeNotQueries _updateType = new ProcessUnitTypeNotQueries(AlarmasABC.BLL.InvokeOperations.operations.UPDATE);

        try
        {
            _unitType.Name = _typeName;
            _unitType.TypeID = int.Parse(_typeID);
            _unitType.ComID = int.Parse(Session["trkCompany"].ToString());

            _updateType.UnitType = _unitType;
            _updateType.invoke();

        }
        catch (Exception ex)
        {
            throw new Exception(" CompanyAdmin::UnitType:: " + ex.Message.ToString());
        }

        finally
        {
            _unitType = null;
            _updateType = null;
        }
        _lblMessage.Text = "Unit Type Updated Successfully.";
        _lblMessage.ForeColor = System.Drawing.Color.Green;
    }
    private int createUnitGroup(string name)
    {
        AlarmasABC.Core.Admin.UnitType unitType = new AlarmasABC.Core.Admin.UnitType();

        ProcessUnitTypeNotQueries insert = new ProcessUnitTypeNotQueries(AlarmasABC.BLL.InvokeOperations.operations.INSERT);

        try
        {
            unitType.TypeName = name;
            unitType.ComID = comID;

            insert.UnitType = unitType;
            insert.invoke();

            DataSet _ds = new DataSet();
            ExecuteSQL exec = new ExecuteSQL();
            _ds = exec.getDataSet("SELECT typeID FROM tblUnitType WHERE comID = "
                                  + comID + " AND typeName = '" + name + "';");

            int typeID = int.Parse(_ds.Tables[0].Rows[0][0].ToString());
            if (typeID < 1)
            {
                return -1;
            }

            return typeID;

        }
        catch (Exception ex)
        {
            throw new Exception(" CreateNewAccount::createUnitGroup(): " + ex.Message.ToString());
        }
        finally
        {
            unitType = null;
        }
    }