protected void btnAddUser_Click(object sender, EventArgs e)
    {
        DealerUsers objUsers = new DealerUsers();

        DataTable dtUsers = new DataTable();

        dtUsers = (DataTable)Session["DealerUsers"];

        DataView dv = new DataView();

        DataTable dt = new DataTable();

        dv = dtUsers.DefaultView;

        dv.RowFilter = "UserID='" + txtUserID.Text + "'";

        dt = dv.ToTable();

        if (dt.Rows.Count == 0)
        {
            objUsers.AddDealerUsers(Session[Constants.DealerCode].ToString(), "0", txtName.Text, txtUserID.Text, txtPassword.Text, txtUserName.Text, txtPhoneNumber.Text, Convert.ToInt32(ddlActive.SelectedItem.Value));

            FillUsers();
        }
        else
        {
            MpeAlert.Show();
            lblErrorMSg.Visible = true;
            lblErrorMSg.Text = "User ID already exists.";

        }
    }
    private void FillUsers()
    {
        DealerUsers objUsers = new DealerUsers();
        DataSet dsUsers = new DataSet();
        try
        {
            dsUsers = objUsers.GetDealerGetUsers(Session[Constants.DealerCode].ToString());

            if (dsUsers.Tables[0].Rows.Count > 0)
            {
                grdUsers.DataSource = dsUsers.Tables[0];
                grdUsers.DataBind();
                Session["DealerUsers"] = dsUsers.Tables[0];

                DataView dv = new DataView();
                DataTable dt = new DataTable();
                dv = dsUsers.Tables[0].DefaultView;
                dv.RowFilter = "isdefault=1";
                dt = dv.ToTable();

                ArrayList strAddress = new ArrayList();
                strAddress.Add(dt.Rows[0]["Address"].ToString().Trim());
                strAddress.Add(dt.Rows[0]["City"].ToString().Trim());
                strAddress.Add(dt.Rows[0]["State_Code"].ToString());
                strAddress.Add(dt.Rows[0]["Zip"].ToString());

                lblDealerBName.Text = dt.Rows[0]["BusinessName"].ToString().Trim();
                lblDealerCode.Text = dt.Rows[0]["DealerCode"].ToString().Trim();

                if (strAddress[0].ToString() != "0" && (strAddress[1].ToString() != "" || strAddress[2].ToString() != "UN" || strAddress[3].ToString() != ""))
                {
                    lblDealerAddress.Text = GeneralFunc.ToProper(strAddress[0].ToString()).Trim() + ", ";
                }
                else
                {
                    lblDealerAddress.Text = GeneralFunc.ToProper(strAddress[0].ToString()).Trim();
                }

                if (strAddress[1].ToString() != "" && (strAddress[2].ToString() != "UN" || strAddress[3].ToString() != ""))
                {
                    lblDealerCity.Text = GeneralFunc.ToProper(strAddress[1].ToString()).Trim() + ", ";
                }
                else
                {
                    lblDealerCity.Text = GeneralFunc.ToProper(strAddress[1].ToString()).Trim();
                }

                if ((strAddress[2].ToString() != "UN") && (strAddress[3].ToString() != ""))
                {
                    lblDealerState.Text = strAddress[2].ToString() + " ";
                }
                else if ((strAddress[2].ToString() != "UN") && (strAddress[3].ToString() == ""))
                {
                    lblDealerState.Text = strAddress[2].ToString();
                }
                lblDealerZip.Text = strAddress[3].ToString();
                lblDealerPhone.Text = objGeneralFunc.filPhnm(dt.Rows[0]["Phonenumber"].ToString().Trim());
                lblDealerEmail.Text = dt.Rows[0]["UserName"].ToString().Trim();

            }

        }
        catch (Exception ex)
        {

        }
    }
    protected void btnEdit_Click1(object sender, EventArgs e)
    {
        DealerUsers objUsers = new DealerUsers();

        objUsers.AddDealerUsers(Session[Constants.DealerCode].ToString(), txtEditUId.Value, txtEditName.Text, txtEditUserID.Text, txtEditNewPassword.Text, txtEditUserName.Text, txtEditPhoneNumber.Text, Convert.ToInt32(ddlEditActive.SelectedItem.Value));

        FillUsers();
    }