Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //校验数据
                CheckContent();
                bool        result;
                UserManager userManager;
                //判断是新增 or 修改
                if (this.Owner is UserManager)
                {
                    userManager = (UserManager)this.Owner;
                    if (userManager.flag.Equals("1"))
                    {
                        userTable            = new ScanDataSet.UserInfoDataTable();
                        userInfoRow          = userTable.NewUserInfoRow();
                        userInfoRow.usercode = this.tbUserCode.Text.Trim();

                        userInfoRow.username = this.tbUserName.Text.Trim();
                        userInfoRow.password = this.tbUserPassWord.Text.Trim();
                        userInfoRow.forgid   = ((UserManager)this.Owner).orgID;
                        userInfoRow.frcode   = ((UserManager)this.Owner).frcode;
                        userInfoRow.site     = this.tbSite.Text.Trim();
                        string status = "";
                        if (this.startRadioButton.Checked)
                        {
                            status = "1";
                        }

                        if (this.forbidRadioButton.Checked)
                        {
                            status = "0";
                        }
                        userInfoRow.status = status;

                        userTable.AddUserInfoRow(userInfoRow);
                        result = new Business.UserInfo().AddUser(userTable);
                    }
                    else if (userManager.flag.Equals("2"))
                    {
                        ScanDataSet scandataset = new Business.UserInfo().GetUserByID(userManager.userID);
                        if (scandataset.UserInfo.Rows.Count > 0)
                        {
                            userTable = scandataset.UserInfo;
                            userRow   = scandataset.UserInfo.Rows[0];

                            userRow["usercode"] = this.tbUserCode.Text.Trim();
                            userRow["username"] = this.tbUserName.Text.Trim();
                            userRow["password"] = this.tbUserPassWord.Text.Trim();
                            userRow["forgid"]   = ((UserManager)this.Owner).orgID;
                            userRow["frcode"]   = Util.Util.GetAppSetting("rcode").ToString();
                            userRow["site"]     = this.tbSite.Text.Trim();
                            string status = "";
                            if (this.startRadioButton.Checked)
                            {
                                status = "1";
                            }

                            if (this.forbidRadioButton.Checked)
                            {
                                status = "0";
                            }
                            userRow["status"] = status;

                            if (!String.IsNullOrEmpty(((UserManager)this.Owner).userID))
                            {
                                userRow["id"] = ((UserManager)this.Owner).userID;
                            }
                            result = new Business.UserInfo().AddUser(userTable);
                        }
                        else
                        {
                            MessageBox.Show("获取用户信息错误!");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("获取业务标记错误!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("获取父窗口错误!");
                    return;
                }



                if (result)
                {
                    MessageBox.Show("保存成功!");
                    userManager.searchData();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("保存失败!");

                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }