Example #1
0
        public void AddOpers(Opers op)
        {
            string sql = "INSERT INTO `Opers`(`operID`,`operName`,`operSex`,`operPws`,`operPos`)VALUES (@operID,@operName,@operSex,@operPws,@operPos)";
            DbUtil.ExecuteNonQuery(sql,
                new MySqlParameter("@operID", op.operID),
                new MySqlParameter("@operName", op.operName),
                new MySqlParameter("@operSex", op.operSex),
                new MySqlParameter("@operPws", op.operPws),
                new MySqlParameter("@operPos", op.operPos));

            foreach (string s in op.openGrantRigts)
            {
                sql = "insert into OpersRights(operid,rightsName) values (@operid,@rightsName)";
                DbUtil.ExecuteNonQuery(sql, new MySqlParameter("@operid", op.id), new MySqlParameter("@rightsName",s));
            }
        }
Example #2
0
        private void lbOK_Click(object sender, EventArgs e)
        {
            string openID = tbOpenID.Text.Trim();
            string openName = tbOperName.Text.Trim();
            string openPos = cbOperPos.Text;
            string openSex = cbOperSex.Text;
            string openPwd = tbOperPwd.Text.Trim();
            if (openName == "" || openID == "")
            {
                MessageBox.Show("登录名和用户名不能为空");
                return;
            }
            if (lbOK.Text.Equals("增加"))
            {
                try
                {
                    Opers op = new Opers();
                    op.operID = openID;
                    op.operName = openName;
                    op.operPos = openPos;
                    op.operSex = openSex;
                    op.operPws = openPwd;
                    OpersService service = new OpersService();
                    List<string> grantRights = new List<string>();
                    for (int i = 0; i < lxGrant.Items.Count; i++)
                    {
                        grantRights.Add(lxGrant.Items[i].ToString());
                    }
                    op.openGrantRigts = grantRights;
                    service.AddOpers(op);
                    MessageBox.Show("新增操作员成功");
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            else
            {
                OpersService service = new OpersService();
                Opers op = service.GetOpersByID(id);
                op.operID = openID;
                op.operName = openName;
                op.operPos = openPos;
                op.operSex = openSex;
                op.operPws = openPwd;
                List<string> grantRights = new List<string>();
                for (int i = 0; i < lxGrant.Items.Count; i++)
                {
                    grantRights.Add(lxGrant.Items[i].ToString());
                }
                op.openGrantRigts = grantRights;
                service.UpdateOpers(op);
                MessageBox.Show("修改操作员成功");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
Example #3
0
        public void UpdateOpers(Opers op)
        {
            string sql = "UPDATE `Opers` SET `operID` = @operID,`operName` = @operName,`operSex` = @operSex,`operPws` = @operPws,`operPos` = @operPos WHERE `id` = @id";
            DbUtil.ExecuteNonQuery(sql,
                new MySqlParameter("@operID", op.operID),
                new MySqlParameter("@operName", op.operName),
                new MySqlParameter("@operSex", op.operSex),
                new MySqlParameter("@operPws", op.operPws),
                new MySqlParameter("@operPos", op.operPos),
                new MySqlParameter("@id", op.id));

            sql = "delete from OpersRights where operid = @operid";
            DbUtil.ExecuteNonQuery(sql,new MySqlParameter("@operid",op.id));

            foreach (string s in op.openGrantRigts)
            {
                sql = "insert into OpersRights(operid,rightsName) values (@operid,@rightsName)";
                DbUtil.ExecuteNonQuery(sql, new MySqlParameter("@operid", op.id), new MySqlParameter("@rightsName", s));
            }
        }
Example #4
0
 public Opers ToOpers(DataRow row)
 {
     Opers op = new Opers();
     op.id = (int)row["id"];
     op.operID = (string)row["operID"];
     op.operName = (string)row["operName"];
     op.operPos = (string)row["operPos"];
     op.operPws = (string)row["operPws"];
     op.operSex = (string)row["operSex"];
     return op;
 }