protected void btnLogon_Click(object sender, EventArgs e)
        {
            string username = txtName.Text.Trim().ToLower();
            string password = txtPwd.Text.Trim().ToLower();

            EnterpriseUser enterpriseUser = new EnterpriseUser();
            enterpriseUser.Username = username;
            enterpriseUser.Password = password;

            EnterpriseUserBLL enterpriseBll = new EnterpriseUserBLL();

            if (enterpriseBll.CheckLogin(enterpriseUser))
            {
                if (txtValidate.Text.ToUpper().Equals(Session["CheckCode"].ToString()))
                {
                    /*设置session变量username为用户名*/
                    Session["username"] = username;
                    Session["EuserID"] = enterpriseBll.GetEnterpriseIdByUser(username);
                    Session["usertype"] = "E";//E - 企业端,S-系统端,A-答题端
                    Session["userfullName"] = enterpriseBll.GetIncNameByUser(username);

                    Response.Redirect("~/Enterprise/ManageActivity.aspx");
                }
                else
                {
                    MessageBox.ShowAndRedirect(this, "您输入的验证码有误,请重新输入!", "EnterpriseLogin.aspx");
                }
            }
            else
            {
                MessageBox.ShowAndRedirect(this, "您输入的用户名称或者密码有误,请重新输入!", "EnterpriseLogin.aspx");
            }
        }
        private void load()
        {
            Model.EnterpriseUser account = (Model.EnterpriseUser)Session["Login"];
            RPCResult <List <Model.EnterpriseUser> > r = ZHSMSProxy.GetZKD().GetLowerEnterprises(account.AccountCode);
            DataTable dt = CreateTable();

            if (r.Success)
            {
                List <Model.EnterpriseUser> accounts = r.Value;
                if (accounts.Count > 0)
                {
                    foreach (Model.EnterpriseUser a in accounts)
                    {
                        DataRow dr = dt.NewRow();
                        dr["accountID"] = a.AccountID;
                        dr["code"]      = a.AccountCode;

                        dr["name"]    = a.Name;
                        dr["contact"] = a.Contact;
                        dr["phone"]   = a.Phone;
                        dr["address"] = a.Address;
                        dt.Rows.Add(dr);
                    }
                }

                GridView1.DataSource = dt;
                GridView1.DataBind();
                Session["dt"] = dt;
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int Add(EnterpriseUser model)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("insert into ExamDB.dbo.tb_EnterpriseUsers(");
            strSql.Append(@"users_name,
                            users_pwd,
                            users_incname,
                            users_contact,
                            users_phone,
                            users_address,
                            users_firstlogontime,
                            users_availablemoney,
                            users_totalconsumemoney)");

            strSql.Append(" values (");

            strSql.Append(@"@users_name,
                            @users_pwd,
                            @users_incname,
                            @users_contact,
                            @users_phone,
                            @users_address,
                            @users_firstlogontime,
                            @users_availablemoney,
                            @users_totalconsumemoney)");

            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@users_name", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_pwd", SqlDbType.NChar,255),
                    new SqlParameter("@users_incname", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_contact", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_phone",SqlDbType.NVarChar,255),
                    new SqlParameter("@users_address", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_firstlogontime", SqlDbType.DateTime),
                    new SqlParameter("@users_availablemoney", SqlDbType.Float),
                    new SqlParameter("@users_totalconsumemoney", SqlDbType.Float)
                                        };
            parameters[0].Value = model.Username;
            parameters[1].Value = Encrypt(model.Password);
            parameters[2].Value = model.Users_incname;
            parameters[3].Value = model.Users_contact;
            parameters[4].Value = model.Users_phone;
            parameters[5].Value = model.Users_address;
            parameters[6].Value = model.Users_firstlogon;
            parameters[7].Value = model.Users_availablemoney;
            parameters[8].Value = model.Users_totalconsumemoney;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
            if (obj == null)
            {
                return -1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        protected void btnChange_Click(object sender, EventArgs e)
        {
            EnterpriseUser temp = new EnterpriseUser();

            temp.Username = lblUserName.Text.Trim();
            temp.Users_incname = lblCoName.Text.Trim();
               // temp.Users_address = txtbAddress.Text.Trim();
            temp.Users_contact = txtbContact.Text.Trim();
            temp.Users_phone = txtbPhone.Text.Trim();
            temp.Users_scale = ddlCoScale.SelectedValue;
            temp.Users_type = ddlCoType.SelectedValue;

            if (m_EnterpriseUserBll.UpdateContact(temp) > 0)
            {
                MessageBox.ShowAndRedirect(this, "修改成功", "ManageActivity.aspx");
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<EnterpriseUser> GetModelList(string strWhere)
        {
            DataSet ds = EnterpriseUserDAL.GetListAll();
            List<EnterpriseUser> modelList = new List<EnterpriseUser>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                EnterpriseUser model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new EnterpriseUser();

                    //TODO: ADD MODEL
                    modelList.Add(model);
                }
            }
            return modelList;
        }
 /// <summary>
 /// 判断登录
 /// </summary>
 public bool CheckLogin(EnterpriseUser enterpriseUser)
 {
     return EnterpriseUserDAL.CheckLogin(enterpriseUser);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(EnterpriseUser model)
 {
     return EnterpriseUserDAL.Add(model);
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int UpdateContact(EnterpriseUser model)
 {
     return EnterpriseUserDAL.UpdateContact(model);
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int Update(EnterpriseUser model)
 {
     return  EnterpriseUserDAL.Update(model);
 }
        /// <summary>
        /// 判断登录
        /// </summary>
        public static bool CheckLogin(EnterpriseUser enterpriseUser)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ExamDB.dbo.tb_EnterpriseUsers");
            strSql.Append(" where users_name=@Username");
            strSql.Append(" and users_pwd=@Password");
            SqlParameter[] parameters ={
                   new SqlParameter("@Username",SqlDbType.VarChar,255),
                   new SqlParameter("@Password",SqlDbType.VarChar,255)};
            parameters[0].Value = enterpriseUser.Username;
            parameters[1].Value = Encrypt(enterpriseUser.Password);

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新联系信息
        /// </summary>
        public static int UpdateContact(EnterpriseUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ExamDB.dbo.tb_EnterpriseUsers set ");
            strSql.Append("users_incname=@users_incname,");
            strSql.Append("users_contact=@users_contact,");
            strSql.Append("users_phone=@users_phone,");
            strSql.Append("users_address=@users_address,");
            strSql.Append("users_type=@users_type,");
            strSql.Append("users_scale=@users_scale");
            strSql.Append(" where users_name=@users_name ");
            SqlParameter[] parameters = {
                    new SqlParameter("@users_incname", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_contact", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_phone", SqlDbType.NChar,255),
                    new SqlParameter("@users_address", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_type", SqlDbType.NVarChar,10),
                    new SqlParameter("@users_scale",SqlDbType.NVarChar,10),
                    new SqlParameter("@users_name", SqlDbType.NVarChar,255)};
            parameters[0].Value = model.Users_incname;
            parameters[1].Value = model.Users_contact;
            parameters[2].Value = model.Users_phone;
            parameters[3].Value = model.Users_address;
            parameters[4].Value = model.Users_type;
            parameters[5].Value = model.Users_scale;
            parameters[6].Value = model.Username;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static int Update(EnterpriseUser model)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("update ExamDB.dbo.tb_EnterpriseUsers set ");
            strSql.Append("users_name=@users_name,");
            strSql.Append("users_pwd=@users_pwd,");
            strSql.Append("users_incname=@users_incname,");
            strSql.Append("users_contact=@users_contact,");
            strSql.Append("users_phone=@users_phone,");
            strSql.Append("users_address=@users_address");
            strSql.Append(" where users_id=@users_id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@users_id", SqlDbType.Int,4),
                    new SqlParameter("@users_name", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_pwd", SqlDbType.NChar,255),
                    new SqlParameter("@users_incname", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_contact", SqlDbType.NVarChar,255),
                    new SqlParameter("@users_phone",SqlDbType.NVarChar,255),
                    new SqlParameter("@users_address", SqlDbType.NVarChar,255)};
            parameters[0].Value = model.Id;
            parameters[1].Value = model.Username;
            parameters[2].Value = Encrypt(model.Password);
            parameters[3].Value = model.Users_incname;
            parameters[4].Value = model.Users_contact;
            parameters[5].Value = model.Users_phone;
            parameters[6].Value = model.Users_address;

            return  DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static EnterpriseUser GetModel(int ID)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 * from ExamDB.dbo.tb_EnterpriseUsers");
            strSql.Append(" where users_id=@ID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            EnterpriseUser  model=new  EnterpriseUser();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if (ds.Tables[0].Rows[0]["users_id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["users_id"].ToString());
                }

                model.Username = ds.Tables[0].Rows[0]["users_name"].ToString();
                model.Password = ds.Tables[0].Rows[0]["users_pwd"].ToString();
                model.Users_incname=ds.Tables[0].Rows[0]["users_incname"].ToString();
                model.Users_contact = ds.Tables[0].Rows[0]["users_contact"].ToString();
                model.Users_phone = ds.Tables[0].Rows[0]["users_phone"].ToString();
                model.Users_address = ds.Tables[0].Rows[0]["users_address"].ToString();
                model.Users_availablemoney = float.Parse(ds.Tables[0].Rows[0]["users_availablemoney"].ToString());
                if (ds.Tables[0].Rows[0]["users_firstlogontime"].ToString() != "")
                {
                    model.Users_firstlogon = DateTime.Parse(ds.Tables[0].Rows[0]["users_firstlogontime"].ToString());
                }

                model.Users_totalconsumemoney = float.Parse(ds.Tables[0].Rows[0]["users_totalconsumemoney"].ToString());
                model.Users_scale = ds.Tables[0].Rows[0]["users_scale"].ToString();
                model.Users_type = ds.Tables[0].Rows[0]["users_type"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int userId = 0;

            if (Request.QueryString["users_id"] != null)
            {
                userId = int.Parse(Request.QueryString["users_id"]);
            }

            // *验证用户输入的信息*/
            if (string.IsNullOrEmpty(UserName.Text))
            {
                MessageBox.ResponseScript(this, "您好,请填写用户名!");
            }
            if (string.IsNullOrEmpty(Password.Text))
            {
                MessageBox.ResponseScript(this, "您好,请填写密码!");
            }
            if (string.IsNullOrEmpty(CompanyName.Text))
            {
                MessageBox.ResponseScript(this, "您好,请填写公司名称!");
            }

            EnterpriseUserBLL enterpriseUserBll = new EnterpriseUserBLL();
            EnterpriseUser enterpriseUser = new EnterpriseUser();
            if (0 == userId)
            {
                if (enterpriseUserBll.Exists(UserName.Text.Trim().ToLower()))
                {
                    MessageBox.ShowAndRedirect(this, "用户添加失败:此用户名已存在", "AddEnterpriseUser.aspx");
                    return;
                }
                enterpriseUser.Username = UserName.Text.Trim().ToLower();
                enterpriseUser.Users_incname = CompanyName.Text.Trim();
                enterpriseUser.Password = Password.Text.Trim().ToLower();
                enterpriseUser.Users_phone = txtbPhone.Text.Trim();
                enterpriseUser.Users_contact = txtbContact.Text.Trim();

                if (enterpriseUserBll.Add(enterpriseUser) != -1)
                {
                    MessageBox.ShowAndRedirect(this, "企业用户添加成功", "EnterpriseUserList.aspx");
                }
                else
                {
                    MessageBox.ShowAndRedirect(this, "企业用户添加失败", "EnterpriseUserList.aspx");
                }
            }
            else
            {
                enterpriseUser.Id = userId;
                enterpriseUser.Username = UserName.Text.Trim();
                enterpriseUser.Users_incname = CompanyName.Text.Trim();
                enterpriseUser.Password = Password.Text.Trim();
                enterpriseUser.Users_phone = txtbPhone.Text.Trim();
                enterpriseUser.Users_contact = txtbContact.Text.Trim();
                if (enterpriseUserBll.Update(enterpriseUser) == 1)
                {
                    MessageBox.ShowAndRedirect(this, "企业用户修改成功", "EnterpriseUserList.aspx");
                }
                else
                {
                    MessageBox.ShowAndRedirect(this, "企业用户修改失败", "EnterpriseUserList.aspx");
                }
            }
        }