private void createUnit(int deviceID, int typeID)
    {
        Units _units = new Units();
        ProcessUnitManagementQueries _unitManagement = new ProcessUnitManagementQueries(AlarmasABC.BLL.InvokeOperations.operations.INSERT);

        try
        {
            _units.UnitID = deviceID;
            _units.UnitName = deviceID.ToString();
            _units.TypeID = typeID;
            _units.IconName = "redcar";
            _units.ComID = comID;

            _unitManagement.Units = _units;
            _unitManagement.invoke();

            /*DataSet _ds = new DataSet();
            ExecuteSQL exec = new ExecuteSQL();
            _ds = exec.getDataSet("SELECT unitID FROM tblUnits WHERE deviceID = " + deviceID +
                                  " AND unitName = '" + deviceID + "' AND comID = " + comID);
            int unitID = int.Parse(_ds.Tables[0].Rows[0][0].ToString());
            if (unitID < 1)
            {
                return -1;
            }

            return unitID;*/

        }
        catch (Exception ex)
        {
            throw new Exception("CreateNewAccount::createUnit(): " + ex.Message.ToString());
        }
        finally
        {
            _units = null;
            _unitManagement = null;
        }
    }
    private bool updateUserInfo(int UnitID, string companyID)
    {
        string _listValue = _hListValue.Value;
        string[] _listItem = _listValue.Split(';');

        if (_listItem.Length > 1)
        {
            deleteUnitUserInforamtion(UnitID, companyID);

            for (int i = 0; i < _listItem.Length - 1; ++i)
            {

                Units _unit = new Units();
                ProcessUnitManagementQueries _unitmangmnt = new ProcessUnitManagementQueries(_unit);
                try
                {
                    _unit.GroupID = int.Parse(_listItem[i]);
                    _unit.UnitID = UnitID;
                    _unit.ComID = int.Parse(companyID);

                    _unitmangmnt.Units = _unit;
                    _unitmangmnt.updateUnitUserInfo();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
                finally
                {
                    _unit = null;
                    _unitmangmnt = null;

                }
            }

        }
           return true;
    }
    private void updateInfo(string iconName, string companyID)
    {
        string patternID = cmbPattern.SelectedValue.ToString();
        int comID = int.Parse(companyID);

        //DateTime pDate = new DateTime();
        //DateTime dDate = new DateTime();
        //if (txtUnitPerchaseDate.SelectedDate.ToString() != "")
        //    pDate = Convert.ToDateTime(txtUnitPerchaseDate.SelectedDate.ToString());
        //else
        //    pDate = Convert.ToDateTime("01/01/2000");
        //if (txtDevicePerchaseDate.SelectedDate.ToString() != "")
        //    dDate = Convert.ToDateTime(txtDevicePerchaseDate.SelectedDate.ToString());
        //else
        //    dDate = Convert.ToDateTime("01/01/2000");

        Units _units = new Units();
        ProcessUnitManagementQueries _unitManagement = new ProcessUnitManagementQueries(AlarmasABC.BLL.InvokeOperations.operations.UPDATE);
        try
        {
            _units.UnitID = int.Parse(cmbUnitName.SelectedValue.ToString());
            _units.UnitName = txtName.Text.Trim();
            _units.LicenseID = txtLicense.Text.Trim();
            //_units.DriverName = txtDriver.Text.Trim();
            //_units.VIN = txtVIN.Text.Trim();
            //_units.ModelID = int.Parse(cmbUnitModel.SelectedValue.ToString());
            //_units.Unitpurchasedate = pDate;
            //_units.LevelArmor = cmbArmor.SelectedValue.ToString();
            //_units.Wtint = txtWindowtIntScheme.Text.Trim();
            //_units.Package = cmbCommonPackage.SelectedValue.ToString();
            //_units.UnitColor = txtUnitColor.Text.Trim();
            //_units.KeyCode = txtKeyCode.Text.Trim();
            //_units.Unitfueltype = int.Parse(cmbFuel.SelectedValue.ToString());
            //_units.DevicePurchaseLocation = txtDevicePerchaseLocation.Text.Trim();
            //_units.DevicePurchaseDate = dDate;
            //if (txtunitCost.Text.ToString() != "")
            //{
            //    _units.Unitcost = int.Parse(txtunitCost.Text.Trim());
            //}
            //else
            //{
            //    txtunitCost.Text = "0";
            //    _units.Unitcost = int.Parse(txtunitCost.Text.Trim());
            //}
            //_units.CounterIED = txtCounterIED.Text.Trim();
            _units.TypeID = int.Parse(cmbVehicleCat.SelectedValue.ToString());
            _units.IconName = iconName;
            _units.OtherInfo = txtOtherInfo.Text.Trim();
            _units.PatternID = int.Parse(patternID);

            _unitManagement.Units = _units;
            _unitManagement.invoke();

            int UnitID = int.Parse(cmbUnitName.SelectedValue.ToString());

            if (updateUserInfo(UnitID, companyID))
            {
                lblMessage.Text = "Unit " + _units.UnitName + " Updated Successfully...";
                clearControls();

            }
            else
                clearData(UnitID.ToString());

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString());
        }
        finally
        {
            _units = null;
            _unitManagement = null;
        }
    }
    private void saveInfo(string iconName, string companyID)
    {
        string patternID = cmbPattern.SelectedValue.ToString();
        int comID = int.Parse(companyID);

        Units _units = new Units();
        ProcessUnitManagementQueries _unitManagement = new ProcessUnitManagementQueries(AlarmasABC.BLL.InvokeOperations.operations.INSERT);
        ProcessUnitManagementQueries _umg = new ProcessUnitManagementQueries();
        DataSet _ds = new DataSet();
        try
        {
            _units.UnitID = int.Parse(txtDevice.Text.Trim());
            _units.UnitName = txtName.Text.Trim();
            _units.LicenseID = txtLicense.Text.Trim();
            _units.TypeID = int.Parse(cmbVehicleCat.SelectedValue.ToString());
            _units.IconName = iconName;
            _units.ComID = comID;
            _units.OtherInfo = txtOtherInfo.Text.Trim();
            _units.PatternID = int.Parse(patternID);

            _unitManagement.Units = _units;
            _unitManagement.invoke();

            _umg.MaxUnitId();
            _ds = _umg.Ds;
            int UnitID = int.Parse(_ds.Tables[0].Rows[0][0].ToString());

            saveUserInfo(UnitID, companyID);

            lblMessage.Text = "Unit \"" + _units.UnitName + "\" Setup Successfully...";

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            throw new Exception(ex.Message.ToString());
        }
        finally
        {
            _units = null;
            _unitManagement = null;
            _umg = null;
            _ds = null;
        }
    }
    private void loadVehicleInfo(string _UnitId, string _ComID)
    {
        Units _units = new Units();
        try
        {
            _units.UnitID = int.Parse(_UnitId);
            ProcessUnitManagementQueries _UnitManagement = new ProcessUnitManagementQueries(AlarmasABC.BLL.InvokeOperations.operations.SELECT);
            _UnitManagement.Units = _units;
            _UnitManagement.invoke();

            DataSet _ds = _UnitManagement.Ds;

            cmbVehicleCat.SelectedValue = _ds.Tables[0].Rows[0]["typeID"].ToString();
            txtLicense.Text = _ds.Tables[0].Rows[0]["LicenseID"].ToString();
            txtName.Text = _ds.Tables[0].Rows[0]["unitName"].ToString();
            txtDevice.Text = _ds.Tables[0].Rows[0]["deviceID"].ToString();
            txtOtherInfo.Text = _ds.Tables[0].Rows[0]["otherInfo"].ToString();
            loadImage(_UnitId, _ComID);
            if (_ds.Tables[0].Rows[0]["patternID"].ToString() != "")
                cmbPattern.SelectedValue = _ds.Tables[0].Rows[0]["patternID"].ToString();

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString());
        }
        finally
        {
            _units = null;
        }
    }
    private void loadImage(string _Unitid, string _comId)
    {
        Units _unit = new Units();
        _unit.UnitID = int.Parse(_Unitid);
        _unit.ComID = int.Parse(_comId);
        ProcessUnitManagementQueries _UnitImage = new ProcessUnitManagementQueries(_unit);
        _UnitImage.loadImage();
        DataSet _ds = _UnitImage.Ds;

        if (_ds.Tables[0].Rows.Count > 0)
        {
            imgIcon.Src = "";
            imgIcon.Src = "../Icon/" + _ds.Tables[0].Rows[0][0].ToString() + ".png";
        }
        else
        {

        }
    }
    private void deleteUnitUserInforamtion(int UnitId, string ComID)
    {
        Units _unit = new Units();
        ProcessUnitManagementQueries _unitmangmnt = new ProcessUnitManagementQueries(_unit);
        try
        {
            _unit.UnitID = UnitId;
            _unit.ComID = int.Parse(ComID);

            _unitmangmnt.Units = _unit;
            _unitmangmnt.deleteUnitUserInfo();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString());
        }
        finally
        {
            _unit = null;
            _unitmangmnt = null;

        }
    }
 private void clearData(string ID)
 {
     Units _unit = new Units();
     _unit.UnitID = int.Parse(ID);
     ProcessUnitManagementQueries _UmgtQry = new ProcessUnitManagementQueries(_unit);
     _UmgtQry.Units = _unit;
     _UmgtQry.clearUnitData();
 }
 private bool CheckInfo(string comID)
 {
     Units _unit = new Units();
     _unit.ComID = int.Parse(comID);
     _unit.UnitID = int.Parse(txtDevice.Text.Trim());
     _unit.UnitName = txtName.Text;
     ProcessUnitManagementQueries processmgmt = new ProcessUnitManagementQueries(_unit);
     processmgmt.Units = _unit;
     processmgmt.checkUnitExist();
     DataSet _ds = processmgmt.Ds;
     if (_ds.Tables[0].Rows.Count > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }