Exemple #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public IndustryPlatform.Model.SYS_OperatorEntity GetModel(string UserCode)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserCode,UserName,Password,IsForbid,OrgCode,Tel,Email,Address,ZipCode,PID,Gender,RegDate,MobileNo,TypeCode from Sys_Operator ");
            strSql.Append(" where UserCode=@UserCode ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserCode", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = UserCode;

            IndustryPlatform.Model.SYS_OperatorEntity model = new IndustryPlatform.Model.SYS_OperatorEntity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString();
                model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                model.Password = ds.Tables[0].Rows[0]["Password"].ToString();
                model.IsForbid = ds.Tables[0].Rows[0]["IsForbid"].ToString();
                model.OrgCode  = ds.Tables[0].Rows[0]["OrgCode"].ToString();
                model.Tel      = ds.Tables[0].Rows[0]["Tel"].ToString();
                model.Email    = ds.Tables[0].Rows[0]["Email"].ToString();
                model.Address  = ds.Tables[0].Rows[0]["Address"].ToString();
                model.ZipCode  = ds.Tables[0].Rows[0]["ZipCode"].ToString();
                model.PID      = ds.Tables[0].Rows[0]["PID"].ToString();
                model.Gender   = ds.Tables[0].Rows[0]["Gender"].ToString();
                if (ds.Tables[0].Rows[0]["RegDate"].ToString() != "")
                {
                    model.RegDate = DateTime.Parse(ds.Tables[0].Rows[0]["RegDate"].ToString());
                }
                model.MobileNo = ds.Tables[0].Rows[0]["MobileNo"].ToString();
                model.TypeCode = ds.Tables[0].Rows[0]["TypeCode"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
        public int AddOperator(SYS_OperatorEntity operEntity)
        {
            try
            {

                SqlParameter[] parm = new SqlParameter[]{};
                SetParameterValue(operEntity, out parm);
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into Sys_Operator(");
                strSql.Append("UserCode,UserName,Password,IsForbid,OrgCode,Tel,Email,Address,ZipCode,PID,Gender,RegDate,MobileNo,TypeCode)");
                strSql.Append(" values (");
                strSql.Append("@UserCode,@UserName,@Password,@IsForbid,@OrgCode,@Tel,@Email,@Address,@ZipCode,@PID,@Gender,@RegDate,@MobileNo,@TypeCode)");

                int op = DbHelperSQL.ExecuteSql(strSql.ToString(), parm);
                return op;
            }
            catch
            {
                return 0;
            }
        }
 public int UpdateOperator(SYS_OperatorEntity operEntity)
 {
     return dal.UpdateOperator(operEntity);
 }
 public int AddOperator(SYS_OperatorEntity operEntity)
 {
     return dal.AddOperator(operEntity);
 }
    protected void ib_save_Click(object sender, ImageClickEventArgs e)
    {
        lock (this)
        {
            if (CookieManager.GetCookieValue("uid").ToString() == "0" && this.ddl_parentOrgID.SelectedIndex == 0)
            {
               // MessageBox.Show(this, "请选择部门");
                MessageBox.Show(this.UpdatePanel1, this, "请选择部门");
                return;
            }
            if (this.ddl_TypeCode.Visible == true && this.ddl_TypeCode.Items[0].Text == "请选择磅房")
            {
                if (this.ddl_TypeCode.SelectedValue == "")
                {
                    //MessageBox.Show(this, ddl_TypeCode.Items[0].Text);
                    MessageBox.Show(this.UpdatePanel1, this, ddl_TypeCode.Items[0].Text);
                    return;
                }
            }
            int checkid = operbll.Ch(this.txt_username.Text.ToString());

            if (checkid == 1)
            {
                //MessageBox.Show(this, "您输入的用户姓名已经存在,请重新输入!");
                MessageBox.Show(this.UpdatePanel1, this, "您输入的用户姓名已经存在,请重新输入!");
                return;
            }
            SYS_OperatorEntity operEntity = new SYS_OperatorEntity();
            operEntity.Gender = this.rblist_sex.SelectedValue.ToString();
            operEntity.Address = this.txt_address.Text.ToString();
            operEntity.IsForbid = "0";
            operEntity.MobileNo = this.txt_mobile.Text.ToString();
            operEntity.Email = this.txt_email.Text.ToString();
            operEntity.UserCode = DbHelperSQL.GetBaseMaxID("UserCode", "Sys_Operator", "UserCode<>'0'").ToString();
            operEntity.OrgCode = this.ddl_parentOrgID.SelectedValue;
            //operEntity.TypeCode = this.ddl_TypeCode.SelectedValue;
            operEntity.Password = CommonMethod.MD5Crypt("12345");
            operEntity.PID = this.txt_pid.Text.ToString();
            operEntity.RegDate = Convert.ToDateTime(System.DateTime.Now);
            operEntity.UserName = this.txt_username.Text.ToString();
            operEntity.Tel = this.txt_tel.Text;
            if (ddl_TypeCode.Visible)
            {
                operEntity.TypeCode = this.ddl_TypeCode.SelectedValue;
            }
            else
            {
                operEntity.TypeCode = "0";
            }
            operEntity.ZipCode = this.zipcode.Text.ToString();
            int isign = operbll.AddOperator(operEntity);
            if (isign == 1)
            {
                #region 数据同步

                if (ConfigurationManager.AppSettings["IsSync"] == "1")
                {
                    try
                    {
                        IndustryPlatform.DBUtility.MsmqManage msm =  MsmqManage.GetMsmq();
                        string strSQL = "INSERT INTO Sys_Operator ( " +
                            "[UserCode] ," +
                            "[UserName] ," +
                            "[Password] ," +
                            "[IsForbid] ," +
                            "[OrgCode] ," +
                            "[Tel] ," +
                            "[Email] ," +
                            "[Address] ," +
                            "[ZipCode] ," +
                            "[PID] ," +
                            "[Gender] ," +
                            "[RegDate] ," +
                            "[MobileNo] ," +
                            "[TypeCode] ) VALUES ('" + operEntity.UserCode + "','" + CommonMethod.RepChar(operEntity.UserName) +
                             "','" + CommonMethod.RepChar(operEntity.Password) + "','" + operEntity.IsForbid +
                             "','" + operEntity.OrgCode + "','" + operEntity.Tel + "','" + operEntity.Email +
                             "','" + CommonMethod.RepChar(operEntity.Address) + "','" + operEntity.ZipCode + "','" + operEntity.PID +
                             "','" + operEntity.Gender + "','" + operEntity.RegDate +
                             "','" + operEntity.MobileNo + "','" + operEntity.TypeCode + "')";
                        strSQL = msm.AllStation + msm.Prefix + "Sys_Operator" + msm.Prefix + msm.AddFlg + msm.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + msm.Prefix + strSQL;
                        msm.AddMsmq(strSQL);

                        //向考勤机发送同步数据
                        if (System.Configuration.ConfigurationManager.AppSettings["ConnKQIP"].ToString() != "")
                        {
                            string kqSql = "INSERT INTO [HMKQ].[dbo].[员工]" +
                                   "([员工编号]" +
                                   ",[姓名]" +
                                //",[虹膜代码]"+
                                //",[虹膜代码2]"+
                                //",[虹膜代码3]"+
                                   ",[密码]" +
                                   ",[部门]" +
                                //",[组别]"+
                                //",[自定义编号]"+
                                   ",[管理权]" +
                                   ",[黑名单])" +
                                //",[照片])"+
                                   " VALUES" +
                                   "('" + operEntity.UserCode + "','" + operEntity.UserName + "','" + CommonMethod.RepChar(operEntity.Password) + "','" + operEntity.OrgCode + "',0,0)";
                            msm.AddMsmq(kqSql, System.Configuration.ConfigurationManager.AppSettings["ConnKQIP"].ToString());//语句,IP
                        }
                    }
                    catch
                    { }
                }
                #endregion

                setnull();
                //MessageBox.Show(this, "添加成功!");
                MessageBox.Show(this.UpdatePanel1, this, "添加成功!");
            }
            else
            {
                 //MessageBox.Show(this, "添加失败!");
               MessageBox.Show(this.UpdatePanel1, this, "添加失败!");
            }
        }
    }
 public int UpdateOperator(SYS_OperatorEntity operEntity)
 {
     try
     {
         StringBuilder strSql = new StringBuilder();
         strSql.Append("update Sys_Operator set ");
         strSql.Append("UserName=@UserName,");
         strSql.Append("Password=@Password,");
         strSql.Append("IsForbid=@IsForbid,");
         strSql.Append("OrgCode=@OrgCode,");
         strSql.Append("Tel=@Tel,");
         strSql.Append("Email=@Email,");
         strSql.Append("Address=@Address,");
         strSql.Append("ZipCode=@ZipCode,");
         strSql.Append("PID=@PID,");
         strSql.Append("Gender=@Gender,");
         strSql.Append("RegDate=@RegDate,");
         strSql.Append("MobileNo=@MobileNo,");
         strSql.Append("TypeCode=@TypeCode");
         strSql.Append(" where UserCode=@UserCode ");
         SqlParameter[] parm = new SqlParameter[] { };
         SetParameterValue(operEntity,out parm);
         int op = DbHelperSQL.ExecuteSql(strSql.ToString(), parm);
         return op;
     }
     catch
     {
         return 0;
     }
 }
        public void SetParameterValue(SYS_OperatorEntity model, out SqlParameter[] sqlParm)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@UserCode", SqlDbType.VarChar,10),
                    new SqlParameter("@UserName", SqlDbType.NVarChar,20),
                    new SqlParameter("@Password", SqlDbType.NVarChar,50),
                    new SqlParameter("@IsForbid", SqlDbType.VarChar,1),
                    new SqlParameter("@OrgCode", SqlDbType.VarChar,10),
                    new SqlParameter("@Tel", SqlDbType.NVarChar,20),
                    new SqlParameter("@Email", SqlDbType.NVarChar,100),
                    new SqlParameter("@Address", SqlDbType.NVarChar,200),
                    new SqlParameter("@ZipCode", SqlDbType.VarChar,10),
                    new SqlParameter("@PID", SqlDbType.VarChar,18),
                    new SqlParameter("@Gender", SqlDbType.NVarChar,2),
                    new SqlParameter("@RegDate", SqlDbType.DateTime),
                    new SqlParameter("@MobileNo", SqlDbType.NVarChar,20),
                    new SqlParameter("@TypeCode", SqlDbType.VarChar,10)};

            parameters[0].Value = model.UserCode;
            parameters[1].Value = model.UserName;
            parameters[2].Value = model.Password;
            parameters[3].Value = model.IsForbid;
            parameters[4].Value = model.OrgCode;
            parameters[5].Value = model.Tel;
            parameters[6].Value = model.Email;
            parameters[7].Value = model.Address;
            parameters[8].Value = model.ZipCode;
            parameters[9].Value = model.PID;
            parameters[10].Value = model.Gender;
            parameters[11].Value = model.RegDate;
            parameters[12].Value = model.MobileNo;
            parameters[13].Value = model.TypeCode;

            sqlParm= parameters;
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public IndustryPlatform.Model.SYS_OperatorEntity GetModel(string UserCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 UserCode,UserName,Password,IsForbid,OrgCode,Tel,Email,Address,ZipCode,PID,Gender,RegDate,MobileNo,TypeCode from Sys_Operator ");
            strSql.Append(" where UserCode=@UserCode ");
            SqlParameter[] parameters = {
                    new SqlParameter("@UserCode", SqlDbType.VarChar,50)};
            parameters[0].Value = UserCode;

            IndustryPlatform.Model.SYS_OperatorEntity model = new IndustryPlatform.Model.SYS_OperatorEntity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString();
                model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                model.Password = ds.Tables[0].Rows[0]["Password"].ToString();
                model.IsForbid = ds.Tables[0].Rows[0]["IsForbid"].ToString();
                model.OrgCode = ds.Tables[0].Rows[0]["OrgCode"].ToString();
                model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString();
                model.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                model.ZipCode = ds.Tables[0].Rows[0]["ZipCode"].ToString();
                model.PID = ds.Tables[0].Rows[0]["PID"].ToString();
                model.Gender = ds.Tables[0].Rows[0]["Gender"].ToString();
                if (ds.Tables[0].Rows[0]["RegDate"].ToString() != "")
                {
                    model.RegDate = DateTime.Parse(ds.Tables[0].Rows[0]["RegDate"].ToString());
                }
                model.MobileNo = ds.Tables[0].Rows[0]["MobileNo"].ToString();
                model.TypeCode = ds.Tables[0].Rows[0]["TypeCode"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
    protected void ib_save_Click(object sender, ImageClickEventArgs e)
    {
        if (CookieManager.GetCookieValue("uid").ToString()=="0" && this.ddl_parentOrgID.SelectedIndex == 0)
        {
            MessageBox.Show(this.UpdatePanel1,this, "请选择部门");
            return;
        }
        if (this.ddl_TypeCode.Visible == true)
        {
            if (this.ddl_TypeCode.SelectedValue == "")
            {
                MessageBox.Show(this.UpdatePanel1, this, this.ddl_TypeCode.Items[0].Text);
                return;
            }
        }

        if (DbHelperSQL.Exists("Select Count(0) from Sys_Operator where UserName='******'", "''") + "' and UserCode<>'" + Request.QueryString["operid"].ToString() + "'"))
        {
            MessageBox.Show(this.UpdatePanel1, this, "您输入的用户名已经存在!");
            return;
        }
        SYS_OperatorEntity operEntity = new SYS_OperatorEntity();
        operEntity = operbll.GetModel(Request.QueryString["operid"].ToString());

        operEntity.Gender = this.rblist_sex.SelectedValue.ToString();
        operEntity.Address = this.txt_address.Text.ToString();
        operEntity.MobileNo = this.txt_mobile.Text.ToString();
        operEntity.Email = this.txt_email.Text.ToString();
        //operEntity. = Convert.ToDecimal(operbll.GetMaxID("operatorID", "SYS_Operator"));
        operEntity.OrgCode = this.ddl_parentOrgID.SelectedValue;
        operEntity.TypeCode = this.ddl_TypeCode.SelectedValue;
        operEntity.PID = this.txt_pid.Text.ToString();
        operEntity.RegDate = Convert.ToDateTime(System.DateTime.Now);
        operEntity.UserName = this.txt_username.Text.ToString();
        operEntity.Tel = this.txt_tel.Text;

        if (ddl_TypeCode.Visible)
        {
            operEntity.TypeCode = this.ddl_TypeCode.SelectedValue;
        }
        else
        {
            operEntity.TypeCode = "0";
        }
        operEntity.ZipCode = this.zipcode.Text.ToString();
        int isign = operbll.UpdateOperator(operEntity);
        if (isign == 1)
        {
            //MessageBox.Show(this, "修改成功!");
            #region 数据同步

            if (ConfigurationManager.AppSettings["IsSync"] == "1")
            {
                try
                {
                    IndustryPlatform.DBUtility.MsmqManage msm =  MsmqManage.GetMsmq();
                    string strSQL = "Update Sys_Operator set "+
                        "[UserCode] = '" + operEntity.UserCode + "', " +
                        "[UserName] =  '" + CommonMethod.RepChar(operEntity.UserName) + "', " +
                        "[Password] = '" + CommonMethod.RepChar(operEntity.Password) + "', " +
                        "[IsForbid] = '" + operEntity.IsForbid + "', " +
                        "[OrgCode] = '" + operEntity.OrgCode + "', " +
                        "[Tel] = '" + operEntity.Tel + "', " +
                        "[Email] = '" + operEntity.Email + "' ," +
                        "[Address] = '" + CommonMethod.RepChar(operEntity.Address) + "', " +
                        "[ZipCode] = '" + operEntity.ZipCode + "', " +
                        "[PID] = '" + operEntity.PID + "', " +
                        "[Gender] = '" + operEntity.Gender + "', " +
                        "[RegDate] = '" + operEntity.RegDate + "', " +
                        "[MobileNo] = '" + operEntity.MobileNo + "', " +
                        "[TypeCode] = '" + operEntity.TypeCode +"' "+
                        " where [UserCode]='" + CommonMethod.RepChar(operEntity.UserCode) + "'";
                    strSQL = msm.AllStation + msm.Prefix + "Sys_Operator" + msm.Prefix + msm.EditFlg + msm.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + msm.Prefix + strSQL;
                    msm.AddMsmq(strSQL);

                    //向考勤机发送更新语句
                    if (System.Configuration.ConfigurationManager.AppSettings["ConnKQIP"].ToString() != null)
                    {
                        string strKQSQL = "UPDATE [HMKQ].[dbo].[员工]" +
                        "SET [姓名] = '" + operEntity.UserName + "'" +
                           " ,[密码] = '" + CommonMethod.RepChar(operEntity.Password) + "'" +
                            ",[部门] = '" + operEntity.OrgCode + "'" +
                       "WHERE [员工编号]='" + operEntity.UserCode + "'";
                        msm.AddMsmq(strKQSQL, System.Configuration.ConfigurationManager.AppSettings["ConnKQIP"].ToString());
                    }
                }
                catch
                { }
            }
            #endregion

            ScriptManager.RegisterStartupScript(this.UpdatePanel1,Page.GetType(), "", "top.currForm.close();", true);
        }
        else
        {
            MessageBox.Show(this.UpdatePanel1, this, "修改失败!");
        }
    }