コード例 #1
0
ファイル: Add.aspx.cs プロジェクト: dalinhuang/labms
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbUserName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "用户名不能为空!");
                tbUserName.Focus();
                return;
            }
            else if (string.IsNullOrEmpty(tbRealName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "真实姓名不能为空!");
                tbRealName.Focus();
                return;
            }
            else if (string.IsNullOrEmpty(tbPassword.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "密码不能为空!");
                tbPassword.Focus();
                return;
            }
            else
            {
                if (!EBut.IsExistUserName(tbUserName.Text.Trim()))//用户名已经存在,不能注册
                {
                    Common.JShelper.JSAlert(this.Page, "", "用户名已经存在!");
                    tbUserName.Text = "";
                    tbUserName.Focus();
                    return;
                }
                else
                {
                    //往用户表里添加信息
                    LabMS.Model.UserTable Mut = new LabMS.Model.UserTable();
                    DataSet ds = new DataSet();
                    Mut.CreateTime = DateTime.Now;

                    Mut.UserName = tbUserName.Text.Trim();
                    Mut.Password = tbPassword.Text.Trim();
                    Mut.PCode = tb.Text.Trim();
                    ds = EBut.GetTeacherByPCode(tb.Text.Trim());
                    //Mut.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                    //Mut.Tel = ds.Tables[0].Rows[0]["Tel"].ToString();
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["Staff_Birth"].ToString()))
                    {
                        DateTime d1 = DateTime.Parse(ds.Tables[0].Rows[0]["Staff_Birth"].ToString());
                        DateTime d2 = DateTime.Now;
                        Mut.Age = d2.Year - d1.Year;
                    }

                    Mut.SexCode = ds.Tables[0].Rows[0]["Staff_Sex"].ToString();

                    LabMS.BLL.UserTable But = new LabMS.BLL.UserTable();
                    hiddenAddUserID.Value=But.Add(Mut).ToString();
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增用户成功!');window.location.href='UserDefault.aspx';</script>");
                    AddRole.Visible = true;//显示“添加角色按钮”
                    PanRole.Visible = true;
                }
            }
        }