protected void btn_Save_Click(object sender, ImageClickEventArgs e) { if (this.ddlRoomType.SelectedValue == "") { MessageBox.Show(this.upDepartAdd, this, "请选择磅房类型!"); return; } else if (this.ddlRoomType.SelectedValue == "1") { if (this.ddlCollieryID.SelectedValue == "0") { MessageBox.Show(this.upDepartAdd, this, "请选择磅房所属煤矿!"); return; } } else if (this.ddlVillageCode.SelectedValue == "") { MessageBox.Show(this.upDepartAdd,this,"请选择所属乡镇"); return; } string strOldIP =""; //判断磅房编码的唯一性 if (Request.QueryString["RoomCode"] == null) { if (bll.ExistRoomIP(this.txtRoomIp.Text.Trim(), "")) { MessageBox.Show(this.upDepartAdd, this, "您输入的磅房IP已经存在,请重新输入"); this.txtRoomIp.Focus(); return; } model.IsForbid = "0"; //磅房添加默认是启用的 } else { if (bll.ExistRoomIP(this.txtRoomIp.Text.Trim(), Request.QueryString["RoomCode"].ToString())) { MessageBox.Show(this.upDepartAdd, this, "您输入的磅房IP已经存在,请重新输入"); this.txtRoomIp.Focus(); return; } model = bll.GetModel(Request.QueryString["RoomCode"].ToString()); strOldIP = model.RoomIp; } //绑定数据 model.RoomName = this.txtRoomName.Text; model.Principal = this.txtPrincipal.Text; model.Telephone = this.txtTelephone.Text; model.TransportModel = ""; model.RoomIp = this.txtRoomIp.Text; model.Remark = this.txtRemark.Text; model.VillageCode = ddlVillageCode.SelectedValue; model.CollCode = ddlCollieryID.SelectedValue.Trim(); model.RoomType = this.ddlRoomType.SelectedValue; //执行语句 if (Request.QueryString["RoomCode"] != null) { if (bll.ExistName(txtRoomName.Text, Request.QueryString["RoomCode"].ToString())) { MessageBox.Show(this.upDepartAdd, this, "您输入的磅房名称已经存在请重新输入"); return; } if (bll.Update(model) == 1) //修改成功不用提示,直接关闭 { #region 数据同步 try { //数据同步到各个磅房 //StringBuilder strSql = new StringBuilder(); //strSql.Append("update TT_Room set "); //strSql.Append("VillageCode='"+model.VillageCode+"',"); //strSql.Append("RoomName='"+model.RoomName+"',"); //strSql.Append("Principal='"+model.Principal+"',"); //strSql.Append("Telephone='"+model.Telephone+"',"); //strSql.Append("TransportModel='"+model.TransportModel+"',"); //strSql.Append("RoomType='" + model.RoomType + "',"); //strSql.Append("RoomIp='" + model.RoomIp + "',"); //strSql.Append("IsForbid='" + model.IsForbid + "',"); //strSql.Append("Remark='" + model.Remark + "',"); //strSql.Append("CollCode='" + model.CollCode + "'"); //strSql.Append(" where RoomCode='"+model.RoomCode+"'"); //string strMq = mq.AllStation + mq.Prefix + "TT_Room" + mq.Prefix + mq.EditFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + mq.Prefix + strSql.ToString(); //mq.AddMsmq(strMq.ToString());禁用了消息队列 } catch { } #endregion ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "top.currForm.close();", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "alert('修改失败!');", true); } } else//新增保存 { if (bll.ExistName(txtRoomName.Text.Trim(), "")) { MessageBox.Show(this.upDepartAdd, this, "您输入的磅房名称已经存在请重新输入"); return; } lock (this) { model.RoomCode = DbHelperSQL.GetBaseMaxID("RoomCode", "TT_Room", "RoomCode<>'0'"); if (bll.Add(model) == 1) { #region 数据同步 //StringBuilder strSql = new StringBuilder(); //strSql.Append("insert into TT_ROOM("); //strSql.Append("RoomCode,VillageCode,RoomName,Principal,Telephone,TransportModel,RoomType,RoomIp,IsForbid,Remark,CollCode)");; //strSql.Append(" values ("); //strSql.Append("'" + model.RoomCode + "','" + model.VillageCode + "','" + model.RoomName + "','" + model.Principal + "','" + model.Telephone + "','" + model.TransportModel + "','"+model.RoomType+"','"+model.RoomIp+"','"+model.IsForbid+"','"+model.Remark+"','"+model.CollCode+"')"); //string strMq = mq.AllStation + mq.Prefix + "TT_Room" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + mq.Prefix + strSql.ToString(); //mq.AddMsmq(strMq.ToString());禁用了消息队列 #endregion ShowInfo(); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "alert('添加失败!');", true); } } } }
private void ShowInfo() { if (Request.QueryString["RoomCode"] != null) { model = bll.GetModel(Request.QueryString["RoomCode"].ToString()); //this.txtRoomCode.Text = model.RoomCode; this.txtRoomName.Text = model.RoomName; this.txtPrincipal.Text = model.Principal; this.txtTelephone.Text = model.Telephone; this.txtRoomIp.Text = model.RoomIp; this.txtRemark.Text = model.Remark; ddlVillageCode.SelectedValue = model.VillageCode; this.ddlRoomType.SelectedValue = model.RoomType; hf_roomname.Value = model.RoomName; if (this.ddlRoomType.SelectedValue == "1") { this.ddlCollieryID.Enabled = true; this.ddlCollieryID.SelectedValue = model.CollCode; this.lblCollStar.Visible = true; } //this.ddlIsForbid.SelectedValue = model.IsForbid; //this.txtRoomCode.Enabled = false; } else { //this.txtRoomCode.Text = ""; this.txtRoomName.Text = ""; this.txtPrincipal.Text = ""; this.txtTelephone.Text = ""; this.ddlRoomType.SelectedValue = ""; this.txtRoomIp.Text = ""; this.txtRemark.Text = ""; ddlVillageCode.SelectedValue = ""; ddlCollieryID.SelectedValue = "0"; this.ddlCollieryID.Enabled = false; this.lblCollStar.Visible = false; } }