using DevExpress.XtraGrid.Columns;
|
using Gs.DevApp.Entity;
|
using Gs.DevApp.ToolBox;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Dynamic;
|
using System.IO;
|
using System.Text;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.DevFrm.Work
|
{
|
public partial class Frm_Work01 : DevExpress.XtraEditors.XtraForm
|
{
|
string _webServiceName = "WorkCollect/";
|
string dianJianPath = "";//电检取值路径
|
string goodTag = "√";
|
string badTag = "×";
|
string fGxTouRu = "G001:投入";
|
string fGxDianJian = "G002:电检";
|
string fGxShouJian = "G003:水检";
|
string fGxZhongJian = "G004:终检";
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="_fGx">工序</param>
|
/// <param name="_fBc">班次</param>
|
/// <param name="_strinOther">目前为电检路径</param>
|
public Frm_Work01(string _fGx, string _fBc, string _strinOther)
|
{
|
InitializeComponent();
|
txt_gx.Text = _fGx;
|
txt_bc.Text = _fBc;
|
txt_dianJianPath.Text = _strinOther;
|
dianJianPath = _strinOther;
|
this.Text = "工序采集【" + _fGx + " - " + _fBc + "】";
|
addColumn();
|
txt_barCode.KeyDown += (s, e) =>
|
{
|
if (e.KeyCode == Keys.Enter) { addModel(goodTag); };
|
};
|
btnGood.Click += (s, e) =>
|
{
|
addModel(goodTag);
|
};
|
btnBad.Click += (s, e) =>
|
{
|
UcDictionarySelect frm = new UcDictionarySelect("工序不良描述", " a.s_type='工序不良描述' and pid<>'00000000-0000-0000-0000-000000000000'");
|
frm.UpdateParent += (ss, ee) =>
|
{
|
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
|
var lst = ee.DynamicList;
|
foreach (dynamic dym in lst)
|
{
|
if (stringBuilder.Length > 0)
|
stringBuilder.Append("|");
|
stringBuilder.Append(dym.dicTxt);
|
}
|
string _txt = stringBuilder.ToString();
|
if (string.IsNullOrEmpty(_txt))
|
{
|
Toast vm = new Toast(-1, "~当为不良时,请选择不良项目~");
|
vm.Show();
|
}
|
else
|
addModel(badTag, _txt);
|
};
|
frm.ShowDialog();
|
};
|
}
|
|
/// <summary>
|
/// 根据工序,构造不同类型的实体
|
/// </summary>
|
/// <param name="_barCode">条码</param>
|
/// <param name="_checkResult">结果</param>
|
/// <param name="_badDescription">不良描述</param>
|
/// <returns></returns>
|
private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "")
|
{
|
dynamic _obj = new ExpandoObject();
|
_obj.barCode = _barCode;
|
_obj.checkResult = _checkResult;//检测结果
|
_obj.processNo = txt_gx.Text.Trim();//工序
|
_obj.banCi = txt_bc.Text.Trim();//班次
|
_obj.gongWei = txt_gw.Text.Trim();//工位
|
_obj.badDescription = _badDescription.Trim();//不良描述
|
if (txt_gx.Text.Trim() == fGxTouRu)
|
{
|
return _obj;
|
}
|
//电检
|
if (txt_gx.Text.Trim() == fGxDianJian)
|
{
|
string TM = "";
|
string JD = "";
|
string JY = "";
|
string JN = "";
|
string XL = "";
|
string GV = "";
|
string JDV = "";
|
string JYV = "";
|
string JNV = "";
|
string XLV = "";
|
string GVV = "";
|
string myStr = File.ReadAllText(dianJianPath, Encoding.Default);
|
if (myStr == "")
|
{
|
return _obj;
|
}
|
JArray dsTemp = JArray.Parse(myStr);
|
foreach (var ss in dsTemp) //查找某个字段与值
|
{
|
TM = (((JObject)ss)["TiaoMa"] == null) ? "" : ((JObject)ss)["TiaoMa"].ToString();
|
JD = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["state"].ToString();
|
JY = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["state"].ToString();
|
JN = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["state"].ToString();
|
XL = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["state"].ToString();
|
GV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["state"].ToString();
|
JDV = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["value"].ToString().Replace(" ", ",");
|
JYV = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["value"].ToString().Replace(" ", ", ");
|
JNV = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["value"].ToString().Replace(" ", ", ");
|
XLV = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["value"].ToString().Replace(" ", ", ");
|
GVV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["value"].ToString().Replace(" ", ", ");
|
}
|
_obj.t001 = TM;
|
_obj.t002 = JD;
|
_obj.t003 = JY;
|
_obj.t004 = JN;
|
_obj.t005 = XL;
|
_obj.t006 = GV;
|
_obj.t007 = JDV;
|
_obj.t008 = JYV;
|
_obj.t009 = JNV;
|
_obj.t010 = XLV;
|
_obj.t011 = GVV;
|
//正式上线要清空文本数据
|
//File.WriteAllText(dianJianPath, "");
|
return _obj;
|
}
|
//水检
|
if (txt_gx.Text.Trim() == fGxShouJian)
|
{
|
string strCsl1 = "strCsl1";
|
string strSw1 = "strSw1";
|
string strCsl2 = "strCsl2";
|
string strSw2 = "strSw2";
|
string strCsl3 = "strCsl3";
|
string strSw3 = "strSw3";
|
string strCsl4 = "strCsl4";
|
string strSw4 = "strSw4";
|
string strCsl5 = "strCsl5";
|
string strSw5 = "strSw5";
|
string SJJG = "";
|
_obj.t002 = strCsl1;
|
_obj.t003 = strSw1;
|
_obj.t004 = strCsl2;
|
_obj.t005 = strSw2;
|
_obj.t006 = strCsl3;
|
_obj.t007 = strSw3;
|
_obj.t008 = strCsl4;
|
_obj.t009 = strSw4;
|
_obj.t010 = strCsl5;
|
_obj.t011 = strSw5;
|
// _obj.t012 = SJJG;这个待确定
|
return _obj;
|
}
|
|
if (txt_gx.Text.Trim() == fGxZhongJian)
|
{
|
return _obj;
|
}
|
return null;
|
}
|
|
/// <summary>
|
/// 上报实体
|
/// </summary>
|
/// <param name="_checkResult">结果:√</param>
|
/// <param name="_badDescription">不良描述</param>
|
private void addModel(string _checkResult, string _badDescription = "")
|
{
|
string _barCode = txt_barCode.Text.Trim();
|
if (string.IsNullOrEmpty(_barCode))
|
{
|
Toast vm = new Toast(-1, "~请先扫追溯码~");
|
vm.Show();
|
return;
|
}
|
dynamic _obj = getObj(_barCode, _checkResult, _badDescription);
|
//if (_obj == null)
|
//{
|
// Toast vm = new Toast(-1, "~读取数据失败,请检查设备~");
|
// vm.Show();
|
// return;
|
//}
|
try
|
{
|
string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
|
ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
dynamic dy = _rtn.rtnData;
|
//表头和汇总
|
UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, false);
|
lbSum1.Text = dy.lbSum1;
|
lbSum2.Text = dy.lbSum2;
|
lbSum3.Text = dy.lbSum3;
|
lbSum4.Text = dy.lbSum4;
|
prog1.Position = dy.jd;
|
//良品列表
|
txt_barCode.ReadOnly = false;
|
JObject _job = JObject.Parse(strJson);
|
JArray array = new JArray();
|
foreach (var a in _job["rtnData"]["list"])
|
{
|
array.Add(a);
|
}
|
DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
|
if (dt.Rows.Count > 0)
|
{
|
gcMx1.BindingContext = new BindingContext();
|
gcMx1.DataSource = dt;
|
gcMx1.ForceInitialize();
|
gvMx1.BestFitColumns();
|
Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1);
|
}
|
else
|
{
|
Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
|
}
|
//不良品列表
|
JArray array2 = new JArray();
|
foreach (var a in _job["rtnData"]["list2"])
|
{
|
array2.Add(a);
|
}
|
DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString());
|
if (dt2.Rows.Count > 0)
|
{
|
gcMx2.BindingContext = new BindingContext();
|
gcMx2.DataSource = dt2;
|
gcMx2.ForceInitialize();
|
gvMx2.BestFitColumns();
|
Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx2);
|
}
|
else
|
{
|
Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx2, gvMx2);
|
}
|
string _msg = _rtn.rtnMsg;
|
if (!string.IsNullOrEmpty(_msg))
|
{
|
Toast vm = new Toast((goodTag == "√" ? 1 : -1), _msg);
|
vm.Show();
|
};
|
}
|
else
|
{
|
Toast vm = new Toast(-1, _rtn.rtnMsg);
|
vm.Show();
|
}
|
}
|
catch (Exception ex)
|
{
|
Toast vm = new Toast(-1, ex.Message);
|
vm.Show();
|
}
|
}
|
|
/// <summary>
|
/// 增加电检取数的列
|
/// </summary>
|
public void addColumn()
|
{
|
List<dynamic> _lst = new List<dynamic>();
|
if (txt_gx.Text.Trim() == fGxDianJian)
|
{
|
_lst.Add(new
|
{
|
ziduan = "t002",
|
wenben = "接地",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t004",
|
wenben = "交耐",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t005",
|
wenben = "泄漏",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t006",
|
wenben = "功率",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t007",
|
wenben = "接地结果",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t009",
|
wenben = "交耐结果",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t010",
|
wenben = "泄漏结果",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
|
_lst.Add(new
|
{
|
ziduan = "t011",
|
wenben = "功率结果",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
}
|
if (txt_gx.Text.Trim() == fGxShouJian)
|
{
|
_lst.Add(new
|
{
|
ziduan = "t002",
|
wenben = "出水量1",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t003",
|
wenben = "水温1",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t004",
|
wenben = "出水量2",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t005",
|
wenben = "水温2",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t006",
|
wenben = "出水量3",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t007",
|
wenben = "水温3",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t008",
|
wenben = "出水量4",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t009",
|
wenben = "水温4",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
|
_lst.Add(new
|
{
|
ziduan = "t010",
|
wenben = "出水量5",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
_lst.Add(new
|
{
|
ziduan = "t011",
|
wenben = "水温5",
|
kejian = true,
|
visibleIndex = 1,
|
});
|
}
|
foreach (var item in _lst)
|
{
|
GridColumn newColumn = new GridColumn();
|
newColumn.FieldName = item.ziduan; // 设置与数据源对应的字段名
|
newColumn.Caption = item.wenben; // 设置列的标题
|
//newColumn.Visible = item.visibleIndex; // 设置列是否可见
|
newColumn.VisibleIndex = item.visibleIndex; // 设置列的显示顺序
|
gvMx1.Columns.Add(newColumn);
|
}
|
}
|
}
|
}
|