/// <summary> /// 添加,修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { if (btnUpdate.Text == "添加") { RoomType model = new RoomType(); model.Rt_Name = txtName.Value.Trim(); model.Rt_Price = Convert.ToDecimal(txtPrice.Value.Trim()); model.Rt_Note = txtNote.Value.Trim(); if (RoomTypeBLL.AddRoomType(model) > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');window.location.replace('RoomTypeManage.aspx');</script>"); return; } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!');</script>"); return; } } else { RoomType model = RoomTypeBLL.GetIdByRoomType(Convert.ToInt32(Request.QueryString["id"])); model.Rt_Name = txtName.Value.Trim(); model.Rt_Price = Convert.ToDecimal(txtPrice.Value.Trim()); model.Rt_Note = txtNote.Value.Trim(); if (RoomTypeBLL.UpdateRoomType(model) > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.location.replace('RoomTypeManage.aspx');</script>"); return; } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>"); return; } } }
/// <summary> /// 添加房间类型 /// </summary> private void AddRoomType() { RoomTypeBLL rtBll = new RoomTypeBLL(); RoomTypeBean rtb = new RoomTypeBean(); //得到表单提交的值 rtb.TypeName = Request.Form["TypeName"]; rtb.TypePrice = double.Parse(Request.Form["TypePrice"].ToString()); rtb.IsTv = Request.Form["IsTv"]; rtb.IsKongTiao = Request.Form["IsKongTiao"]; rtb.Remark = Request.Form["remark"]; string json; //如果success为true,则表示服务器端处理成功 if (rtBll.AddRoomType(rtb)) { json = @"{success: true}"; } else { json = @"{success: false}"; } Response.Write(json); }
//保存 private void toolStripButton3_Click(object sender, EventArgs e) { if (this.txtTypeName.Text.Trim().Length == 0) { MessageBox.Show("房间类型名称不能为空!", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTypeName.Focus(); return; } if (this.txtTypePrice.Text.Trim().Length == 0) { MessageBox.Show("房间价格不能为空!", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTypePrice.Focus(); return; } if (!CheckNum.CheckStringIsNum(this.txtTypePrice.Text.Trim())) { MessageBox.Show("您的输入有误,房间价格必须为数字类型!", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTypePrice.Clear(); this.txtTypePrice.Focus(); return; } if (Convert.ToDecimal(this.txtTypePrice.Text.Trim()) <= 0) { MessageBox.Show("房间价格必须大于0!", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTypePrice.Clear(); this.txtTypePrice.Focus(); return; } //根据新增或修改分开操作 //修改 if (this.FormType == "修改") { if (!Checkdgv()) { return; } if (this.dgvRoomTypes.CurrentRow.DataBoundItem == null) { return; } int typeId = (this.dgvRoomTypes.CurrentRow.DataBoundItem as RoomType).TypeID; RoomType rt = new RoomType( typeId, this.txtTypeName.Text.Trim(), Convert.ToDecimal(this.txtTypePrice.Text.Trim()) ); try { RoomTypeBLL.UpdateRoomType(rt); ShowRoomTypes(); ExeuceTextReanOnly(); this.tsmiSave.Enabled = false; this.tsmiAdd.Enabled = true; } catch (Exception ex) { MessageBox.Show("修改房间类型出现异常\n" + ex.Message, "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); } } //新增 else if (this.FormType == "新建") { RoomType rt = new RoomType( this.txtTypeName.Text.Trim(), Convert.ToDecimal(this.txtTypePrice.Text.Trim()) ); try { RoomTypeBLL.AddRoomType(rt); ShowRoomTypes(); ExeuceTextReanOnly(); this.tsmiSave.Enabled = false; this.tsmiUpdate.Enabled = true; } catch (Exception ex) { MessageBox.Show("新增房间类型出现异常\n" + ex.Message, "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }