Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BookShop.Model.Employee model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Employee set ");
            strSql.Append("empPassword=@empPassword,");
            strSql.Append("empName=@empName,");
            strSql.Append("sex=@sex,");
            strSql.Append("birthday=@birthday,");
            strSql.Append("department=@department,");
            strSql.Append("title=@title,");
            strSql.Append("salary=@salary,");
            strSql.Append("address=@address,");
            strSql.Append("telephone=@telephone,");
            strSql.Append("email=@email");
            strSql.Append(" where employeeNo=@employeeNo ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@empPassword", SqlDbType.VarChar,   10),
                new SqlParameter("@empName",     SqlDbType.VarChar,   12),
                new SqlParameter("@sex",         SqlDbType.Char,       1),
                new SqlParameter("@birthday",    SqlDbType.DateTime),
                new SqlParameter("@department",  SqlDbType.VarChar,   30),
                new SqlParameter("@title",       SqlDbType.VarChar,   10),
                new SqlParameter("@salary",      SqlDbType.Decimal,    9),
                new SqlParameter("@address",     SqlDbType.VarChar,   40),
                new SqlParameter("@telephone",   SqlDbType.VarChar,   15),
                new SqlParameter("@email",       SqlDbType.VarChar,   20),
                new SqlParameter("@employeeNo",  SqlDbType.Char, 8)
            };
            parameters[0].Value  = model.empPassword;
            parameters[1].Value  = model.empName;
            parameters[2].Value  = model.sex;
            parameters[3].Value  = model.birthday;
            parameters[4].Value  = model.department;
            parameters[5].Value  = model.title;
            parameters[6].Value  = model.salary;
            parameters[7].Value  = model.address;
            parameters[8].Value  = model.telephone;
            parameters[9].Value  = model.email;
            parameters[10].Value = model.employeeNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.Employee DataRowToModel(DataRow row)
 {
     BookShop.Model.Employee model = new BookShop.Model.Employee();
     if (row != null)
     {
         if (row["employeeNo"] != null)
         {
             model.employeeNo = row["employeeNo"].ToString();
         }
         if (row["empPassword"] != null)
         {
             model.empPassword = row["empPassword"].ToString();
         }
         if (row["empName"] != null)
         {
             model.empName = row["empName"].ToString();
         }
         if (row["sex"] != null)
         {
             model.sex = row["sex"].ToString();
         }
         if (row["birthday"] != null && row["birthday"].ToString() != "")
         {
             model.birthday = DateTime.Parse(row["birthday"].ToString());
         }
         if (row["department"] != null)
         {
             model.department = row["department"].ToString();
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["salary"] != null && row["salary"].ToString() != "")
         {
             model.salary = decimal.Parse(row["salary"].ToString());
         }
         if (row["address"] != null)
         {
             model.address = row["address"].ToString();
         }
         if (row["telephone"] != null)
         {
             model.telephone = row["telephone"].ToString();
         }
         if (row["email"] != null)
         {
             model.email = row["email"].ToString();
         }
     }
     return(model);
 }
