Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listPermission.Count == 0 || this.listUserID.Count == 0)
                {
                    return;
                }

                string permissions = "";
                int    number      = 0;

                Dictionary <string, string> dictAttribute = new Dictionary <string, string>();

                foreach (var permission in this.listPermission)
                {
                    permissions += permission + ",";
                }

                dictAttribute.Add("permissions", permissions.Substring(0, permissions.Length - 1));

                foreach (var userID in this.listUserID)
                {
                    if (XmlFile.UpdateXmlNode(Global.UsersConfigPath, userID, dictAttribute))
                    {
                        number++;
                    }
                }

                if (number == this.listUserID.Count)
                {
                    MessageBox.Show("保存成功。");
                }
                else
                {
                    dictAttribute.Clear();

                    dictAttribute.Add("permissions", "");

                    foreach (var userID in this.listUserID)
                    {
                        XmlFile.UpdateXmlNode(Global.UsersConfigPath, userID, dictAttribute);
                    }

                    MessageBox.Show("保存失败。");
                }
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtOrgPassword.Text.Trim() == "")
                {
                    MessageBox.Show("旧密码不能为空,请输入。");
                    this.txtOrgPassword.Focus();
                    return;
                }

                if (this.txtNewPassword.Text.Trim() == "")
                {
                    MessageBox.Show("新密码不能为空,请输入。");
                    this.txtNewPassword.Focus();
                    return;
                }

                if (this.txtOrgPassword.Text != Global.Password)
                {
                    MessageBox.Show("旧密码输入错误");
                    this.txtOrgPassword.Text = "";
                    this.txtOrgPassword.Focus();
                    return;
                }

                if (MessageBox.Show("确定修改密码吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    Dictionary <string, string> dictAttribute = new Dictionary <string, string>();

                    dictAttribute.Add("password", this.txtNewPassword.Text);

                    var userID = Global.UserID;

                    if (XmlFile.UpdateXmlNode(Global.UsersConfigPath, userID, dictAttribute))
                    {
                        Global.Password          = this.txtNewPassword.Text;
                        this.txtNewPassword.Text = "";
                        this.txtOrgPassword.Text = "";
                        MessageBox.Show("修改成功。");
                    }
                    else
                    {
                        MessageBox.Show("修改失败。");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
            }
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtWorkNumber.Text.Trim() == "")
                {
                    MessageBox.Show("工号不能为空,请输入。");
                    this.txtWorkNumber.Focus();
                    return;
                }

                if (this.txtWorkNumber.Text.ToLower() == "admin")
                {
                    MessageBox.Show("工号不能为[admin],请重新输入。");
                    this.txtWorkNumber.Text = "";
                    this.txtWorkNumber.Focus();
                    return;
                }

                if (this.txtName.Text.Trim() == "")
                {
                    MessageBox.Show("姓名不能为空,请输入。");
                    this.txtName.Focus();
                    return;
                }

                if (this.txtName.Text.ToLower() == "admin")
                {
                    MessageBox.Show("姓名不能为[admin],请重新输入。");
                    this.txtName.Text = "";
                    this.txtName.Focus();
                    return;
                }

                var userName   = this.txtName.Text;
                var workNumber = this.txtWorkNumber.Text;
                var dept       = this.cbbDept.SelectedIndex != -1 ? this.cbbDept.SelectedItem.ToString() : "";

                if (this.isAdd)
                {
                    DataRow[] row = Global.DtUser.Select(string.Format("workNumber = '{0}'", this.txtWorkNumber.Text));

                    if (row.Length > 0)
                    {
                        MessageBox.Show("此工号已经存在,请重新输入。");
                        this.txtWorkNumber.Text = "";
                        this.txtWorkNumber.Focus();
                        return;
                    }

                    var id = Guid.NewGuid().ToString();

                    DataRow dr = Global.DtUser.NewRow();
                    dr["id"]          = id;
                    dr["userName"]    = this.txtName.Text;
                    dr["workNumber"]  = this.txtWorkNumber.Text;
                    dr["dept"]        = this.cbbDept.SelectedItem.ToString();
                    dr["password"]    = "******";
                    dr["permissions"] = "";

                    Global.DtUser.Rows.Add(dr);

                    if (XmlFile.AddXmlNode(Global.UsersConfigPath, dr))
                    {
                        MessageBox.Show("添加成功。");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加失败。");
                    }
                }
                else
                {
                    var id = this.dgvRow.Cells["id"].Value.ToString();

                    DataRow[] dr = Global.DtUser.Select(string.Format("id = '{0}'", id));

                    if (dr.Length > 0)
                    {
                        dr[0]["userName"]   = this.txtName.Text;
                        dr[0]["workNumber"] = this.txtWorkNumber.Text;
                        dr[0]["dept"]       = this.cbbDept.SelectedItem.ToString();
                    }

                    Dictionary <string, string> dictAttribute = new Dictionary <string, string>();

                    dictAttribute.Add("dept", dr[0]["dept"].ToString());
                    dictAttribute.Add("userName", dr[0]["userName"].ToString());

                    var userID = dr[0]["id"].ToString();

                    if (XmlFile.UpdateXmlNode(Global.UsersConfigPath, userID, dictAttribute))
                    {
                        MessageBox.Show("修改成功。");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("修改失败。");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
            }
        }