| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinGrid;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.Qcm
- {
- public partial class FrmComMscPhyStdNote : FrmBase
- {
- public FrmComMscPhyStdNote()
- {
- InitializeComponent();
- // this.MaximizeBox = false;
- this.MinimizeBox = false;
- }
- private string pic; //理化标准索引号
- public string Pic
- {
- get { return pic; }
- set { pic = value; }
- }
- private string index; //理化标准索引号-序号
- public string Index
- {
- get { return index; }
- set { index = value; }
- }
- private string phyCode; //检验项代码
- public string PhyCode
- {
- get { return phyCode; }
- set { phyCode = value; }
- }
- private string phyName; //检验项名称
- public string PhyName
- {
- get { return phyName; }
- set { phyName = value; }
- }
- private OpeBase newOb; //ob对象
- public OpeBase NewOb
- {
- get { return newOb; }
- set { newOb = value; }
- }
- private string sResult;
- public string SResult
- {
- get { return sResult; }
- set { sResult = value; }
- }
- private string sResult2; //预留
- public string SResult2
- {
- get { return sResult2; }
- set { sResult2 = value; }
- }
- private string noteIndex;
- public string NoteIndex
- {
- get { return noteIndex; }
- set { noteIndex = value; }
- }
- private string stdMin;
- public string StdMin
- {
- get { return stdMin; }
- set { stdMin = value; }
- }
- private string stdGuid;
- public string StdGuid
- {
- get { return stdGuid; }
- set { stdGuid = value; }
- }
- private bool isCustAlphaPopup = false;
- public bool IsCustAlphaPopup
- {
- get { return isCustAlphaPopup; }
- set { isCustAlphaPopup = value; }
- }
- string stdDesc = "";
- private void FrmComMscPhyStdNote_Load(object sender, EventArgs e)
- {
- if (isCustAlphaPopup)
- {
- ultraToolbarsManager1.Tools["ButtonTool2"].SharedProps.Visible = false;
- ultraToolbarsManager1.Tools["ButtonTool5"].SharedProps.Visible = false;
- ultraGroupBox1.Visible = false;
- }
- DoQuery();
- }
- private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- if (e.Tool.Key.Equals("ButtonTool1")) //查询
- {
- DoQuery();
- }
- else if (e.Tool.Key.Equals("ButtonTool2")) //新增
- {
- DoAdd();
- }
- else if (e.Tool.Key.Equals("ButtonTool3")) //选择确定
- {
- DoChoose();
- }
- else if (e.Tool.Key.Equals("ButtonTool5")) //修改
- {
- DoUpdate();
- }
- else if (e.Tool.Key.Equals("ButtonTool6")) //关闭
- {
- if (MessageBox.Show("是否关闭本窗口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- return;
- this.Close();
- }
- }
- private void DoQuery()
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.doQuery", new object[] { this.PhyCode }, this.newOb);
- GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);
- //DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.queryGuid", new object[] { this.Pic, this.Index }, this.NewOb);
- //string strGuid = "";
- //if (dt1 != null && dt1.Rows.Count > 0)
- //{
- // strGuid = dt1.Rows[0][0].ToString();
- //}
- foreach (UltraGridRow row in ultraGrid1.Rows)
- {
- if (row.Cells["STD_DESC"].Value.ToString() == stdDesc)
- {
- row.Activate();
- break;
- }
- }
- if (stdGuid != "")
- {
- foreach (UltraGridRow row in ultraGrid1.Rows)
- {
- if (row.Cells["GUID"].Value.ToString() == stdGuid)
- {
- row.RowSelectorAppearance.BackColor = Color.Yellow;
- break;
- }
- }
- }
- stdDesc = "";
- }
- private void DoAdd()
- {
- if (GetData() == -1)
- {
- return;
- }
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isReapt", new object[] { ultraTextEditor2.Text.Trim(), this.PhyCode }, this.NewOb);
- if (dt != null && dt.Rows.Count > 0)
- {
- MessageUtil.ShowWarning("你输入的标准要求重复!");
- return;
- }
- stdDesc = ultraTextEditor2.Text.Trim();
- int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.doAdd", new object[] { parmList }, this.NewOb);
- if (count > 0)
- {
- MessageUtil.ShowTips("数据新增成功!");
- DoQuery();
- }
- }
- private void DoUpdate()
- {
- UltraGridRow ugr = ultraGrid1.ActiveRow;
- if (ugr == null)
- {
- MessageUtil.ShowWarning("请选择一条要修改的记录!");
- return;
- }
- if (GetData() == -1)
- {
- return;
- }
- //判断要修改的序号是否被组合。
- DataTable dtIndex = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isGrouped", new object[] { this.PhyCode }, this.NewOb);
- if (dtIndex != null && dtIndex.Rows.Count > 0)
- {
- string indexStr = dtIndex.Rows[0][0].ToString();
- if (indexStr != "")
- {
- indexStr = indexStr.Replace("AND", "{");
- indexStr = indexStr.Replace("OR", "}");
- string[] arrIndex = indexStr.Split(new char[] { '{', '}', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < arrIndex.Length; i++)
- {
- if (arrIndex[i].ToString() == ugr.Cells["INDEX_SEQ"].Value.ToString())
- {
- MessageUtil.ShowWarning("选择修改的标准说明已被用于组合新标准,无法修改!");
- return;
- }
- }
- }
- }
- //判断要修改的序号是否被引用。
- DataTable dtGuid = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isRefenced", new object[] { ugr.Cells["GUID"].Value.ToString() }, this.NewOb);
- if (dtGuid != null && dtGuid.Rows.Count > 0)
- {
- MessageUtil.ShowWarning("选择修改的标准说明已被引用,无法修改!");
- return;
- }
- //判断组合的序号是否包含了自身序号。
- if (ultraTextEditor3.Text != "")
- {
- string group = ultraTextEditor3.Text;
- group = group.Replace("AND", "{");
- group = group.Replace("OR", "}");
- string[] arrGroup = group.Split(new char[] { '{', '}', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < arrGroup.Length; i++)
- {
- if (arrGroup[i] == ugr.Cells["INDEX_SEQ"].Value.ToString())
- {
- MessageUtil.ShowWarning("标准组合不能引用自身!");
- return;
- }
- }
- }
- //判断修改的标准要求,或组合的标准要求是否重复。
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isReaptUpdate", new object[] { ultraTextEditor2.Text.Trim(), this.PhyCode, ugr.Cells["INDEX_SEQ"].Value.ToString() }, this.NewOb);
- if (dt != null && dt.Rows.Count > 0)
- {
- MessageUtil.ShowWarning("你输入的标准要求重复!");
- return;
- }
- stdDesc = ultraTextEditor2.Text.Trim();
- if (MessageBox.Show("是否确认修改数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- return;
- parmList.RemoveAt(parmList.Count - 1);
- parmList.Add(ugr.Cells["PHY_CODE"].Value.ToString());
- parmList.Add(ugr.Cells["INDEX_SEQ"].Value.ToString());
- int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.doUpdate", new object[] { parmList }, this.NewOb);
- if (count > 0)
- {
- MessageUtil.ShowTips("数据修改成功!");
- DoQuery();
- }
- }
- private void DoChoose()
- {
- UltraGridRow ugr = ultraGrid1.ActiveRow;
- if (ugr == null)
- {
- MessageUtil.ShowWarning("请选择一条需要关联的记录!");
- return;
- }
- if (MessageBox.Show("是否确认关联?是,请到理化标准界面保存关联结果,否则不做处理", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- NoteIndex = ugr.Cells["STD_DESC"].Value.ToString();
- StdGuid = ugr.Cells["GUID"].Value.ToString();
- this.Close();
- // ArrayList list = new ArrayList();
- // list.Add(ugr.Cells["GUID"].Value.ToString());
- // list.Add(ugr.Cells["STD_DESC"].Value.ToString());
- // list.Add(this.Pic);
- // list.Add(this.Index);
- // int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.updateMaterial", new object[] { list }, this.NewOb);
- // if (count > 0)
- // {
- // MessageUtil.ShowTips("关联成功!");
- // DoQuery();
- // }
- }
- ArrayList parmList = new ArrayList();
- private int GetData()
- {
- parmList.Clear();
- bool isChecked = ultraCheckEditor1.Checked;
- if (isChecked == false && ultraTextEditor2.Text.Trim() == "" && ultraTextEditor3.Text.Trim() == "")
- {
- MessageUtil.ShowWarning("请输入标准要求!");
- return -1;
- }
- //标准组合序号---
- if (ultraCheckEditor1.Checked)
- {
- if (ultraTextEditor3.Text.Trim() == "")
- {
- MessageUtil.ShowWarning("请选择标准组合!");
- return -1;
- }
- }
- if (ultraTextEditor3.Text.Trim() != "")
- {
- string str = ultraTextEditor3.Text;
- str = str.Replace("AND", "+");
- str = str.Replace("OR", "-");
- //组合是否合乎数学公式性
- if (!TestFormula(str))
- {
- MessageUtil.ShowWarning("标准组合不合法!");
- return -1;
- }
- //组合的项目是否存在。
- if (!isExistNum(str))
- {
- MessageUtil.ShowWarning("标准组合序号有不存在的序号!");
- return -1;
- }
- }
- parmList.Add(this.PhyCode);
- parmList.Add(this.PhyName);
- parmList.Add(ultraTextEditor2.Text.Trim());
- parmList.Add(ultraTextEditor3.Text.Trim());
- parmList.Add(this.UserInfo.GetUserName());
- parmList.Add(ultraTextEditor4.Text.Trim());
- parmList.Add(System.Guid.NewGuid().ToString("N"));
- return 0;
- }
- /// <summary>
- /// 组合是否合法
- /// </summary>
- /// <param name="str"></param>
- /// <returns></returns>
- private bool TestFormula(string str)
- {
- decimal? result;
- result = str.CompileFormula();
- if (result == null)
- return false;
- return true;
- }
- string repStr = "A";
- /// <summary>
- /// 是否存在组合序号然后转化序号组合以及描述
- /// </summary>
- /// <returns></returns>
- private bool isExistNum(string str)
- {
- SResult = ultraTextEditor3.Text;
- string strGroup = sResult; //保留一份副本
- char[] ch = new char[] { '(', ')', '+', '-', ' ' };
- string[] arrStr = str.Split(ch, StringSplitOptions.RemoveEmptyEntries);
- Dictionary<string, string> dicValue = new Dictionary<string, string>(); //标准说明
- Dictionary<string, string> dicTemp = new Dictionary<string, string>(); //中间变量
- Dictionary<string, string> dicGroup = new Dictionary<string, string>(); //组合序号
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.doQueryIndex", new object[] { this.PhyCode }, this.newOb);
- if (dt != null && dt.Rows.Count > 0)
- {
- for (int i = 0; i < arrStr.Length; i++)
- {
- DataRow[] dr = dt.Select("INDEX_SEQ = '" + arrStr[i] + "'");
- if (dr.Length <= 0)
- {
- return false;
- }
- if (!dicValue.ContainsKey(arrStr[i]))
- dicValue.Add(arrStr[i], dr[0]["STD_DESC"].ToString());
- if (!dr[0]["INDEX_SEQ_GROUP"].ToString().Equals("") && !dicGroup.ContainsKey(arrStr[i]))
- dicGroup.Add(arrStr[i], dr[0]["INDEX_SEQ_GROUP"].ToString());
- }
- int[] arrInt = StringToInt(arrStr);
- string[] tempStr = new string[arrStr.Length];
- sResult = sResult.Replace("AND", "且");
- sResult = sResult.Replace("OR", "或");
- for (int i = 0; i < arrInt.Length; i++)
- {
- if (dicTemp.ContainsKey(arrInt[i].ToString()))
- {
- sResult = sResult.Replace(arrInt[i].ToString(), "#" + dicTemp[arrInt[i].ToString()]);
- if (dicGroup.ContainsKey(arrInt[i].ToString()))
- strGroup = strGroup.Replace(arrInt[i].ToString(), "#" + dicTemp[arrInt[i].ToString()]);
- }
- else
- {
- sResult = sResult.Replace(arrInt[i].ToString(), "#" + repStr);
- if (dicGroup.ContainsKey(arrInt[i].ToString()))
- strGroup = strGroup.Replace(arrInt[i].ToString(), "#" + repStr);
- }
- dicTemp.Add(repStr, arrInt[i].ToString());
- tempStr[i] = repStr;
- char newCh = Convert.ToChar(Convert.ToChar(repStr) + 1);
- repStr = newCh.ToString();
- }
- for (int i = 0; i < tempStr.Length; i++)
- {
- sResult = sResult.Replace("#" + tempStr[i], dicValue[dicTemp[tempStr[i]]]);
- if (dicGroup.ContainsKey(dicTemp[tempStr[i]]))
- {
- strGroup = strGroup.Replace("#" + tempStr[i], dicGroup[dicTemp[tempStr[i]]]);
- }
- }
- ultraTextEditor2.Text = sResult;
- ultraTextEditor3.Text = strGroup;
- // MessageBox.Show(sResult+"\n"+strGroup);
- return true;
- }
- else
- {
- return false;
- }
- }
- private int[] StringToInt(string[] arrStr)
- {
- int[] arrInt = new int[arrStr.Length];
- for (int i = 0; i < arrStr.Length; i++)
- {
- arrInt[i] = Convert.ToInt32(arrStr[i]);
- }
- arrInt = ArrSort(arrInt);
- return arrInt;
- }
- private int[] ArrSort(int[] arr)
- {
- for (int i = 0; i < arr.Length; ++i)
- {
- int temp = arr[i]; //定义一个int变量,并使用获得的数组元素值赋值
- int j = i;
- while ((j > 0) && (arr[j - 1] < temp)) //判断数组中的元素是否小于获得的值
- {
- arr[j] = arr[j - 1]; //如果是,则将后一元素的的值提前
- --j;
- }
- arr[j] = temp; //最后将int变量存储的值赋值给最后一个元素
- }
- return arr;
- }
- private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
- {
- if (ultraCheckEditor1.Checked)
- {
- ultraTextEditor3.Enabled = true;
- ultraTextEditor3.ReadOnly = true;
- }
- else
- {
- ultraTextEditor3.Enabled = false;
- }
- }
- private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
- {
- UltraGridRow ugr = ultraGrid1.ActiveRow;
- if (ugr == null)
- return;
- ultraTextEditor2.Text = ugr.Cells["STD_DESC"].Value.ToString();
- ultraTextEditor3.Text = ugr.Cells["INDEX_SEQ_GROUP"].Value.ToString();
- ultraTextEditor4.Text = ugr.Cells["MEMO"].Value.ToString();
- }
- private void ultraTextEditor3_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
- {
- UserControlCal usc = new UserControlCal();
- usc.CloseEvent += new CloseHandler(usc_CloseEvent);
- usc.OkEvent += new OkHandler(usc_OkEvent);
- ultraPopupControlContainer1.PopupControl = usc;
- int x = ultraGroupBox1.PointToScreen(ultraTextEditor3.Location).X;
- int y = ultraGroupBox1.PointToScreen(ultraTextEditor3.Location).Y - usc.Height;
- usc.TxtValue = ultraTextEditor3.Text;
- ultraPopupControlContainer1.Show(new Point(x, y));
- }
- void usc_OkEvent(string result, string result2)
- {
- this.SResult = result;
- ultraPopupControlContainer1.Close();
- ultraTextEditor3.Text = this.SResult;
- }
- void usc_CloseEvent()
- {
- ultraPopupControlContainer1.Close();
- }
- }
- }
|