| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.Qcm.BLL;
- using Core.StlMes.Client.Qcm.model;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinGrid;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.Qcm
- {
- public partial class ComBaseWaterGroupFrm : FrmBase
- {
- private ComBaseWaterGroupBLL _waterGroupBLL;
- private List<ComBaseWaterGroupEntity> _waterGroupGradeList;
- public ComBaseWaterGroupFrm()
- {
- InitializeComponent();
- EntityHelper.ShowGridCaption<ComBaseWaterGroupEntity>(ultraGrid1.DisplayLayout.Bands[0]);
- EntityHelper.ShowGridCaption<ComBaseWaterGroupEntity>(ultraGrid2.DisplayLayout.Bands[0]);
- }
- private void ComBaseWaterGroupFrm_Load(object sender, EventArgs e)
- {
- _waterGroupBLL = new ComBaseWaterGroupBLL(ob);
- QueryWaterGroup();
- }
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- base.ToolBar_Click(sender, ToolbarKey);
- switch (ToolbarKey)
- {
- case "Query":
- QueryWaterGroup();
- break;
- case "Save":
- SaveWaterGroup();
- break;
- case "MoveUp":
- MoveUp();
- break;
- case "MoveDown":
- MoveDown();
- break;
- case "Close":
- this.Close();
- break;
- }
- }
- private void QueryWaterGroup()
- {
- this.comBaseWaterGroupEntityBindingSource.DataSource = _waterGroupBLL.QueryWaterGroup();
- ultraGrid1.UpdateData();
- }
- private void QueryWaterGroupGrade()
- {
- ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)ultraGrid1.ActiveRow.ListObject;
- _waterGroupGradeList = _waterGroupBLL.QueryWaterGroupGrade(waterGroup.WaterGroupCode);
- this.comBaseWaterGroupEntityBindingSource1.DataSource = _waterGroupGradeList.AsQueryable()
- .OrderByDescending(a => a.Chk).ThenBy(a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
- foreach (UltraGridRow row in ultraGrid2.Rows)
- {
- ComBaseWaterGroupEntity waterGroup2 = (ComBaseWaterGroupEntity)row.ListObject;
- if (waterGroup2.WaterGroupCode != "")
- {
- row.SetValue("Chk", "True");
- }
- }
- ultraGrid2.UpdateData();
- }
- /// <summary>
- /// 空认为是最大的值
- /// </summary>
- private class NullMaxCompare : IComparer<decimal?>
- {
- #region IComparer<string> 成员
- public int Compare(decimal? x, decimal? y)
- {
- if (x == y)
- {
- return 0;
- }
- else if (x == null)
- {
- return Convert.ToInt32(99999 - y);
- }
- else if (y == null)
- {
- return Convert.ToInt32(x - 99999);
- }
- else
- {
- return Convert.ToInt32(x - y);
- }
- }
- #endregion
- }
- ///// <summary>
- ///// 空认为是最小的值
- ///// </summary>
- //private class NullSmallCompare : IComparer<decimal?>
- //{
- // #region IComparer<string> 成员
- // public int Compare(decimal? x, decimal? y)
- // {
- // if (x == y)
- // {
- // return 0;
- // }
- // else if (x == null)
- // {
- // return 0;
- // }
- // else if (y == null)
- // {
- // return 0;
- // }
- // else if (x > y)
- // {
- // return 1;
- // }
- // else
- // {
- // return -1;
- // }
- // }
- // #endregion
- //}
- private void SaveWaterGroup()
- {
- ultraGrid2.UpdateData();
- if (ultraGrid1.ActiveRow == null)
- {
- MessageUtil.ShowWarning("请选择一行记录!");
- return;
- }
- if (ultraGrid1.ActiveRow.GetValue("WaterGroup") == "")
- {
- MessageUtil.ShowWarning("请输入连浇群组名称!");
- return;
- }
- var rows = ultraGrid2.Rows.AsQueryable().Where("CHK = 'True'");
- var waterGroups = rows.Select(a => (ComBaseWaterGroupEntity)a.ListObject);
- if (rows.Count() == 0)
- {
- MessageUtil.ShowWarning("请选择记录!");
- return;
- }
- string waterGroupDesc = ultraGrid1.ActiveRow.GetValue("WaterGroup");
- string waterGroupCode = ultraGrid1.ActiveRow.GetValue("WaterGroupCode");
- if (_waterGroupBLL.GetWaterGroupCnt(waterGroupDesc, waterGroupCode) > 0)
- {
- MessageUtil.ShowWarning("系统已连浇群组名称" + waterGroupDesc + "!");
- return;
- }
- var groupRows = waterGroups.GroupBy(a => a.GradeIndex).Where(a => a.Count() >= 2);
- foreach (var row in groupRows)
- {
- MessageUtil.ShowWarning("钢种序号:" + row.Key + "重复!");
- var repeatRow = rows.Where(a => a.GetValue("GradeIndex") == row.Key.ToString());
- if (repeatRow.Count() > 0)
- {
- repeatRow.First().Cells["GradeIndex"].Activate();
- }
- return;
- }
- List<ComBaseWaterGroupEntity> listWaterGroups = rows.Select(a => (ComBaseWaterGroupEntity)a.ListObject).ToList();
- string gradeCodes = "";
- foreach (ComBaseWaterGroupEntity waterGroup in listWaterGroups)
- {
- waterGroup.CreateName = UserInfo.GetUserName();
- waterGroup.WaterGroupCode = ultraGrid1.ActiveRow.GetValue("WaterGroupCode");
- waterGroup.WaterGroup = ultraGrid1.ActiveRow.GetValue("WaterGroup");
- if (gradeCodes == "")
- {
- gradeCodes = waterGroup.Gradecode;
- }
- else
- {
- gradeCodes += "," + waterGroup.Gradecode;
- }
- }
- string gradeWaterGroup = "";
- if (_waterGroupBLL.GetWaterGroupGradeCnt(gradeCodes, waterGroupCode, out gradeWaterGroup) > 0)
- {
- MessageUtil.ShowWarning("该连浇群组与连浇群组" + gradeWaterGroup + "的钢种组合重复!");
- return;
- }
- if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
- {
- return;
- }
- waterGroupCode = _waterGroupBLL.SaveWaretGroupGrade(listWaterGroups);
- MessageUtil.ShowTips("保存成功!");
- Relocate(waterGroupCode);
- }
- private void Relocate(string waterGroupCode)
- {
- QueryWaterGroup();
- var row = ultraGrid1.Rows.Where(a => a.GetValue("waterGroupCode") == waterGroupCode).FirstOrDefault();
- if (row != null)
- {
- row.Activate();
- }
- }
- private void MoveUp()
- {
- ultraGrid2.BeginUpdate();
- IQueryable<UltraGridRow> rows = ultraGrid2.Rows.AsQueryable().Where(
- a => a.Activated || a.Selected);
- IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
- foreach (UltraGridRow row in rows)
- {
- if (row.Index == 0) continue;
- ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)row.ListObject;
- ComBaseWaterGroupEntity[] preWaterGroups = ultraGrid2.Rows.AsQueryable().Select(a => (ComBaseWaterGroupEntity)a.ListObject)
- .Where(a => a.Chk && a.GradeIndex < waterGroup.GradeIndex).OrderByDescending(a => a.GradeIndex).ToArray();
- if (preWaterGroups.Length > 0)
- {
- decimal? index = waterGroup.GradeIndex;
- waterGroup.GradeIndex = preWaterGroups[0].GradeIndex;
- preWaterGroups[0].GradeIndex = index;
- }
- else
- {
- continue;
- }
- }
- this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
- a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
- ultraGrid2.EndUpdate();
- }
- private void MoveDown()
- {
- ultraGrid2.BeginUpdate();
- IQueryable<ComBaseWaterGroupEntity> selectedRows = ultraGrid2.Rows.AsQueryable().Where(
- a => a.Activated || a.Selected).Select(a => (ComBaseWaterGroupEntity)a.ListObject).OrderByDescending(a => a.GradeIndex);
- IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
- foreach (ComBaseWaterGroupEntity waterGroup in selectedRows)
- {
- ComBaseWaterGroupEntity[] preWaterGroups = ultraGrid2.Rows.AsQueryable().Select(a => (ComBaseWaterGroupEntity)a.ListObject)
- .Where(a => a.Chk && a.GradeIndex > waterGroup.GradeIndex).OrderBy(a => a.GradeIndex).ToArray();
- if (preWaterGroups.Length > 0)
- {
- decimal? index = waterGroup.GradeIndex;
- waterGroup.GradeIndex = preWaterGroups[0].GradeIndex;
- preWaterGroups[0].GradeIndex = index;
- }
- else
- {
- continue;
- }
- }
- this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
- a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
- ultraGrid2.EndUpdate();
- }
- private void ultraGrid2_InitializeRow(object sender, InitializeRowEventArgs e)
- {
- }
- private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
- {
- try
- {
- this.Cursor = Cursors.WaitCursor;
- QueryWaterGroupGrade();
- }
- finally
- {
- this.Cursor = Cursors.Default;
- }
- }
- private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
- {
- e.Layout.Override.TemplateAddRowPrompt = "点击新增一行记录!";
- e.Layout.Override.TemplateAddRowAppearance.BackColor = Color.FromArgb(255, 255, 128);
- }
- private void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- ultraGrid1.UpdateData();
- }
- private void ultraGrid2_CellChange(object sender, CellEventArgs e)
- {
- ultraGrid2.UpdateData();
- ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)e.Cell.Row.ListObject;
- if (e.Cell.Column.Key == "Chk" && waterGroup.GradeIndex == null)
- {
- IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
- var waterGroups = queryableRows.Where(a => a.GradeIndex != null).OrderByDescending(
- a => a.GradeIndex, new NullMaxCompare());
- if (waterGroups.Count() > 0)
- {
- waterGroup.GradeIndex = waterGroups.First().GradeIndex + 1;
- }
- else
- {
- waterGroup.GradeIndex = 1;
- }
- ultraGrid2.Refresh();
- this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
- a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
- }
- }
- }
- }
|