private void btnAdd_Click(object sender, EventArgs e) { ManagerInfo mi = new ManagerInfo(); mi.MName = textBox2.Text; mi.MPwd = textBox3.Text; mi.MType = rbManager.Checked ? 1 : 0; if (TXT.Text.Equals("添加时无编号")) { //判断出是在添加还是修改保存 if (miBll.Add(mi)) { MessageBox.Show("添加成功!"); LoadList(); } else { MessageBox.Show("添加失败,请稍候重试!"); } } else { mi.MId = Convert.ToInt32(TXT.Text); if (miBll.Edit(mi)) { LoadList(); } } textBox2.Text = ""; textBox3.Text = ""; TXT.Text = "添加时无编号"; rbWaiter.Checked = true; }
private void btnSave_Click(object sender, EventArgs e) { var mi = new ManagerInfo { MName = txtName.Text, MPwd = txtPwd.Text, MType = radioMa.Checked ? 1 : 0 }; if (btnSave.Text == "添加") { if (miBll.Add(mi)) { LoadList(); btnCancel_Click(null, null); } else { MessageBox.Show("添加失败"); } } if (btnSave.Text == "修改") { mi.Mid = Convert.ToInt32(txtId.Text); if (miBll.Edit(mi)) { LoadList(); btnCancel_Click(null, null); } else { MessageBox.Show("修改失败"); } } }
private void btnSave_Click(object sender, EventArgs e) { ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked ? 1 : 0 }; if (txtId.Text.Equals("No ID")) { if (miBll.Add(mi)) { LoadList(); } else { MessageBox.Show("Failed"); } } else { mi.Mid = int.Parse(txtId.Text); if (miBll.Edit(mi)) { LoadList(); } } txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; btnSave.Text = "Add"; txtId.Text = "No ID"; }
private void btnSave_Click(object sender, EventArgs e) { //判断输入有效性 if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("请输入用户名"); txtName.Focus(); return; } if (string.IsNullOrWhiteSpace(txtPwd.Text)) { MessageBox.Show("请输入密码"); txtPwd.Focus(); return; } //接收用户输入 ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked ? 1 : 0 //经理值为1,店员值为0 }; if (txtId.Text.Equals("添加时无编号")) { #region 添加 //调用bll的Add方法 if (miBll.Add(mi)) { //如果添加成功,则重新加载数据 LoadList(); } else { MessageBox.Show("添加失败,请稍候重试"); } #endregion } else { #region 修改 mi.MId = int.Parse(txtId.Text); if (miBll.Edit(mi)) { LoadList(); } #endregion } //清除文本框 txtName.Text = ""; txtPwd.Text = ""; txtId.Text = "添加时无编号"; rb2.Checked = true; btnSave.Text = "添加"; }
/// <summary> /// Save /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (txtName.Text == "" && txtPwd.Text == "") { label6.Text = "Tips: User name and password cannot be empty."; return; } //Create an new manager by input ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked ? 1 : 0 //1 for Manager, 0 for Clerk }; if (txtId.Text.Equals("The number is empty.")) { #region Add //Call add method in Dal if (miBll.Add(mi)) { LoadList(); } else { MessageBox.Show("Failed to add an item"); } #endregion } else { #region Update mi.MId = int.Parse(txtId.Text); if (miBll.Edit(mi)) { LoadList(); } #endregion } //Clear the value in from txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; btnSave.Text = "Add"; txtId.Text = "The number is empty."; }
private void btnSave_Click(object sender, EventArgs e) { ManagerInfo miInfo = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked ? 1 : 0 }; if (txtId.Text.Equals("添加时无编号")) { #region add if (bll.Add(miInfo)) { LoadList(); txtPwd.Text = ""; txtName.Text = ""; rb2.Checked = true; } else { MessageBox.Show("添加失败,请检查数据"); } #endregion } else { #region edit miInfo.MId = int.Parse(txtId.Text); if (bll.Edit(miInfo)) { LoadList(); } #endregion } txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; btnSave.Text = "添加"; txtId.Text = "添加时无编号"; }
/// <summary> /// 添加或修改管理员 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { ManagerInfo mi = new ManagerInfo() { Mname = txtName.Text, Mpwd = txtPwd.Text, Mtype = rb1.Checked ? 1 : 0, }; if (btnSave.Text == "添加") { if (miBll.Add(mi)) { LoadList(); txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; } else { MessageBox.Show("添加失败"); } } else if (btnSave.Text == "修改") { mi.Mid = Convert.ToInt32(txtId.Text); if (miBll.Edit(mi)) { LoadList(); txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; txtId.Text = "添加时无编号"; btnSave.Text = "添加"; } else { MessageBox.Show("修改失败"); } } }
private void btnSave_Click(object sender, EventArgs e) { //接受用户输入 ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked ? 1 : 0//经理值为1,店员值为0 }; if (txtId.Text.Equals("添加时无编号")) { #region 添加 if (miBll.Add(mi)) { MessageBox.Show("添加成功."); LoadList(); } else { MessageBox.Show("添加失败,请稍后再试......"); } #endregion } else { #region 修改 mi.MId = int.Parse(txtId.Text); if (miBll.Edit(mi)) { MessageBox.Show("添加成功."); LoadList(); } else { MessageBox.Show("修改失败,请稍后再试......"); } } #endregion CleanText(); }
private void btnSave_Click(object sender, EventArgs e) { //接收控件的值,用于构造对象 ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, MPwd = txtPwd.Text, MType = rb1.Checked?1:0 }; //判断当前是要进行添加操作,还是要进行修改操作 if (btnSave.Text == "添加") { //调用执行添加,如果成功则刷新,失败则提示 if (miBll.Add(mi)) { btnCancel_Click(null, null); LoadList(); } else { MessageBox.Show("添加失败,请稍候重试"); } } else { //如果是修改,则需要指定主键 mi.Mid = Convert.ToInt32(txtId.Text); //调用执行修改,如果成功则刷新,失败则提示 if (miBll.Edit(mi)) { btnCancel_Click(null, null); LoadList(); } else { MessageBox.Show("修改失败,请稍候重试"); } } }
private void btnSave_Click(object sender, EventArgs e) { ManagerInfo mi = new ManagerInfo() { MName = txtName.Text, Mpwd = txtPwd.Text, Mtype = rb1.Checked ? 1 : 0//经理值为1,店员值为0 }; if (txtId.Text.Equals("添加时无编号")) { //添加 //调用bll的Add方法 if (miBll.Add(mi)) { //如果添加成功,则重新加载数据 LoadList(); } else { MessageBox.Show("添加失败,请稍后重试"); } } else { //修改 mi.MId = int.Parse(txtId.Text); if (miBll.Edit(mi)) { LoadList(); } } //清除文本框中的值 txtName.Text = ""; txtPwd.Text = ""; rb2.Checked = true; btnSave.Text = "添加"; txtId.Text = "添加时无编号"; }
//添加操作 private void button1_Click(object sender, EventArgs e) { //接收控件的值,用于构造对象 ManagerInfo mi = new ManagerInfo() { MName = textBox1.Text, MPwd = textBox2.Text, MType = radioButton1.Checked ? 1 : 0 }; //判断当前是要进行添加操作,还是要进行修改操作 if (button1.Text == "添加") { if (miBll.Add(mi)) { button2_Click(null, null); LoadList(); MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败,请重试!!!"); } } else { mi.MId = Convert.ToInt32(textBox3.Text); if (miBll.Edit(mi)) { LoadList(); MessageBox.Show("修改成功"); } else { MessageBox.Show("修改失败,请稍后重试!!!"); } } }