protected void btn_Save_Click(object sender, ImageClickEventArgs e) { if (Request.QueryString["strCoalKindCode"] == null) { model.IsForbid = "0"; if (bll.ExistsCoalKindName(this.txtCoalKindName.Text.Trim(), "")) { MessageBox.Show(this.upDepartAdd, this, "您输入的煤种名称已经存在,请重新输入"); return; } } else { model = bll.GetModel(Request.QueryString["strCoalKindCode"].ToString()); if (bll.ExistsCoalKindName(this.txtCoalKindName.Text.Trim(), Request.QueryString["strCoalKindCode"].ToString())) { MessageBox.Show(this.upDepartAdd, this, "您输入的煤种名称已经存在,请重新输入"); return; } } //绑定数据 model.CoalKindName = txtCoalKindName.Text.Trim(); if (txtProportion.Text.Trim() == "") txtProportion.Text = "0"; model.Proportion = Convert.ToDecimal(txtProportion.Text.Trim().Replace(" ","")); model.TypeCode = ddlInOut.SelectedValue; model.Remark = txtRemark.Text.Trim(); model.TaxPercent = Convert.ToDecimal(txtTaxPercent.Text.Trim().Replace(" ", "")); TDTK.IndustryPlatform.CoalTraffic.DBUtility.MsmqManage msm = new TDTK.IndustryPlatform.CoalTraffic.DBUtility.MsmqManage(); //执行语句 if (Request.QueryString["strCoalKindCode"] != null) { if (bll.Update(model) == 1) //修改成功不用提示,直接关闭 { #region 数据同步 StringBuilder strSql = new StringBuilder(); strSql.Append("update TT_CoalKind set "); strSql.Append("CoalKindName='"+model.CoalKindName+"',"); strSql.Append("Proportion='"+model.Proportion+"',"); strSql.Append("TypeCode='" + model.TypeCode + "',"); strSql.Append("Remark='"+model.Remark+"',"); strSql.Append("TaxPercent='"+model.TaxPercent+"',"); strSql.Append("IsForbid='"+model.IsForbid+"'"); strSql.Append(" where CoalKindCode='"+model.CoalKindCode+"' "); string strMq = msm.AllStation + msm.Prefix + "TT_CoalKind" + msm.Prefix + msm.EditFlg + msm.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + msm.Prefix + strSql.ToString(); msm.AddMsmq(strMq); #endregion ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "top.currForm.close();", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "alert('修改失败!');", true); } } else//新增保存 { lock (this) { string strSQL = "Select Max(CoalKindCode) From TT_CoalKind Where CoalKindCode Like '" + ddlInOut.SelectedValue + "%'"; string strCode = ddlInOut.SelectedValue + "001"; object objID= DbHelperSQL.GetSingle(strSQL); if (objID != null) { strCode = (Convert.ToInt32(objID)+1).ToString(); } model.CoalKindCode = strCode; // model.CoalKindCode = DbHelperSQL.GetBaseMaxID("CoalKindCode", "TT_CoalKind"); if (bll.Add(model) == 1) { ShowInfo(); #region 数据同步 //添加成功,数据同步到各个磅房 string strSql = "insert into TT_CoalKind(CoalKindCode,CoalKindName,Proportion,TypeCode,Remark,IsForbid,TaxPercent)" + "Values('" + model.CoalKindCode + "','" + model.CoalKindName + "','" + model.Proportion + "','" + model.TypeCode + "','" + model.Remark + "','" + model.IsForbid + "','"+model.TaxPercent+"')"; string strMq = msm.AllStation + msm.Prefix + "TT_CoalKind" + msm.Prefix + msm.AddFlg + msm.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + msm.Prefix + strSql.ToString(); msm.AddMsmq(strMq); #endregion } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "alert('添加失败!');", true); } } } }
private void ShowInfo() { if (Request.QueryString["strCoalKindCode"] != null) { model = bll.GetModel(Request.QueryString["strCoalKindCode"].ToString()); if (model != null) { this.txtCoalKindName.Text = model.CoalKindName; this.txtProportion.Text = Convert.ToString(model.Proportion); this.ddlInOut.SelectedValue = model.TypeCode; this.txtRemark.Text = model.Remark; this.ddlIsForbid.SelectedValue = model.IsForbid; this.txtTaxPercent.Text = model.TaxPercent.ToString(); } } else { this.txtCoalKindName.Text = ""; this.txtProportion.Text = ""; this.ddlInOut.SelectedValue = "1"; this.txtRemark.Text = ""; this.ddlIsForbid.SelectedValue = "0"; this.txtTaxPercent.Text = "100"; } }