| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 |
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Server;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinEditors;
- 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 FrmStandardG : FrmBase
- {
- //提示信息
- private string errMessage = "";
- private Dictionary<string, UltraComboEditor> _ultCmbDic_Unit = null;
- //定位标准基础
- private string _std = "";
- //判断是否勾选
- private int isSelectData = -1;
- UltraComboEditor[] ucbs = new UltraComboEditor[3];
- public FrmStandardG()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 重写基类方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="ToolbarKey"></param>
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- switch (ToolbarKey)
- {
- case "doQuery":
- DoQuery();
- break;
- case "doSave":
- DoSave();
- break;
- case "doDelete":
- this.DoDeleteOrResume(true);
- break;
- case "doResume":
- this.DoDeleteOrResume(false);
- break;
- case "Refresh":
- InitComBoEditor();
- break;
- case "Export":
- Export();
- break;
- case "Close":
- this.Close();
- break;
- }
- }
- private void Export()
- {
- GridHelper.ulGridToExcel(ultraGrid1, "其他标准");
- }
- /// <summary>
- /// 查询
- /// </summary>
- private void DoQuery()
- {
- //查询条件
- string valid = "1";
- if (ChcValid.Checked)
- valid = "0";
- string std = "";
- if (ChcStd.Checked)
- std = TextStd.Text.Trim();
- //CoreStandard标准基础表
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreStandard1.getComBaseStd", new Object[] { valid, std }, this.ob);
- if (CustomInfo == "1")
- {
- DataRow[] rows = dt.Select("STDSTYLE<>'订货标准' AND STDSTYLE<>'协议标准'");
- foreach (DataRow dr in rows)
- {
- dt.Rows.Remove(dr);
- }
- }
- if (CustomInfo == "2")
- {
- DataRow[] rows = dt.Select("STDSTYLE<>'内控'");
- foreach (DataRow dr in rows)
- {
- dt.Rows.Remove(dr);
- }
- }
- if (CustomInfo == "3")
- {
- DataRow[] rows = dt.Select("STDSTYLE<>'Alpha'");
- foreach (DataRow dr in rows)
- {
- dt.Rows.Remove(dr);
- }
- }
- if (CustomInfo == "4")
- {
- DataRow[] rows = dt.Select("STDSTYLE='协议标准' or STDSTYLE='订货标准' or STDSTYLE='Alpha' or STDSTYLE='内控'");
- foreach (DataRow dr in rows)
- {
- dt.Rows.Remove(dr);
- }
- }
- GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
- //定位
- UltraGridRow[] rows1 = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "STD_NAME" }, new string[] { _std });
- if (rows1.Length > 0)
- rows1[0].Activate();
- UltraGridColumn[] col = new UltraGridColumn[] { this.ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME"], this.ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"] };
- GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, col);
- QcmBaseCommon.SetUltraGridNoEdit(ultraGrid1);
- isSelectData = -1;
- }
- /// <summary>
- /// 保存
- /// </summary>
- private void DoSave()
- {
- ultraGrid1.UpdateData();
- if (isSelectData == -1)
- {
- MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //标准基础
- UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHC" }, new string[] { "True" });
- ArrayList stdAdd = new ArrayList();
- ArrayList stdUpdate = new ArrayList();
- if (rows.Length > 0)
- {
- foreach (UltraGridRow row in rows)
- {
- ArrayList stdList = GetStdData(row);
- if (stdList == null)
- {
- MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //标准名称
- string stdName = row.Cells["STD_NAME"].Value.ToString().Trim();
- string stdType = row.Cells["STDSTYLE"].Value.ToString();
- string stdCodeU = row.Cells["STD_CODE"].Value.ToString().Trim();
- if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("") && row.Cells["STD_NAME_OLD"].Value.ToString() != stdName)
- {
- DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.CoreStandard.getPsc", new Object[] { stdCodeU }, this.ob);
- if (dt1 != null && dt1.Rows.Count > 0 && Int32.Parse(dt1.Rows[0][0].ToString()) > 0)
- {
- MessageBox.Show("标准代码:" + stdCodeU + " 已经被产品规范码引用,不能修改!", "提示",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- _std = stdName;
- //标准代码
- string stdCode = row.Cells["STD_CODE"].Value.ToString().Trim();
- //如果创建人为空,则新增,否则修改
- if (row.Cells["VALIDFLAG"].Value.ToString().Equals(""))
- {
- UltraGridRow[] rows1 = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "STD_NAME", "STDSTYLE" }, new string[] { stdName, stdType });
- if (rows1.Length > 1)
- {
- MessageBox.Show("标准名称:" + stdName + " 已经存在,请重新输入!", "提示",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //验证标准名称是否重复
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreStandard1.checkStdName", new Object[] { stdName, stdType }, this.ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- MessageBox.Show("标准名称:" + stdName + " 已经存在,请重新输入!", "提示",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- stdAdd.Add(stdList);
- }
- else
- {
- //验证标准名称是否重复
- DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreStandard1.checkStdName",
- new Object[] { stdName, stdCode, stdType }, this.ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- MessageBox.Show("标准名称:" + stdName + " 已经存在,请重新输入!", "提示",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- stdList.Add(stdCode);
- stdUpdate.Add(stdList);
- }
- }
- }
- if (MessageBox.Show("是否保存选择记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- //产品规范
- ArrayList pscAdd = new ArrayList();
- ArrayList pscUpdate = new ArrayList();
- //客户
- ArrayList custerAdd = new ArrayList();
- ArrayList custerUpdate = new ArrayList();
- if (stdAdd.Count > 0 || pscAdd.Count > 0 || custerAdd.Count > 0 || stdUpdate.Count > 0 || pscUpdate.Count > 0 || custerUpdate.Count > 0)
- {
- int count = ServerHelper.SetData("com.steering.pss.qcm.CoreStandard1.saveCoreStandard1",
- new Object[] { stdAdd, stdUpdate, pscAdd, pscUpdate, custerAdd, custerUpdate }, this.ob);
- if (count > 0)
- {
- MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- DoQuery();
- }
- }
- }
- /// <summary>
- /// 作废与恢复
- /// </summary>
- /// <param name="flag"></param>
- private void DoDeleteOrResume(Boolean flag)
- {
- if (isSelectData == -1)
- {
- MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (flag)
- {
- if (MessageBox.Show("是否作废选择记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- }
- else
- {
- if (MessageBox.Show("是否恢复选择记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- }
- //标准基础
- UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHC" }, new string[] { "True" });
- ArrayList stdList = new ArrayList();
- ArrayList pscList = new ArrayList();
- ArrayList custList = new ArrayList();
- if (rows.Length > 0)
- {
- foreach (UltraGridRow row in rows)
- {
- ArrayList std = new ArrayList();
- if (flag)
- {
- std.Add(UserInfo.GetUserName());
- }
- else
- std.Add("");
- std.Add(row.Cells["STD_CODE"].Value.ToString());
- stdList.Add(std);
- //用于定位
- _std = row.Cells["STD_NAME"].Value.ToString();
- //DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.getCount", new Object[] { row.Cells["STD_NAME"].Value.ToString() }, this.ob);
- //if (dt1 != null && dt1.Rows.Count > 0 && Int32.Parse(dt1.Rows[0][0].ToString()) > 0)
- //{
- // MessageBox.Show("标准名称:" + row.Cells["STD_NAME"].Value.ToString() + " 已经被引用,不能作废!", "提示",
- // MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- //}
- }
- }
- if (stdList.Count > 0 || pscList.Count > 0 || custList.Count > 0)
- {
- int count = ServerHelper.SetData("com.steering.pss.qcm.CoreStandard1.deleteOrResume",
- new Object[] { stdList, pscList, custList, flag }, this.ob);
- if (count > 0)
- {
- if (flag)
- MessageBox.Show("作废成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- else
- MessageBox.Show("恢复成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- DoQuery();
- }
- }
- }
- /// <summary>
- /// 初始化下拉框
- /// </summary>
- private void InitComBoEditor()
- {
- for (int i = 0; i < ucbs.Length; i++)
- {
- ucbs[i] = new UltraComboEditor();
- Controls.Add(ucbs[i]);
- ucbs[i].Visible = false;
- }
- UltraGridBand ugb = ultraGrid1.DisplayLayout.Bands[0];
- //初始化标准类型
- ClsBaseInfo.FillStdType(ucbs[0], this.ob, false);
- if (CustomInfo == "1")
- {
- ((DataTable)ucbs[0].DataSource).DefaultView.RowFilter = "CODE IN ('G', 'X')";
- }
- if (CustomInfo == "2")
- {
- ((DataTable)ucbs[0].DataSource).DefaultView.RowFilter = "CODE IN ('N')";
- }
- if (CustomInfo == "3")
- {
- ((DataTable)ucbs[0].DataSource).DefaultView.RowFilter = "CODE IN ('K')";
- }
- if (CustomInfo == "4")
- {
- ((DataTable)ucbs[0].DataSource).DefaultView.RowFilter = "CODE IN ('P','S')";
- }
- ugb.Columns["STDSTYLE"].EditorComponent = ucbs[0];
- ugb.Columns["STDSTYLE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
- //初始化标准协会
- QcmBaseCommon.InitDropUltraComEditor(ucbs[1], "com.steering.pss.qcm.CoreStandard1.bandCmbMaxStdXh", "BASENAME", this.ob, true);
- ugb.Columns["STD_STYLE_NAME"].EditorComponent = ucbs[1];
- ugb.Columns["STD_STYLE_NAME"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
- //初始化管理部门
- QcmBaseCommon.InitDropUltraComEditor(ucbs[2], "com.steering.comm.data.ComBaseInfo.getDepartment", "DEPARTNAME", this.ob, false);
- ugb.Columns["DEPARTMENT_DESC"].EditorComponent = ucbs[2];
- ugb.Columns["DEPARTMENT_DESC"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
- CreateGrid1Combo(ucbs[2]);
- }
- /// <summary>
- /// 集合 生成Comboeditor集合 用于科室管理
- /// </summary>
- private void CreateGrid1Combo(UltraComboEditor ultraComboDepart)
- {
- int cout = ultraComboDepart.Items.Count;
- _ultCmbDic_Unit = new Dictionary<string, UltraComboEditor>(cout + 1);
- _ultCmbDic_Unit.Add("NoValue", new UltraComboEditor());
- for (int i = 0; i < ultraComboDepart.Items.Count; i++)
- {
- string pid = ultraComboDepart.Items[i].DataValue.ToString().Split('@')[0];
- DataTable dt = ServerHelper.GetData("com.steering.comm.data.ComBaseInfo.getSection",
- new object[] { }, this.ob);
- dt.DefaultView.RowFilter = "PID = '" + pid + "'";
- UltraComboEditor cmb = new UltraComboEditor();
- cmb.DataSource = dt;
- cmb.DisplayMember = "DEPARTNAME";
- cmb.ValueMember = "DEPARTID";
- cmb.Visible = false;
- _ultCmbDic_Unit.Add(pid, cmb);
- this.Controls.Add(cmb);
- }
- }
- /// <summary>
- /// 动态绑定数据源 管理科室
- /// </summary>
- private void BandComboToGrid(InitializeRowEventArgs e)
- {
- string pid = e.Row.Cells["DEPARTMENT_CODE"].Value.ToString();
- if (_ultCmbDic_Unit.ContainsKey(pid))
- {
- e.Row.Cells["UNIT_DESC"].EditorComponent = _ultCmbDic_Unit[pid];
- }
- else
- {
- e.Row.Cells["UNIT_DESC"].EditorComponent = _ultCmbDic_Unit["NoValue"];
- }
- }
- private void ChcStd_CheckedChanged(object sender, EventArgs e)
- {
- if (ChcStd.Checked)
- TextStd.Enabled = true;
- else
- TextStd.Enabled = false;
- }
- private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
- {
- //增加一行,自动获取最大的标准代码,然后加1
- UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow;
- int stdCode = 0;
- DataRow[] rows = dataTable1.Select("", "STD_CODE DESC");
- if (rows.Length > 0)
- stdCode = Convert.ToInt32(rows[0]["STD_CODE"].ToString().Substring(3, 7));
- ugr.Cells["STD_CODE"].Value = "STD" + string.Format("{0:0000000}", (stdCode + 1));
- //增加行如果没有勾选则不可编辑
- if (!Convert.ToBoolean(ugr.Cells["CHC"].Value))
- {
- for (int i = 0; i < ugr.Cells.Count; i++)
- {
- if (!ugr.Cells[i].Column.Key.Equals("CHC"))
- ugr.Cells[i].Activation = Activation.ActivateOnly;
- }
- }
- }
- private void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- ultraGrid1.UpdateData();
- UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow;
- if (e.Cell.Column.Key.Equals("STD_STYLE_NAME")) //标准协会
- {
- ugr.Cells["STD_STYLE"].Value = ugr.Cells["STD_STYLE_NAME"].Value.ToString();
- }
- //if (e.Cell.Column.Key.Equals("STDSTYLE")) //标准类型
- //{
- // if (e.Cell.Value.ToString().Equals("K"))
- // {
- // ugr.Cells["DEPARTMENT_DESC"].Appearance.BackColor = Color.Empty;
- // ugr.Cells["UNIT_DESC"].Appearance.BackColor = Color.Empty;
- // }
- // else
- // {
- // ugr.Cells["DEPARTMENT_DESC"].Appearance.BackColor = Color.Yellow;
- // ugr.Cells["UNIT_DESC"].Appearance.BackColor = Color.Yellow;
- // }
- //}
- if (e.Cell.Column.Key.Equals("DEPARTMENT_DESC")) //部门管理
- {
- string departMentCode = ugr.Cells["DEPARTMENT_DESC"].Value.ToString();
- string[] str = departMentCode.Split('@');
- ugr.Cells["DEPARTMENT_CODE"].Value = str[0];
- //根据部门号查询管理科室
- ugr.Cells["UNIT_CODE"].Value = "";
- ugr.Cells["UNIT_DESC"].Value = "";
- }
- if (e.Cell.Column.Key.Equals("UNIT_DESC")) //科室管理
- {
- ugr.Cells["UNIT_CODE"].Value = ugr.Cells["UNIT_DESC"].Value.ToString();
- }
- if (e.Cell.Column.Key.Equals("CHC"))//选择
- {
- Activation activation = Activation.ActivateOnly;
- if (Convert.ToBoolean(e.Cell.Value))
- {
- activation = Activation.AllowEdit;
- isSelectData += 1;
- }
- else
- isSelectData -= 1;
- CellsCollection cells = e.Cell.Row.Cells;
- for (int i = 0; i < cells.Count; i++)
- {
- if (!cells[i].Column.Key.Equals("CHC"))
- {
- e.Cell.Row.Cells[i].Activation = activation;
- }
- }
- }
- }
- private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
- {
- BandComboToGrid(e);
- if (e.Row.Cells["VALIDFLAG"].Value.ToString().Equals("无效"))
- {
- e.Row.Appearance.ForeColor = Color.Red;
- }
- else
- {
- e.Row.Appearance.ForeColor = Color.Black;
- }
- }
- /// <summary>
- /// 获取标准类型数据
- /// </summary>
- /// <param name="ugr"></param>
- /// <returns></returns>
- private ArrayList GetStdData(UltraGridRow ugr)
- {
- ArrayList list = new ArrayList();
- string std_code = ugr.Cells["std_code"].Value.ToString();
- string std_name = ugr.Cells["std_name"].Value.ToString().Trim();
- if (std_name.Equals(""))
- {
- errMessage = "请输入标准名称";
- return null;
- }
- string stdstyle = ugr.Cells["stdstyle"].Text.ToString();
- if (stdstyle.Equals(""))
- {
- errMessage = "请选择标准类型";
- return null;
- }
- if (stdstyle.Equals("订货标准"))
- stdstyle = "G";
- else if (stdstyle.Equals("Alpha"))
- stdstyle = "K";
- else if (stdstyle.Equals("内控"))
- stdstyle = "N";
- else if (stdstyle.Equals("协议标准"))
- stdstyle = "X";
- else if (stdstyle.Equals("试验标准"))
- stdstyle = "S";
- else
- stdstyle = "P";
- string std_note = ugr.Cells["std_note"].Value.ToString();
- string std_style = ugr.Cells["std_style"].Value.ToString();
- string std_style_name = ugr.Cells["std_style_name"].Text.ToString();
- string std_version = ugr.Cells["std_version"].Value.ToString();
- string department_code = ugr.Cells["department_code"].Value.ToString();
- string department_desc = ugr.Cells["department_desc"].Text.ToString();
- if (CustomInfo != "3" && department_desc.Equals(""))
- {
- errMessage = "请选择管理部门描述";
- return null;
- }
- string unit_code = ugr.Cells["unit_code"].Value.ToString();
- string unit_desc = ugr.Cells["unit_desc"].Text.ToString();
- if (CustomInfo != "3" && unit_desc.Equals(""))
- {
- errMessage = "请选择管理科室描述";
- return null;
- }
- string userName = UserInfo.GetUserName();
- string validflag = ugr.Cells["validflag"].Value.ToString();
- if (validflag.Equals("无效"))
- {
- errMessage = "无效记录不能保存";
- return null;
- }
- string memo = ugr.Cells["memo"].Value.ToString();
- list.Add(std_code);
- list.Add(std_name);
- list.Add(stdstyle);
- list.Add(std_note);
- list.Add(std_style);
- list.Add(std_style_name);
- list.Add(std_version);
- list.Add(department_code);
- list.Add(department_desc);
- list.Add(unit_code);
- list.Add(unit_desc);
- list.Add(userName);
- list.Add(memo);
- return list;
- }
- private void FrmStandardG_Load(object sender, EventArgs e)
- {
- InitComBoEditor();
- if (this.CustomInfo == "3")
- {
- this.ultraGrid1.DisplayLayout.Bands[0].Columns["DEPARTMENT_DESC"].CellAppearance.BackColor = Color.Empty;
- this.ultraGrid1.DisplayLayout.Bands[0].Columns["UNIT_DESC"].CellAppearance.BackColor = Color.Empty;
- }
- }
- }
- }
|