using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Views.Grid;
|
using Gs.DevApp.ToolBox;
|
using Gs.DevApp.UserControl;
|
using Gs.DevApp.Entity;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.DevFrm.MJGL
|
{
|
public partial class Frm_MesMoldManagement : XtraForm
|
{
|
private readonly string _webServiceName = "MesMoldManagementManager/";
|
private List<FilterEntity> _filterList = new List<FilterEntity>();
|
private DataTable _moldListDt;
|
|
public Frm_MesMoldManagement()
|
{
|
InitializeComponent();
|
toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
|
toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
|
toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
|
toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
|
toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
|
toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
|
toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
|
toolBarMenu1.getXmlConfig();
|
|
UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", (value) =>
|
{
|
UtilityHelper.JumpTab(xtraTabControl1, 0);
|
}, tips);
|
UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) =>
|
{
|
getModel(value);
|
}, (value) =>
|
{
|
getPageList(pageBar1.CurrentPage);
|
}, lbGuid);
|
|
|
|
txt_itemCode.DoubleClick += (s, e) =>
|
{
|
try
|
{
|
var frm = new Gs.DevApp.DevFrm.QC.JyxmShow("");
|
frm.UpdateParent += (ss, ee) =>
|
{
|
try
|
{
|
var lst = ee.DynamicList;
|
txt_itemId.Text = Convert.ToString(lst[0].itemId);
|
txt_itemCode.Text = Convert.ToString(lst[0].itemNo);
|
txt_itemName.Text = Convert.ToString(lst[0].itemName);
|
txt_itemModel.Text = Convert.ToString(lst[0].itemModel);
|
}
|
catch (Exception ex2)
|
{
|
MsgHelper.Warning("提示:" + ex2.Message);
|
}
|
};
|
frm.ShowDialog();
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
};
|
|
|
// 物料ID选择,复用QC检验项目的选择弹窗
|
txt_itemId.ButtonClick += (s, e) =>
|
{
|
try
|
{
|
var frm = new Gs.DevApp.DevFrm.QC.JyxmShow("");
|
frm.UpdateParent += (ss, ee) =>
|
{
|
try
|
{
|
var lst = ee.DynamicList;
|
txt_itemId.Text = Convert.ToString(lst[0].itemId);
|
txt_itemCode.Text = Convert.ToString(lst[0].itemNo);
|
}
|
catch (Exception ex2)
|
{
|
MsgHelper.Warning("提示:" + ex2.Message);
|
}
|
};
|
frm.ShowDialog();
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
};
|
|
// 模具下拉数据绑定(集成到模具编码控件)
|
try
|
{
|
var pgqMold = new PageQueryModel(1, 999999, "mold_code", "asc", "", "");
|
var jMold = JsonConvert.SerializeObject(pgqMold);
|
var strMold = UtilityHelper.HttpPost("", "MesMoldArchivesManager/GetMoldCodeList", jMold);
|
var rtnMold = UtilityHelper.ReturnToTablePage(strMold);
|
var dtMold = rtnMold.rtnData.list;
|
_moldListDt = dtMold;
|
|
string codeField = _moldListDt.Columns.Contains("mold_code") ? "mold_code" : (_moldListDt.Columns.Contains("moldCode") ? "moldCode" : "");
|
string nameField = _moldListDt.Columns.Contains("mold_name") ? "mold_name" : (_moldListDt.Columns.Contains("moldName") ? "moldName" : "");
|
string specField = _moldListDt.Columns.Contains("mold_spec") ? "mold_spec" : (_moldListDt.Columns.Contains("moldSpec") ? "moldSpec" : "");
|
|
txt_moldCode.Properties.DataSource = _moldListDt;
|
txt_moldCode.Properties.DisplayMember = string.IsNullOrEmpty(codeField) ? nameField : codeField;
|
txt_moldCode.Properties.ValueMember = string.IsNullOrEmpty(codeField) ? nameField : codeField;
|
txt_moldCode.ForceInitialize();
|
txt_moldCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
var view = lookMoldView;
|
view.Columns.Clear();
|
view.OptionsBehavior.AutoPopulateColumns = false;
|
if (!string.IsNullOrEmpty(codeField))
|
{
|
var colCode = view.Columns.AddVisible(codeField, "模具编码");
|
colCode.VisibleIndex = 0;
|
}
|
if (!string.IsNullOrEmpty(nameField))
|
{
|
var colName = view.Columns.AddVisible(nameField, "模具名称");
|
colName.VisibleIndex = 1;
|
}
|
if (!string.IsNullOrEmpty(specField))
|
{
|
var colSpec = view.Columns.AddVisible(specField, "模具规格");
|
colSpec.VisibleIndex = 2;
|
}
|
view.OptionsView.ShowAutoFilterRow = true;
|
view.BestFitColumns();
|
|
txt_moldCode.EditValueChanged += (s, e) =>
|
{
|
try
|
{
|
var row = txt_moldCode.GetSelectedDataRow() as DataRowView;
|
if (row != null)
|
{
|
if (!string.IsNullOrEmpty(nameField)) txt_moldName.Text = Convert.ToString(row[nameField]);
|
if (!string.IsNullOrEmpty(specField)) txt_moldSpec.Text = Convert.ToString(row[specField]);
|
}
|
}
|
catch { }
|
};
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
|
// 物料下拉数据绑定
|
try
|
{
|
var objItems = new
|
{
|
currentPage = 1,
|
everyPageSize = 999999,
|
sortName = "",
|
keyWhere = "",
|
keyType = ""
|
};
|
var jItems = JsonConvert.SerializeObject(objItems);
|
var strItems = UtilityHelper.HttpPost("", "MesItemsManager/GetListSelect", jItems);
|
var rtnItems = UtilityHelper.ReturnToTablePage(strItems);
|
var dtItems = rtnItems.rtnData.list;
|
lookItem.Properties.DataSource = dtItems;
|
lookItem.Properties.DisplayMember = "ItemNo";
|
lookItem.Properties.ValueMember = "Id";
|
lookItem.ForceInitialize();
|
lookItem.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
lookItem.EditValueChanged += (s, e) =>
|
{
|
try
|
{
|
var row = lookItem.GetSelectedDataRow() as DataRowView;
|
if (row != null)
|
{
|
txt_itemCode.Text = Convert.ToString(row["ItemNo"]);
|
txt_itemId.Text = Convert.ToString(row["Id"]);
|
txt_itemName.Text = Convert.ToString(row["ItemName"]);
|
txt_itemModel.Text = Convert.ToString(row["ItemModel"]);
|
}
|
}
|
catch { }
|
};
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
|
|
|
getPageList(1);
|
pageBar1.PagerEvent += PageBar1_PagerEvent;
|
}
|
|
private void PageBar1_PagerEvent(int curPage, int pageSize)
|
{
|
getPageList(curPage);
|
}
|
|
private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
|
{
|
gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
|
gridView1.ActiveFilter.Clear();
|
gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
|
var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName);
|
frm.UpdateParent += Frm_UpdateParent;
|
frm.ShowDialog();
|
}
|
|
private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
|
{
|
_filterList = e.FilterList;
|
getPageList(1);
|
}
|
|
private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
|
{
|
_filterList = UtilityHelper.GetDilter(gridView1.Columns, gridView1);
|
getPageList(1);
|
}
|
|
private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
|
{
|
if (xtraTabControl1.SelectedTabPageIndex == 1)
|
getModel(lbGuid.Text.Trim());
|
else
|
getPageList(pageBar1.CurrentPage);
|
}
|
|
private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
|
{
|
UtilityHelper.JumpTab(xtraTabControl1, 1);
|
}
|
|
private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
|
{
|
toolBarMenu1.currentAction = "edit";
|
string rowGuid, rowName;
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_moldCode, gridView1);
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
UtilityHelper.JumpTab(xtraTabControl1, 3);
|
getModel(rowGuid);
|
}
|
|
private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
|
{
|
lbGuid.Text = "";
|
UtilityHelper.JumpTab(xtraTabControl1, 4);
|
UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true);
|
}
|
|
private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
|
{
|
string rowGuid, rowName;
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_moldCode, gridView1);
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
try
|
{
|
var strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(new List<string> { rowGuid }));
|
var rtn = UtilityHelper.ReturnToDynamic(strJson);
|
MsgHelper.Warning("提示:" + rtn.rtnMsg);
|
if (rtn.rtnCode > 0) getPageList(pageBar1.CurrentPage);
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
|
{
|
toolBarMenu1.isSetBtn = false;
|
var moldCodeVal = Convert.ToString(txt_moldCode.EditValue)?.Trim();
|
if (string.IsNullOrEmpty(moldCodeVal))
|
{
|
MsgHelper.Warning("模具编码不能为空!");
|
txt_moldCode.Focus();
|
return;
|
}
|
var obj = new
|
{
|
Guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()),
|
MoldCode = moldCodeVal,
|
ItemCode = txt_itemCode.Text.Trim(),
|
ItemId = txt_itemId.Text.Trim(),
|
Status = txt_status.Text.Trim(),
|
PackQty = txt_packQty.Text.Trim(),
|
Capacity = txt_capacity.Text.Trim(),
|
Description = txt_description.Text.Trim()
|
};
|
if (string.IsNullOrEmpty(txt_itemCode.Text.Trim()) || string.IsNullOrEmpty(txt_itemId.Text.Trim()))
|
{
|
MsgHelper.Warning("物料编码与物料ID必须选择!");
|
txt_itemId.Focus();
|
return;
|
}
|
try
|
{
|
var strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(obj));
|
var rtn = UtilityHelper.ReturnToDynamic(strJson);
|
MsgHelper.Warning("提示:" + rtn.rtnMsg);
|
if (rtn.rtnCode > 0)
|
{
|
lbGuid.Text = rtn.rtnData;
|
toolBarMenu1.isSetBtn = true;
|
UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false);
|
toolBarMenu1.currentAction = "";
|
UtilityHelper.JumpTab(xtraTabControl1, 6);
|
}
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
private void getPageList(int curPage)
|
{
|
gcMain1.DataSource = null;
|
var sbWhere = UtilityHelper.GetSearchWhere(_filterList);
|
var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "mold_code", "asc", "", sbWhere.ToString());
|
var json = JsonConvert.SerializeObject(pgq);
|
try
|
{
|
var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json);
|
var dd = UtilityHelper.ReturnToTablePage(strReturn);
|
if (dd.rtnCode > 0)
|
{
|
DataTable dt = dd.rtnData.list;
|
gcMain1.BindingContext = new BindingContext();
|
gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
|
if (dt.Rows.Count > 0)
|
{
|
gcMain1.DataSource = dt;
|
gcMain1.ForceInitialize();
|
gridView1.BestFitColumns(); UtilityHelper.SetGridLayout(gridView1);
|
}
|
else
|
SetDefaultTableSafe();
|
gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
|
pageBar1.TotalPages = dd.rtnData.pages;
|
pageBar1.CurrentPage = curPage;
|
pageBar1.RecordCount = dd.rtnData.total;
|
}
|
else
|
{
|
MsgHelper.ShowError("提示:" + dd.rtnMsg);
|
SetDefaultTableSafe();
|
}
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
private void getModel(string strGuid)
|
{
|
bool isEdit = toolBarMenu1.currentAction == "edit";
|
if (string.IsNullOrEmpty(strGuid))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
var _obj = new { guid = strGuid };
|
try
|
{
|
var strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
|
var _rtn = UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
var dy = _rtn.rtnData;
|
lbGuid.Text = strGuid;
|
UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit);
|
|
}
|
else
|
{
|
MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
}
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
private void SetDefaultTableSafe()
|
{
|
var dt = new DataTable();
|
foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView1.Columns)
|
{
|
var field = col.FieldName;
|
if (string.IsNullOrEmpty(field)) continue;
|
if (col.UnboundDataType == typeof(System.Boolean))
|
dt.Columns.Add(field, typeof(System.Boolean));
|
else
|
dt.Columns.Add(field, typeof(string));
|
}
|
gcMain1.BindingContext = new BindingContext();
|
gcMain1.DataSource = dt;
|
gcMain1.ForceInitialize();
|
gridView1.BestFitColumns();
|
}
|
}
|
}
|