using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using MES.Service.Modes; using Newtonsoft.Json; using System; using System.Data; using System.Text; namespace Gs.DevApp.DevFrm.QC { public partial class Frm_MesDefectCodeShow : DevExpress.XtraEditors.XtraForm { string strGuid = ""; string strUpGuid = ""; string strType = "";//信息的分类s_type string _webServiceName = "MesDefectCodeManager/"; /// /// /// /// 主键 /// 父亲主键 /// 类别 public Frm_MesDefectCodeShow(string _strGuid, string _strUpGuid, string _strType) { InitializeComponent(); this.strGuid = _strGuid; this.strUpGuid = _strUpGuid; this.strType = _strType; getSelect(); //这是更新,禁止类型和编号 if (!string.IsNullOrEmpty(this.strGuid)) { getMode(strGuid); this.Text = "更新【" + txt_defectName.Text + "】"; txt_sType.Enabled = false; txt_defectCode.ReadOnly = true; return; } //这是增加子项,需要初始化它的编号 if (!string.IsNullOrEmpty(strUpGuid)) { getMode(strUpGuid); this.Text = "增加【" + txt_defectName.Text + "】的子项目"; txt_sType.Enabled = false; txt_defectCode.ReadOnly = false; txt_defectName.Text = ""; return; } this.Text = "增加新项"; } /// /// 保存 /// /// /// private void btnQuery_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_defectCode.Text)) { Gs.DevApp.ToolBox.MsgHelper.ShowInformation("编号不能为空!"); txt_defectCode.Focus(); return; } if (txt_sType.SelectedIndex <= 0) { Gs.DevApp.ToolBox.MsgHelper.ShowInformation("类型不能为空!"); txt_sType.Focus(); return; } if (string.IsNullOrEmpty(txt_defectName.Text)) { Gs.DevApp.ToolBox.MsgHelper.ShowInformation("名称不能为空!"); txt_defectName.Focus(); return; } var _obj = new MesDefectCode() { Guid = UtilityHelper.ToGuid(strGuid.Trim()), DefectCode = txt_defectCode.Text.Trim(), SType = txt_sType.Text.Trim(), DefectName = txt_defectName.Text.Trim(), Pid = UtilityHelper.ToGuid(strUpGuid.Trim()), Type1 = txt_type1.Checked, DefectSort = strType, }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { UpdateParent?.Invoke(this, new UpdateParentEventArgs { StringSingle = "" }); Close(); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } private void btnEsc_Click(object sender, EventArgs e) { this.Close(); } /// /// 回调事件 /// public event EventHandler UpdateParent; /// /// 读取上级 /// private void getSelect() { System.Text.StringBuilder sbWhere = new StringBuilder(); sbWhere.Append(" and a.defect_sort='" + strType + "'"); var _obj = new { strWhere = sbWhere.ToString() }; var strReturn = UtilityHelper.HttpPost("", _webServiceName + "SelectCategory", JsonConvert.SerializeObject(_obj)); var dd = UtilityHelper.ReturnToList(strReturn); var dt = dd.rtnData; txt_sType.Properties.Items.Add("-请选择-"); txt_sType.SelectedIndex = 0; foreach (DataRow dr in dt.Rows) { txt_sType.Properties.Items.Add(dr["typeMemo"].ToString()); } } /// /// 读取实体 /// /// private void getMode(string guid) { var _obj = new { guid = guid,//主建 }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, true); if(string.IsNullOrEmpty(strGuid)) txt_defectCode.Text = dy.maxNo; } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } } }