private void button1_Click(object sender, RoutedEventArgs e)
        {
            //using (TransactionScope ts = new TransactionScope())
            //{
            //    DepartmentDAL deptDal = new DepartmentDAL();
            //    deptDal.Insert("aaa");
            //    deptDal.Insert("fffffffffffffffffffffffffff");
            //    test2();//嵌套事务
            //    throw new Exception();

            //    ts.Complete();
            //}

            using (TransactionScope ts = new TransactionScope())
            {
                DepartmentDAL dal = new DepartmentDAL();
                dal.Insert("测试1");

                //EmployeeDAL employeeDAl = new EmployeeDAL();
                //Employee emp = new Employee();
                //emp.
                //employeeDAl.Insert(emp);
                Operator op = new Operator();
                op.UserName = "******";
                op.Password = "******";
                op.RealName = "haha";
                new OperatorDAL().Insert(op);

                ts.Complete();
            }
        }
示例#2
0
 public Operator[] ListAll()
 {
     DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Operator where IsDeleted=0");
     Operator[] operators = new  Operator[dt.Rows.Count];
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         operators[i] = ToOperator(dt.Rows[i]);
     }
     return operators;
 }
示例#3
0
 public void Insert(Operator op)
 {
     //bit类型,在sql语句中要写0、1
     //在.net中要用bool表示
     SqlHelper.ExecuteNonQuery(@"insert into T_Operator(
         Id,UserName,Password,IsDeleted,RealName,IsLocked) values(newid(),@UserName,@Password,0,@RealName,0)",
             new SqlParameter("@UserName", op.UserName),
             new SqlParameter("@Password", op.Password),
             new SqlParameter("@RealName", op.RealName));
 }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (IsInsert)
            {
                Operator op = new Operator();
                op.RealName = txtRealName.Text;
                op.UserName = txtUserName.Text;
                op.Password = CommonHelper.GetMD5(pwdPassword.Password+CommonHelper.GetPasswordSalt());
                new OperatorDAL().Insert(op);

                Guid operatorId = CommonHelper.GetOperatorId();
                new T_OperationLogDAL().Insert(operatorId, "新增操作员" + txtUserName.Text);

                DialogResult = true;
            }
            else
            {
                string pwd = pwdPassword.Password;
                if (pwd.Length <= 0)//编辑的时候如果密码为空,则保留现有密码不动
                {
                    //new OperatorDAL().Update(EditingId,
                    //    txtUserName.Text, txtRealName.Text);
                    new OperatorDAL().Update(EditingId,
                        null, txtRealName.Text);
                }
                else//如果密码不为空,则把密码重置为用户输入的密码
                {
                    string pwdMd5 = CommonHelper.GetMD5(pwd + CommonHelper.GetPasswordSalt());
                    new OperatorDAL().Update(EditingId,
                        txtUserName.Text, txtRealName.Text, pwdMd5);

                }
                Guid operatorId = CommonHelper.GetOperatorId();
                new T_OperationLogDAL().Insert(operatorId, "修改操作员" + txtUserName.Text);
                DialogResult = true;
            }
        }
示例#5
0
 private Operator ToOperator(DataRow row)
 {
     Operator op = new Operator();
     op.Id = (Guid)row["Id"];
     op.UserName = (string)row["UserName"];
     op.Password = (string)row["Password"];
     op.IsDeleted = (bool)row["IsDeleted"];
     op.RealName = (string)row["RealName"];
     op.IsLocked = (bool)row["IsLocked"];
     return op;
 }