using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Core.StlMes.Client.SaleOrder.BLL;
using CoreFS.CA06;
using Core.Mes.Client.Comm.Tool;
using Infragistics.Win.UltraWinEditors;
using Core.Mes.Client.Comm.Server;
using Core.StlMes.Client.Qcm;
using Infragistics.Win.UltraWinGrid;
using CoreFS.SA06;
using Infragistics.Win;
using Core.Mes.Client.Comm.Control;
namespace Core.StlMes.Client.SaleOrder.Control
{
public partial class CraftOrdDesignStdGicCtrl : UserControl
{
private CraftOrdDesignStdGicBLL _designStdGicBLL;
private CraftOrdDesignMscPlBLL _designMscPlBLL;
private CraftOrdDesignMscPlPrcBLL _designMscPlPrcBLL;
UltraComboEditor MscUce = new UltraComboEditor(); //MSC下拉框
UltraComboEditor StationUce = new UltraComboEditor(); //工序点下拉框
UltraComboEditor StdUce = new UltraComboEditor(); //标准下拉框
UltraComboEditor cmbProBigType = new UltraComboEditor();
UltraComboEditor Gics = new UltraComboEditor();
private OpeBase _ob;
public CraftOrdDesignStdGicCtrl(System.Windows.Forms.Control container, OpeBase ob)
{
InitializeComponent();
_ob = ob;
_designStdGicBLL = new CraftOrdDesignStdGicBLL(ob);
_designMscPlBLL = new CraftOrdDesignMscPlBLL(ob);
_designMscPlPrcBLL = new CraftOrdDesignMscPlPrcBLL(ob);
container.Controls.Add(this);
this.Dock = DockStyle.Fill;
LoadBaseData();
}
private void LoadBaseData()
{
//---子表工序点名称--------
this.Controls.Add(MscUce);
MscUce.Visible = false;
this.Controls.Add(StationUce);
StationUce.Visible = false;
this.Controls.Add(Gics);
Gics.Visible = false;
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreComMscStdProcess.getStation", null, _ob);
StationUce.DataSource = dt;
StationUce.DisplayMember = "STATION_DESC";
StationUce.ValueMember = "STATION_CODE";
QcmBaseQuery.BindColumn(StationUce, "StationCode", entityGrid1.DisplayLayout.Bands[0]);
}
///
/// 查询质量设计加工
///
///
public void Query(CraftOrdDesignStdGicEntity designStdGicEntity)
{
this.CraftOrdDesignStdGicEntityBindingSource.DataSource = _designStdGicBLL.Query(designStdGicEntity);
}
private string designKey = "";
private string[] _parms;
///
/// 查询质量设计加工
///
///
public void QueryByDesignKeyGic(string[] parms)
{
designKey = parms[0];
_parms = parms;
List data = _designStdGicBLL.QueryByDesignKeyGic(parms);
var list = data.Select(p=>p.Gic).Distinct().ToList();
if (list.Count > 1)
{
Gics.DataSource = list;
QcmBaseQuery.BindColumn(Gics, "Gic", entityGrid1.DisplayLayout.Bands[0]);
}
this.CraftOrdDesignStdGicEntityBindingSource.DataSource = data;
//UltraComboEditor cmb = new UltraComboEditor();
foreach (var row in entityGrid1.Rows)
{
GridEdite(row);
if (row.GetValue("CraftSource") == "0")
{
row.Cells["Chk"].Value = null;
row.Cells["Chk"].Activation = Activation.ActivateOnly;
row.Update();
}
//if (cmb.ValueList.FindString(row.GetValue("Gic")) == -1)
//{
// cmb.ValueList.ValueListItems.Add(row.GetValue("Gic"));
//}
}
entityGrid1.UpdateData();
//cmb.DisplayStyle = EmbeddableElementDisplayStyle.WindowsVista;
//entityGrid1.DisplayLayout.Bands[0].Columns["Gic"].EditorComponent = cmb;
//entityGrid1.DisplayLayout.Bands[0].Columns["Gic"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
}
public void Clear()
{
this.CraftOrdDesignStdGicEntityBindingSource.Clear();
}
public void Save()
{
List parms = new List();
var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
foreach (var row in rows)
{
var parm = EntityHelper.CopyEntity(row.ListObject);
if (parm.MscPline == "")
{
MessageUtil.ShowWarning("请选择制程!");
row.SetCellActive("MscPline");
return;
}
//if (parm.ProcessDescC2 == "")
//{
// MessageUtil.ShowWarning("请选择二级工序!");
// row.SetCellActive("ProcessDescC2");
// return;
//}
if (parm.Gic == "")
{
MessageUtil.ShowWarning("请选择加工索引码!");
row.SetCellActive("Gic");
return;
}
if (parm.StationCode.Equals(""))
{
MessageUtil.ShowWarning("请选择工序点名称!");
return;
}
if (parm.ValueText == "" && parm.ValueNum == null)
{
MessageUtil.ShowWarning("文本值和数值必须输入一个!");
return;
}
if (parm.ValueText != "" && parm.ValueNum != null)
{
MessageUtil.ShowWarning("文本值和数值只能输入一个!");
return;
}
parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
parm.DesginKey = designKey;
parm.SpeclFl = "2";
parms.Add(parm);
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
{
return;
}
_designStdGicBLL.Save(parms);
MessageUtil.ShowTips("保存成功!");
QueryByDesignKeyGic(_parms);
}
public void Delete()
{
List parms = new List();
var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
foreach (var row in rows)
{
var parm = EntityHelper.CopyEntity(row.ListObject);
parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
parm.SpeclFl = "2";
parm.DesginKey = designKey;
parms.Add(parm);
}
_designStdGicBLL.Delete(parms);
}
private void GridEdite(UltraGridRow row)
{
if (row.GetValue("Chk") == "True")
{
foreach (UltraGridCell cell in row.Cells)
{
if (cell.Column.CellActivation == Activation.AllowEdit)
{
cell.Activation = Activation.AllowEdit;
}
}
}
else
{
foreach (UltraGridCell cell in row.Cells)
{
if (cell.Column.Key == "Chk") continue;
if (cell.Column.CellActivation == Activation.AllowEdit)
{
cell.Activation = Activation.ActivateOnly;
}
}
}
}
private void entityGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
entityGrid1.UpdateData();
GridEdite(e.Cell.Row);
}
private void entityGrid1_AfterRowInsert(object sender, RowEventArgs e)
{
e.Row.Cells["ProcessCdoe"].Value = "G";
e.Row.Cells["ProcessDesc"].Value = "加工";
e.Row.Cells["CraftSource"].Value = "1";
e.Row.Cells["SpeclFl"].Value = "2";
}
private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
{
UltraGridRow row = entityGrid1.ActiveRow;
string key = entityGrid1.ActiveCell.Column.Key;
if (key == "MscPline")
{
DataTable dt = _designMscPlBLL.QueryMscPlineProcess(designKey);
dt.Columns["MSC_PLINE"].Caption = "制程号";
dt.Columns["WHOLE_BACKLOG"].Caption = "全程途径码";
dt.Columns["WHOLE_BACKLOG_DESC"].Caption = "全程途径描述";
dt.Columns["PROCESS_DESC"].Caption = "工序";
dt.Columns["PROCESS_DESC_C"].Caption = "二级工序";
dt.Columns["GIC"].Caption = "加工内控索引码";
DataTable dtNew = dt.Clone();
foreach (DataRow dr in dt.Rows)
{
string[] gics = dr["GIC"].ToString().Split(',');
foreach (string gic in gics)
{
DataRow drNew = dtNew.NewRow();
drNew["MSC_PLINE"] = dr["MSC_PLINE"];
drNew["WHOLE_BACKLOG"] = dr["WHOLE_BACKLOG"];
drNew["WHOLE_BACKLOG_DESC"] = dr["WHOLE_BACKLOG_DESC"];
drNew["PROCESS_DESC"] = dr["PROCESS_DESC"];
drNew["PROCESS_DESC_C"] = dr["PROCESS_DESC_C"];
drNew["PROCESS_CODE"] = dr["PROCESS_CODE"];
drNew["PROCESS_CODE_C"] = dr["PROCESS_CODE_C"];
drNew["GIC"] = gic.Trim();
dtNew.Rows.Add(drNew);
}
}
BaseInfoPopup popup = new BaseInfoPopup(dtNew, "MSC_PLINE", "CIC", "SIC", "DIC", "WIC", "PIC", "PROCESS_CODE", "PROCESS_CODE_C");
GridHelper.RefreshAndAutoSize(popup.UltraGrid1);
popup.LabelTextBox1.Caption = "制程号";
if (popup.ShowDialog() == DialogResult.OK)
{
row.SetValue("MscPline", popup.ChoicedRow.GetValue("MSC_PLINE"));
row.SetValue("ProcessDescC2", popup.ChoicedRow.GetValue("PROCESS_DESC_C"));
row.SetValue("ProcessCodeC", popup.ChoicedRow.GetValue("PROCESS_CODE_C"));
row.SetValue("ProcessDesc", popup.ChoicedRow.GetValue("PROCESS_DESC"));
row.SetValue("ProcessCode", popup.ChoicedRow.GetValue("PROCESS_CODE"));
row.SetValue("Gic", popup.ChoicedRow.GetValue("GIC"));
}
}
else if (key == "ProcessDescC2")
{
string mscPline = entityGrid1.ActiveRow.GetValue("MscPline");
DataTable dt = _designMscPlPrcBLL.queryProcess(designKey, mscPline);
dt.Columns["PROCESS_DESC"].Caption = "工序";
dt.Columns["PROCESS_DESC_C"].Caption = "二级工序";
BaseInfoPopup popup = new BaseInfoPopup(dt, "PROCESS_DESC_C", "PROCESS_CODE", "PROCESS_CODE_C");
popup.LabelTextBox1.Caption = "二级工序";
if (popup.ShowDialog() == DialogResult.OK)
{
row.SetValue("ProcessDescC2", popup.ChoicedRow.GetValue("PROCESS_DESC_C"));
row.SetValue("ProcessCodeC", popup.ChoicedRow.GetValue("PROCESS_CODE_C"));
row.SetValue("ProcessDesc", popup.ChoicedRow.GetValue("PROCESS_DESC"));
row.SetValue("ProcessCode", popup.ChoicedRow.GetValue("PROCESS_CODE"));
}
}
else if (key == "Gic")
{
string mscPline = entityGrid1.ActiveRow.GetValue("MscPline");
string processCode = entityGrid1.ActiveRow.GetValue("ProcessCode");
DataTable dt = _designMscPlPrcBLL.queryProcessNkIndex(designKey, mscPline, processCode);
dt.Columns["GIC"].Caption = "加工内控索引码";
BaseInfoPopup popup = new BaseInfoPopup(dt, "GIC", "CIC", "SIC", "DIC", "WIC", "PIC");
popup.LabelTextBox1.Caption = "加工内控索引码";
if (popup.ShowDialog() == DialogResult.OK)
{
row.SetValue("Gic", popup.ChoicedRow.GetValue("GIC"));
}
}
}
}
}