Exemplo n.º 3
0
 private void ShowInfo(string employeeNo)
 {
     BookShop.BLL.Employee   bll   = new BookShop.BLL.Employee();
     BookShop.Model.Employee model = bll.GetModel(employeeNo);
     this.lblemployeeNo.Text  = model.employeeNo;
     this.lblempPassword.Text = model.empPassword;
     this.lblempName.Text     = model.empName;
     this.lblsex.Text         = model.sex;
     this.lblbirthday.Text    = model.birthday.ToString();
     this.lbldepartment.Text  = model.department;
     this.lbltitle.Text       = model.title;
     this.lblsalary.Text      = model.salary.ToString();
     this.lbladdress.Text     = model.address;
     this.lbltelephone.Text   = model.telephone;
     this.lblemail.Text       = model.email;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(BookShop.Model.Employee model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Employee(");
            strSql.Append("employeeNo,empPassword,empName,sex,birthday,department,title,salary,address,telephone,email)");
            strSql.Append(" values (");
            strSql.Append("@employeeNo,@empPassword,@empName,@sex,@birthday,@department,@title,@salary,@address,@telephone,@email)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@employeeNo",  SqlDbType.Char,       8),
                new SqlParameter("@empPassword", SqlDbType.VarChar,   10),
                new SqlParameter("@empName",     SqlDbType.VarChar,   12),
                new SqlParameter("@sex",         SqlDbType.Char,       1),
                new SqlParameter("@birthday",    SqlDbType.DateTime),
                new SqlParameter("@department",  SqlDbType.VarChar,   30),
                new SqlParameter("@title",       SqlDbType.VarChar,   10),
                new SqlParameter("@salary",      SqlDbType.Decimal,    9),
                new SqlParameter("@address",     SqlDbType.VarChar,   40),
                new SqlParameter("@telephone",   SqlDbType.VarChar,   15),
                new SqlParameter("@email",       SqlDbType.VarChar, 20)
            };
            parameters[0].Value  = model.employeeNo;
            parameters[1].Value  = model.empPassword;
            parameters[2].Value  = model.empName;
            parameters[3].Value  = model.sex;
            parameters[4].Value  = model.birthday;
            parameters[5].Value  = model.department;
            parameters[6].Value  = model.title;
            parameters[7].Value  = model.salary;
            parameters[8].Value  = model.address;
            parameters[9].Value  = model.telephone;
            parameters[10].Value = model.email;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Employee GetModel(string employeeNo)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 employeeNo,empPassword,empName,sex,birthday,department,title,salary,address,telephone,email from Employee ");
            strSql.Append(" where employeeNo=@employeeNo ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@employeeNo", SqlDbType.Char, 8)
            };
            parameters[0].Value = employeeNo;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtempPassword.Text.Trim().Length == 0)
            {
                strErr += "empPassword不能为空!\\n";
            }
            if (this.txtempName.Text.Trim().Length == 0)
            {
                strErr += "empName不能为空!\\n";
            }
            if (this.txtsex.Text.Trim().Length == 0)
            {
                strErr += "sex不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtbirthday.Text))
            {
                strErr += "birthday格式错误!\\n";
            }
            if (this.txtdepartment.Text.Trim().Length == 0)
            {
                strErr += "department不能为空!\\n";
            }
            if (this.txttitle.Text.Trim().Length == 0)
            {
                strErr += "title不能为空!\\n";
            }
            if (!PageValidate.IsDecimal(txtsalary.Text))
            {
                strErr += "salary格式错误!\\n";
            }
            if (this.txtaddress.Text.Trim().Length == 0)
            {
                strErr += "address不能为空!\\n";
            }
            if (this.txttelephone.Text.Trim().Length == 0)
            {
                strErr += "telephone不能为空!\\n";
            }
            if (this.txtemail.Text.Trim().Length == 0)
            {
                strErr += "email不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   employeeNo  = this.lblemployeeNo.Text;
            string   empPassword = this.txtempPassword.Text;
            string   empName     = this.txtempName.Text;
            string   sex         = this.txtsex.Text;
            DateTime birthday    = DateTime.Parse(this.txtbirthday.Text);
            string   department  = this.txtdepartment.Text;
            string   title       = this.txttitle.Text;
            decimal  salary      = decimal.Parse(this.txtsalary.Text);
            string   address     = this.txtaddress.Text;
            string   telephone   = this.txttelephone.Text;
            string   email       = this.txtemail.Text;


            BookShop.Model.Employee model = new BookShop.Model.Employee();
            model.employeeNo  = employeeNo;
            model.empPassword = empPassword;
            model.empName     = empName;
            model.sex         = sex;
            model.birthday    = birthday;
            model.department  = department;
            model.title       = title;
            model.salary      = salary;
            model.address     = address;
            model.telephone   = telephone;
            model.email       = email;

            BookShop.BLL.Employee bll = new BookShop.BLL.Employee();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }