| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.Mcp.Mch.Mcms.entity;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.Misc;
- using Infragistics.Win.UltraWinListView;
- using Infragistics.Win.UltraWinTabControl;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.SS.Util;
- using BorderStyle = NPOI.SS.UserModel.BorderStyle;
- namespace Core.StlMes.Client.Mcp.Mch.Mcms
- {
- public partial class frmLocalTruckScale : FrmBase
- {
- private static readonly string _path = Environment.CurrentDirectory + "\\data\\SerialPort.xml";
- private frmMessage _frmMessage;
- private SerialPortEntity _serialPortEntity;
- private List<CmmRecordTemplateEntity> _templateList;
- private CmmPoundBaseEntity cmmPoundBase;
- private List<CmmInputRecordEntity> _cmmInputRecordEntities;
- private bool isLoading = true;
- public frmLocalTruckScale()
- {
- InitializeComponent();
- this.IsLoadUserView = true;
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- tbFirstWt.Controls.OfType<UltraTabPageControl>()
- .SelectMany(p => p.Controls.OfType<MatInfo>())
- .ToList()
- .ForEach(p => p.ini(ob));
- tbOther.Controls.OfType<UltraTabPageControl>()
- .SelectMany(p => p.Controls.OfType<MatInfo>())
- .ToList()
- .ForEach(p => p.ini(ob));
- matInfo15.ini(ob);
- matInfo16.ini(ob);
- tbWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
- tbFirstWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
- tbScondWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
- tbOther.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
- _serialPortEntity = new SerialPortEntity(new TruckScaleProtocol(null))
- {
- StrBaudRate = XmlHelper.GetXmlData(_path, "StrBaudRate", "9600"),
- StrDataBits = XmlHelper.GetXmlData(_path, "StrDataBits", "8"),
- StrParity = XmlHelper.GetXmlData(_path, "StrParity", "NONE"),
- StrStopBits = XmlHelper.GetXmlData(_path, "StrStopBits", "ONE"),
- PortName = XmlHelper.GetXmlData(_path, "PortName", "COM1")
- };
- cboNo.DataSource = EntityHelper.GetData<CmmPoundBaseEntity>(
- "com.steering.Mcms.PoundBaseServer.getPoudInfo",
- new object[] {this.ValidDataPurviewIds},
- ob);
- List<CmmPoundBaseEntity> list = EntityHelper.GetData<CmmPoundBaseEntity>(
- "com.steering.Mcms.PoundBaseServer.getPoudInfo",
- new object[] { new string[]{} },
- ob);
- cboPoundList.DataSource = new List<string>() {""}.Concat(list.Select(p=>p.PoundNo)).ToList();
- cboNo.DisplayMember = "PoundNo";
- if (cboNo.Items.Count > 0)
- {
- cboNo.SelectedIndex = 0;
- cboPoundList.Text = cboNo.Text;
- }
- baudRate.Text = _serialPortEntity.StrBaudRate;
- cmbCom.Text = _serialPortEntity.PortName;
- CurrentGrid.DisplayLayout.Override.ActiveCellRowSelectorAppearance.BackColor = Color.ForestGreen;
- _serialPortEntity.ReceiveData += (sender, data, message, type) => ShowMessage(data, message, type);
- RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
- RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- LoadRecord();
- /* var source = new AutoCompleteStringCollection();
- source.AddRange( _cmmInputRecordEntity.Where(p => p.RecordType == "1")
- .Select(p => p.RecordValue).ToArray());*/
- utbConnect_Click(null, null);
- LoadTempate();
-
- Query();
- Query2();
- }
- private void LoadRecord()
- {
- var dic = new Dictionary<string, object>();
- dic.Add("recordType","1");
- List<CmmInputRecordEntity> datas = EntityHelper.GetData<CmmInputRecordEntity>(
- "com.steering.Mcms.InputRecordServer.doQuery",
- new object[] {dic},
- ob);
- txtCar2.DataSource = datas.Where(p => p.RecordType == "1")
- .Select(p => p.RecordValue).Distinct().ToList();
- txtCar2.Text = "";
- dic = new Dictionary<string, object>();
- dic.Add("recordType", new List<string>() { "2", "7", "8", "9" });
- _cmmInputRecordEntities = EntityHelper.GetData<CmmInputRecordEntity>(
- "com.steering.Mcms.InputRecordServer.doQuery",
- new object[] { dic },
- ob);
- }
- private void utbConnect_Click(object sender, EventArgs e)
- {
- if (_serialPortEntity == null) return;
- if ((_serialPortEntity != null) && _serialPortEntity.IsOpen)
- {
- _serialPortEntity.Stop();
- }
- else
- {
- if (string.IsNullOrEmpty(cmbCom.Text))
- {
- if (sender == null) return;
- MessageBox.Show(@"端口号不能为空!");
- }
- if (string.IsNullOrEmpty(baudRate.Text))
- {
- if (sender == null) return;
- MessageBox.Show(@"端口速率不能为空!");
- }
- _serialPortEntity.Start();
- }
- }
- private void utbMessage_Click(object sender, EventArgs e)
- {
- _frmMessage = new frmMessage();
- _frmMessage.Show();
- }
- private void ShowMessage(object data, string message, DataType dataType)
- {
- if (dataType == DataType.ReceiveData)
- {
- double wt;
- if (double.TryParse(data.ToString2(), out wt))
- lblWtNow.SafeRefreshControl(() => { lblWtNow.Text = (wt/100d).ToString("0.00") + "t"; });
- }
- else if (dataType == DataType.Open)
- {
- utbConnect.Appearance.ForeColor = Color.Red;
- cmbCom.SafeRefreshControl(() => cmbCom.Enabled = false);
- baudRate.SafeRefreshControl(() => baudRate.Enabled = false);
- cboNo.SafeRefreshControl(() => cboNo.Enabled = false);
- }
- else if (dataType == DataType.Close)
- {
- utbConnect.Appearance.ForeColor = Color.Lime;
- cmbCom.SafeRefreshControl(() => cmbCom.Enabled = true);
- baudRate.SafeRefreshControl(() => baudRate.Enabled = true);
- cboNo.SafeRefreshControl(() => cboNo.Enabled = true);
- }
- else if (dataType == DataType.Error)
- {
- MessageBox.Show(message);
- }
- if ((_frmMessage != null) && !_frmMessage.IsDisposed)
- _frmMessage.SafeShowMsg(message, dataType);
- else
- _frmMessage = null;
- }
- private void utbShowWt_Click(object sender, EventArgs e)
- {
- string.Format("当前重量{0}", lblWt.Text.Replace("t", "吨")).Speak();
- }
- private void cmbCom_SelectedValueChanged(object sender, EventArgs e)
- {
- _serialPortEntity.PortName = cmbCom.Text;
- XmlHelper.SetXmlData(_path, "PortName", _serialPortEntity.PortName);
- }
- private void baudRate_SelectedValueChanged(object sender, EventArgs e)
- {
- _serialPortEntity.StrBaudRate = baudRate.Text;
- XmlHelper.SetXmlData(_path, "StrBaudRate", _serialPortEntity.StrBaudRate);
- }
- private void lblWtNow_Click(object sender, EventArgs e)
- {
- lblWt.Text = lblWtNow.Text;
- if (CurrentGrid.ActiveRow != null)
- {
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || ("" == current.CarNo)) return;
- if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
- if (tbScondWt.ActiveTab.Key == "3")
- {
- }
- else if (tbScondWt.ActiveTab.Key == "0")
- {
- }
- else
- {
- var matInfo = GetMatInfo();
- if (matInfo != null)
- {
- decimal wt, fwt;
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
- {
- if (wt - fwt > 0)
- matInfo.SetWt(wt - fwt);
- }
- }
- }
- }
- }
- private void utbShowCarNo_Click(object sender, EventArgs e)
- {
- if ((cbxCar1.SelectedIndex < 0) || string.IsNullOrWhiteSpace(txtCar2.Text)) return;
- string.Format(" {0}", cbxCar1.Text + txtCar2.Text).Speak();
- }
- private void chkGross_CheckedChanged(object sender, EventArgs e)
- {
- tbFirstWt.Visible = chkGross.Checked;
- utbSaveAsT.Visible = chkGross.Checked;
- }
- /// <summary>
- /// 一次称重保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void utbSave1_Click(object sender, EventArgs e)
- {
- if (cmmPoundBase==null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
-
- if (string.IsNullOrWhiteSpace(txtCar2.Text) || string.IsNullOrWhiteSpace(cbxCar1.Text))
- {
- MessageBox.Show(@"未录入车牌号!");
- return;
- }
- decimal wt;
- if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
- {
- MessageBox.Show(@"重量异常!");
- return;
- }
- var cmmWeightRecord = new CmmWeightRecordEntityFull();
- if (chkGross.Checked)
- {
- var matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
- if (matInfo != null) cmmWeightRecord = matInfo.GetData();
- }
- cmmWeightRecord.CarNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
- cmmWeightRecord.Recoder = UserInfo.GetUserName();
- cmmWeightRecord.RecordType = !chkGross.Checked ? "101" : tbFirstWt.ActiveTab.Key;
- cmmWeightRecord.WtType = chkGross.Checked ? "1" : "0";
- cmmWeightRecord.Validflag = "1";
- cmmWeightRecord.RecordWeight = wt;
- cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
- cmmWeightRecord.MatType = chkGross.Checked ? tbFirstWt.ActiveTab.Text : "";
- var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None, new JsonSerializerSettings
- {ContractResolver = new CamelCasePropertyNamesContractResolver()});
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.LocalTruckScale",
- MethodName = "DoAdd",
- ServerParams = new object[]
- {
- "",
- json
-
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
- {
- ccp.ReturnInfo.ToString2().Speak();
- lblWt.Text = "0.000t";
- LoadRecord();
- Query();
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.SetDefault(null);
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- }
- }
- /// <summary>
- /// 二次称重
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave2_Click(object sender, EventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- if (tbScondWt.ActiveTab == null) return;
- if (CurrentGrid.ActiveRow == null)
- {
- MessageBox.Show(@"请选择第一次称重记录");
- return;
- }
- decimal wt;
- if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
- {
- MessageBox.Show(@"重量异常!");
- return;
- }
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if (current == null) return;
- var key = GetKey();
- CmmWeightRecordEntityFull cmmWeightRecord;
- if ("207" == key)
- {
- cmmWeightRecord = new CmmWeightRecordEntityFull();
- cmmWeightRecord.WtType = "0";
- }
- else
- {
- var matInfo = GetMatInfo();
- if (matInfo == null) return;
- cmmWeightRecord = matInfo.GetData();
- cmmWeightRecord.WtType = "1";
- if (cmmWeightRecord.RecordNumber == null)
- {
- MessageBox.Show("数量不能为空!");
- return;
- }
-
- }
- string hookWtStr ="";
- if (key == "201")
- {
- if (cmmWeightRecord.MatInfos == null || !cmmWeightRecord.MatInfos.Any())
- {
- MessageBox.Show("无配送单信息!");
- return;
- }
- if (cmmWeightRecord.MatInfos.Any(p => p.ActWeight == null))
- {
- MessageBox.Show("有炉号没有钩子称重量!");
- return;
- }
- decimal hookWt = cmmWeightRecord.MatInfos.Select(p =>(decimal) p.ActWeight).Sum();
- hookWtStr = hookWt.ToString();
- decimal NetWt;
- decimal wt2, wt1;
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
- decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
- {
- NetWt = wt2 - wt1;
- }
- else
- {
- MessageBox.Show("数据异常!");
- return;
- }
- if (NetWt <= 0)
- {
- MessageBox.Show("净重小于0!");
- return;
- }
- cmmWeightRecord.RealWt = NetWt;
- if (Math.Abs(NetWt - hookWt)*1000/NetWt >= 5)
- {
- string msg = " 净重与钩子称 误差超过千分之5";
- msg.Speak();
- if (MessageUtil.ShowYesNoAndQuestion(" 净重: " + NetWt + "t 钩子称重量: " + hookWt + "t 磅差 " + (NetWt - hookWt) + "t 误差超过千分之5, 请确认是否继续保存 ?") == DialogResult.No)
- return;
- }
- }
- cmmWeightRecord.Recoder = UserInfo.GetUserName();
- cmmWeightRecord.RecordType = GetKey();
- cmmWeightRecord.Validflag = "2";
- cmmWeightRecord.RecordWeight = wt;
- cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
- cmmWeightRecord.CarNo = current.CarNo;
- cmmWeightRecord.MatType = GetMatType();
- if (("208" == cmmWeightRecord.RecordType) &&
- ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
- {
- MessageBox.Show(@"无废品出库信息,无法保存!");
- return;
- }
- if (("201" == cmmWeightRecord.RecordType) &&
- ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
- {
- MessageBox.Show(@"无装车单信息,无法保存!");
- return;
- }
- var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None,
- new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()});
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.LocalTruckScale",
- MethodName = "DoAdd",
- ServerParams = new object[]
- {
- current.RecordNo,
- hookWtStr,
- json
-
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
- {
- lblWt.Text = "0.000t";
- string[] result = ccp.ReturnInfo.ToString2().Split('|');
- result[0].Speak();
- if (result.Length > 1)
- {
- Print(result[1]);
- }
- LoadRecord();
- Query();
- Query2();
- //TODO 打印
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.SetDefault(null);
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
-
- }
- }
- private void Print(string resultNo,bool spilt = false)
- {
- var strurl =
- "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=" +
- (spilt?"RepThCattyListCut":"RepThCattyList") +
- ".cpt&RESULT_NO=" +
- resultNo;
- var fre = new FrmRepBrower(ob, strurl)
- {
-
- Size = new Size(900,
- 500)
- };
- fre.Show();
- }
- private void frmLocalTruckScale_FormClosed(object sender, FormClosedEventArgs e)
- {
- if ((_serialPortEntity != null) && _serialPortEntity.IsOpen)
- _serialPortEntity.Stop();
- }
- private void Query()
- {
- var dic = new Dictionary<string, object>();
- if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
- dic.Add("poundNo", cboPoundList.Text );
- dic.Add("validflag", new List<string>() { "1"});
- cmmWeightRecordEntityBindingSource.DataSource = EntityHelper.GetData<CmmWeightRecordEntity>(
- "com.steering.Mcms.RecordServer.doQueryRecord",
- new object[] { dic },
- ob);
- }
- private void LoadTempate()
- {
- if (cmmPoundBase == null)
- {
- return;
- }
- _templateList = EntityHelper.GetData<CmmRecordTemplateEntity>(
- "com.steering.Mcms.TemplateServer.doQueryTempate",
- new object[] { ""},
- ob);
- tbFirstWt_SelectedTabChanged(null, null);
- }
- private void utbSaveAsT_Click(object sender, EventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- if (tbWt.ActiveTab == null) return;
- var matInfo = GetMatInfo();
- if (matInfo != null)
- {
- var cmmWeightRecord = matInfo.GetData();
- string projectName;
- using (var fractureInfo = new ProjectName())
- {
- fractureInfo.ShowDialog();
- if (fractureInfo.DialogResult != DialogResult.OK) return;
- projectName = fractureInfo.ProjectNameStr;
- }
- var template = new CmmRecordTemplateEntity
- {
- CreateUser = UserInfo.GetUserName(),
- TemplateKey = GetKey(),
- TemplateLocation = cmmPoundBase.PoundNo,
- TemplateXml = cmmWeightRecord.ToString(),
- TemplateName = projectName
- };
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.TemplateServer",
- MethodName = "DoSaveTemplateNo",
- ServerParams = new object[]
- {
- JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
- {ContractResolver = new CamelCasePropertyNamesContractResolver()})
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("保存成功!"))
- LoadTempate();
- }
- }
- }
- private MatInfo GetMatInfo()
- {
- MatInfo matInfo = null;
- if (tbWt.ActiveTab == null) return null ;
- if (tbWt.ActiveTab.Key == "1" && tbFirstWt.ActiveTab!=null)
- matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
- else if ( (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
- (tbOther.ActiveTab != null))
- matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "3"))
- matInfo = matInfo15;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0"))
- matInfo = matInfo16;
- return matInfo;
- }
- private MatInfo GetMatInfoByKey(string key)
- {
- MatInfo matInfo = null;
- foreach (var ultraTab in tbFirstWt.Tabs)
- {
- var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p=>p.Key == key) .ToList();
- if (matinfo.Any()) return matinfo[0];
- }
- foreach (var ultraTab in tbOther.Tabs)
- {
- var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
- if (matinfo.Any()) return matinfo[0];
-
- }
- if (key == "201") return matInfo16;
-
- return matInfo;
- }
- private void utbDelete_Click(object sender, EventArgs e)
- {
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.DeleteRow();
- }
- private void utbClear_Click(object sender, EventArgs e)
- {
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.Clear();
- }
- private void tbFirstWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
- {
- LoadTem();
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.Clear();
- if (CurrentGrid.ActiveRow != null)
- {
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || ("" == current.CarNo)) return;
- if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
- if (tbScondWt.ActiveTab.Key == "3")
- {
- }
- else if (tbScondWt.ActiveTab.Key == "0")
- {
- }
- else
- {
- if (matInfo != null)
- {
- decimal wt, fwt;
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
- {
- if (wt - fwt > 0)
- matInfo.SetWt(wt - fwt);
- }
- }
- }
- }
- }
- private void LoadTem()
- {
- if (_templateList == null) return;
- var key = GetKey();
- if (string.IsNullOrWhiteSpace(key)) return;
- if (_cmmInputRecordEntities != null && _cmmInputRecordEntities.Any())
- {
- MatInfo matInfo = GetMatInfo();
- if (matInfo != null)
- {
- matInfo.iniMatName(_cmmInputRecordEntities.Where(p => p.RecordKey == key || string.IsNullOrWhiteSpace(p.RecordKey)).ToList());
- }
- }
- lvTemplate.Items.Clear();
- lvTemplate.Items.AddRange(_templateList.Where(p => p.TemplateKey == key)
- .Select(p =>
- {
- var
- temp =
- new UltraListViewItem(p.TemplateName, null, null) {Key = p.TemplateNo};
- try
- {
- temp.Tag =
- XmlHelper.FromXElement<CmmWeightRecordEntityFull>(XElement.Parse(p.TemplateXml));
- }
- catch (Exception)
- {
- // ignored
- }
- return temp;
- }
- ).
- ToArray()
- );
- }
- private string GetKey()
- {
- return tbWt.ActiveTab.Key == "1"
- ? (tbFirstWt.ActiveTab == null ? "" : tbFirstWt.ActiveTab.Key)
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
- (tbOther.ActiveTab != null)
- ? tbOther.ActiveTab.Key
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
- ? "201"
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2")
- ? "207"
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "3")
- ? "208"
- : "";
- }
- private string GetMatType()
- {
- return tbWt.ActiveTab.Key == "1"
- ? ""
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
- (tbOther.ActiveTab != null)
- ? tbOther.ActiveTab.Text
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
- ? "钢管发运"
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2")
- ? ""
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "3")
- ? "其它内转"
- : "";
- }
- private void lvTemplate_MouseClick(object sender, MouseEventArgs e)
- {
- var listView = sender as UltraListView;
- if (e.Button == MouseButtons.Right)
- {
- var itemAtPoint = lvTemplate.ItemFromPoint(e.Location);
- if (itemAtPoint != null)
- {
- lvTemplate.ContextMenuStrip = listViewMenuStrip;
- ISelectionManager selectionManager = listView;
- if (selectionManager != null) selectionManager.SelectItem(itemAtPoint, true);
- itemAtPoint.Activate();
- }
- }
- }
- private void deleteTemplate_Click(object sender, EventArgs e)
- {
- if (lvTemplate.ActiveItem == null) return;
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.TemplateServer",
- MethodName = "DoDeleteTemplate",
- ServerParams = new object[]
- {
- lvTemplate.ActiveItem.Key,
- UserInfo.GetUserName()
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("删除成功!"))
- LoadTempate();
- }
- }
- private void CurrentGrid_AfterRowActivate(object sender, EventArgs e)
- {
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || ("" == current.CarNo)) return;
- if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
- if (tbScondWt.ActiveTab.Key == "3")
- ShowWasteInfo(current.CarNo);
- else if (tbScondWt.ActiveTab.Key == "0")
- ShowLoadvehicleInfo(current.CarNo);
- else
- {
- var matInfo = GetMatInfo();
- if (matInfo != null)
- {
- decimal wt,fwt;
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) && decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
- {
- if (wt-fwt>0)
- matInfo.SetWt(wt - fwt);
- }
- }
- }
-
- }
- // 显示废品信息
- public void ShowWasteInfo(string carNo)
- {
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryWasteInfo", new object[] { carNo }, ob);
- if ((dt != null) && (dt.Rows.Count > 0))
- {
- cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
- cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
- cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
- cmmWeightRecordEntityFull.MatName = "废品管";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>
- {
- new CmmWeightMatEntity {ActCount = cmmWeightRecordEntityFull.RecordNumber}
- };
- }
- matInfo15.SetDefault(cmmWeightRecordEntityFull);
- }
- //显示装车单信息
- public void ShowLoadvehicleInfo(string carNo)
- {
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- var dt = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleInfo",
- new object[] {carNo}, ob);
- if ((dt != null) && (dt.Rows.Count > 0))
- {
- cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
- cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["LOADVEHICLE_NO"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["RECEIV_NM"].ToString2();
- cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["STACKING_PIECE"].ToString3());
- cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
- cmmWeightRecordEntityFull.OrderName = dt.Rows[0]["CUSTOMER_NM"].ToString2();
- cmmWeightRecordEntityFull.MatName = "钢管";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
- var dtc = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleMatInfo",
- new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
- if ((dtc != null) && (dtc.Rows.Count > 0))
- foreach (DataRow dtcRow in dtc.Rows)
- {
- var cmmWeightMatEntity = new CmmWeightMatEntity
- {
- StorageNo = dtcRow["STORAGE_NO"].ToString2(),
- StorageName = dtcRow["STORAGE_NAME"].ToString2(),
- StoveNo = dtcRow["STOVE_NO"].ToString2(),
- OrderNo = dtcRow["ORDER_NO"].ToString2(),
- OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
- OrderSeqNo = dtcRow["ORDER_SEQ_NO"].ToString2(),
- ProOrderNo = dtcRow["ORDER_NO"].ToString2() + "/" +
- dtcRow["ORDER_SEQ"].ToString2(),
- Produccode = dtcRow["PRODUCCODE"].ToString2(),
- Producname = dtcRow["PRODUCNAME"].ToString2(),
- StdCode = dtcRow["STD_CODE"].ToString2(),
- StdName = dtcRow["STD_NAME"].ToString2(),
- Gradecode = dtcRow["GRADECODE"].ToString2(),
- Gradename = dtcRow["GRADENAME"].ToString2(),
- Steelcode = dtcRow["STEELCODE"].ToString2(),
- Steelname = dtcRow["STEELNAME"].ToString2(),
- SpecCode = dtcRow["SPEC_CODE"].ToString2(),
- SpecName = dtcRow["SPEC_NAME"].ToString2(),
- ModelCode = dtcRow["MODEL_CODE"].ToString2(),
- ModelDesc = dtcRow["MODEL_DESC"].ToString2(),
- ActLenMin = decimal.Parse(dtcRow["ACT_LEN_MIN"].ToString3()),
- ActLenMax = decimal.Parse(dtcRow["ACT_LEN_MAX"].ToString3()),
- ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
- dtcRow["ACT_LEN_MAX"].ToString3(),
- ActWeight = decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3()),
- ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
- JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
- ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
- ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
- };
- cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
- }
- try
- {
- var dth = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryHook",
- new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
- if ((dth != null) && (dth.Rows.Count > 0))
- {
- foreach (DataRow dthRow in dth.Rows)
- {
- double total = double.Parse(dthRow["HOOK_WEIGHT"].ToString3());
- double num = int.Parse(cmmWeightRecordEntityFull.MatInfos.Where(
- p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
- .Select(p => p.ActCount)
- .Sum()
- .ToString3());
- double perWt = Math.Round(total/num, 3);
- List<CmmWeightMatEntity> list = cmmWeightRecordEntityFull.MatInfos.Where(
- p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2()).ToList();
- for (var i = 0; i < list.Count; i++)
- {
- if (i == 0)
- list[i].ActWeight =
- decimal.Parse(
- (total - perWt*(num- double.Parse(list[i].ActCount.ToString3()))).ToString3());
- else
- list[i].ActWeight =
- decimal.Parse(
- (perWt * double.Parse(list[i].ActCount.ToString3())).ToString3());
- }
- }
-
- }
- }
- catch (Exception)
- {
-
- }
- }
- else
- {
- cmmWeightRecordEntityFull = null;
- }
- matInfo16.SetDefault(cmmWeightRecordEntityFull);
- }
- private void tbScondWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
- {
- if (CurrentGrid.ActiveRow != null)
- {
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if (current != null)
- if (tbScondWt.ActiveTab.Key == "3")
- ShowWasteInfo(current.CarNo);
- else if (tbScondWt.ActiveTab.Key == "0")
- ShowLoadvehicleInfo(current.CarNo);
- }
- LoadTem();
- }
- private void utnQuery_Click(object sender, EventArgs e)
- {
- Query2();
- }
- private void Query2()
- {
- var dic = new Dictionary<string, object>();
- if (chkTim.Checked)
- {
- dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
- dic.Add("time1", RegEndTime.Value.ToString("yyy-MM-dd HH:mm:ss"));
- }
- dic.Add("carNo", uteCarNo.Text);
- dic.Add("matType", uceQueryCarType.Text);
- if (uceValidflag.CheckedItems.Count > 0)
- dic.Add("validflag", uceValidflag.CheckedItems.Select(p => p.DataValue.ToString()).ToList());
- dic.Add("orderName", uteOrder.Text);
- dic.Add("shippersName", uteShippersName.Text);
- dic.Add("receiveName", uteReceiveName.Text);
- dic.Add("memo", uteMemo.Text);
- QueryBS.DataSource = EntityHelper.GetData<CmmWeightResultEntity>(
- "com.steering.Mcms.ResultServer.doQuery",
- new object[] {dic},
- ob);
- }
- private void tbMain_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
- {
- if (tbMain.SelectedTab.Key == "1")
- Query();
- else
- Query2();
- }
- private void utbReset_Click(object sender, EventArgs e)
- {
- RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
- RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
- uteCarNo.Text = "";
- uceQueryCarType.Text = "";
- foreach (var uceValidflagItem in uceValidflag.Items)
- uceValidflagItem.CheckState = uceValidflagItem.DataValue.ToString2() == "1"
- ? CheckState.Checked
- : CheckState.Unchecked;
- uteOrder.Text = "";
- uteShippersName.Text = "";
- uteReceiveName.Text = "";
- uteMemo.Text = "";
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null) return;
- UltraButton ub = (sender as UltraButton);
- if(ub==null) return;
- if (MessageUtil.ShowYesNoAndQuestion("是否" + ub.Text + "过磅单?") == DialogResult.No)
- return;
- var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if (data == null) return;
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.LocalTruckScale",
- MethodName = "DoDeleteResult",
- ServerParams = new object[]
- {
- data.ResultNo,
- UserInfo.GetUserName(),
- "重过"==ub.Text?"2":"1"
-
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("操作成功!"))
- {
- Query2();
- Query();
- }
- }
- }
-
- private void cboNo_SelectedValueChanged(object sender, EventArgs e)
- {
- if(cboNo.SelectedIndex<0) return;
- cmmPoundBase = cboNo.SelectedItem as CmmPoundBaseEntity;
-
- CmmBaseProtocolEntity cmmBaseProtocol = null;
- if (cmmPoundBase != null)
- {
- List<CmmBaseProtocolCEntity> protocols = EntityHelper.GetData<CmmBaseProtocolCEntity>(
- "com.steering.Mcms.ProcotolServer.getProcotolId",
- new object[] {cmmPoundBase.PoundProtocolId},
- ob);
- if (protocols != null && protocols.Any())
- {
- cmmBaseProtocol = new CmmBaseProtocolEntity()
- {
- ProtocolId = cmmPoundBase.PoundProtocolId,
- ListC = protocols
- };
- }
- cboPoundList.Text = cmmPoundBase.PoundNo;
- }
- _serialPortEntity.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol));
- }
- private void lvTemplate_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
- {
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.SetDefault(e.Item.Tag as CmmWeightRecordEntityFull, e.Item.Text);
- }
- private void cboPoundList_SelectedValueChanged(object sender, EventArgs e)
- {
- Query();
- }
- private void delete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || ("" == current.CarNo)) return;
- if (MessageUtil.ShowYesNoAndQuestion("是否删除" + current.CarNo + " 过磅记录?") == DialogResult.No)
- return;
-
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.RecordServer",
- MethodName = "DoUpdateRecord",
- ServerParams = new object[]
- {
- current.RecordNo
-
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
- {
- Query();
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- }
- }
- private void ugData_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
- {
- var data = e.Row.ListObject as CmmWeightResultEntity;
- if(data==null) return;
- if(data.RecordType2=="201") e.Row.Appearance.BackColor = Color.ForestGreen;
-
- }
- private void uteCarNo_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 13 )
- {
- Query2();
- }
- }
- private void utnUpdate_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null)
- {
- MessageBox.Show("请选择需要修改磅单记录!");
- return;
- }
- CmmWeightResultEntity cmm = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- MatInfo matInfo = GetMatInfoByKey("101" == cmm.RecordType1? cmm.RecordType2:cmm.RecordType1 );
- if (matInfo == null)
- {
- MessageBox.Show("该类型不允许修改!");
- return;
- }
- using (var frmUpdate = new FrmUpdate(ob, cmm.ResultNo, "101" == cmm.RecordType1
- ? cmm.RecordNo2
- : cmm.RecordNo1)
- {
- ColumnsM = matInfo.ColumnsM,
- ColumnsC = matInfo.ColumnsC
- })
- {
- frmUpdate.ShowDialog();
- if (frmUpdate.DialogResult == DialogResult.OK)
- {
- Query2();
- }
- }
- }
- private void utbPrint_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null) return;
-
- var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if (data == null) return;
- Print(data.ResultNo);
- }
- private void utbPrintSingle_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null) return;
- var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if (data == null) return;
- Print(data.ResultNo,true);
- }
- private void unExcel_Click(object sender, EventArgs e)
- {
- HSSFWorkbook hssfworkbook = new HSSFWorkbook();
- ISheet sheet = hssfworkbook.CreateSheet("磅房统计");
- int index = 0;
- SetHead(sheet, hssfworkbook, index++);
- SetHeadRow(sheet, hssfworkbook
- , new List<string>() {"磅房号", "称重类型", "物资名称", "物资数量", "称重次数", "物资净重"},
- new List<int>() {9, 15, 25, 15, 15, 15},
- index++
- );
- setData(sheet, hssfworkbook, ref index);
- SetSumm(sheet, index, hssfworkbook);
- sheet.ForceFormulaRecalculation = true;
- hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
- using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
- {
- saveFileDialog1.FileName = "磅房统计" + DateTime.Now.ToString("yyMMdd");
- saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string sFullName = saveFileDialog1.FileName;
- MemoryStream ms = new MemoryStream();
- hssfworkbook.Write(ms);
- using (FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
- {
- byte[] bArr = ms.ToArray();
- fs.Write(bArr, 0, bArr.Length);
- fs.Flush();
- }
-
- ProcessStartInfo p = new ProcessStartInfo(sFullName);
- p.WorkingDirectory = Path.GetDirectoryName(sFullName);
- Process.Start(p);
- }
- }
-
-
- }
- private void SetSumm(ISheet sheet, int index, HSSFWorkbook hssfworkbook)
- {
- IRow IRow = sheet.CreateRow(index);
- IRow.Height = 20*20;
- ICell Icell1 = IRow.CreateCell(1);
- Icell1.SetCellValue("合计");
- var style = CenterStyle(hssfworkbook);
- var font = ContextFont(hssfworkbook);
- style.SetFont(font);
- style.BorderTop = BorderStyle.Medium;
- style.BorderBottom = BorderStyle.Medium;
- style.BorderLeft = BorderStyle.Medium;
- style.BorderRight = BorderStyle.Thin;
- //将新的样式赋给单元格
- Icell1.CellStyle = style;
- ICell Icell12 = IRow.CreateCell(2);
- var style12 = CenterStyle(hssfworkbook);
- style12.SetFont(font);
- style12.BorderTop = BorderStyle.Medium;
- style12.BorderBottom = BorderStyle.Medium;
- style12.BorderLeft = BorderStyle.Thin;
- style12.BorderRight = BorderStyle.Thin;
- //将新的样式赋给单元格
- Icell12.CellStyle = style12;
- ICell Icell13 = IRow.CreateCell(3);
- var style13 = CenterStyle(hssfworkbook);
- style13.SetFont(font);
- style13.BorderTop = BorderStyle.Medium;
- style13.BorderBottom = BorderStyle.Medium;
- style13.BorderLeft = BorderStyle.Thin;
- style13.BorderRight = BorderStyle.Thin;
- //将新的样式赋给单元格
- Icell13.CellStyle = style13;
- //合并单元格
- sheet.AddMergedRegion(new CellRangeAddress(index, index, 1, 3));
- List<string> list = new List<string>();
- for (int i = 2; i < index; i++)
- {
- list.Add(i + 1 + "");
- }
- ICell Icell2 = IRow.CreateCell(4);
- if (list.Any())
- {
- Icell2.SetCellType(CellType.Formula);
- Icell2.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "E" + p).ToList())));
- hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell2);
- }
- var style2 = numStyle(hssfworkbook);
- var font2 = ContextFont(hssfworkbook);
- style2.SetFont(font2);
- style2.BorderTop = BorderStyle.Medium;
- style2.BorderBottom = BorderStyle.Medium;
- style2.BorderLeft = BorderStyle.Thin;
- style2.BorderRight = BorderStyle.Thin;
- //将新的样式赋给单元格
- Icell2.CellStyle = style2;
- ICell Icell3 = IRow.CreateCell(5);
- if (list.Any())
- {
- Icell3.SetCellType(CellType.Formula);
- Icell3.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "F" + p).ToList())));
- hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell3);
- }
- var style3 = numStyle(hssfworkbook);
- var font3 = ContextFont(hssfworkbook);
- style3.SetFont(font3);
- style3.BorderTop = BorderStyle.Medium;
- style3.BorderBottom = BorderStyle.Medium;
- style3.BorderLeft = BorderStyle.Thin;
- style3.BorderRight = BorderStyle.Thin;
- //将新的样式赋给单元格
- Icell3.CellStyle = style3;
- ICell Icell4 = IRow.CreateCell(6);
- if (list.Any())
- {
- Icell4.SetCellType(CellType.Formula);
- Icell4.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "G" + p).ToList())));
- hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell4);
- }
- var style4 = numStyle(hssfworkbook);
- var font4 = ContextFont(hssfworkbook);
- style4.SetFont(font4);
- style4.BorderTop = BorderStyle.Medium;
- style4.BorderBottom = BorderStyle.Medium;
- style4.BorderLeft = BorderStyle.Thin;
- style4.BorderRight = BorderStyle.Medium;
- //将新的样式赋给单元格
- Icell4.CellStyle = style4;
- }
- private void setData(ISheet sheet, HSSFWorkbook hssfworkbook, ref int index)
- {
- int index1 = index;
- List<CmmWeightResultEntity> data = QueryBS.DataSource as List<CmmWeightResultEntity>;
- if (data != null && data.Any())
- {
- data.GroupBy(p => new {p.RecoderLocation2, p.MatName, p.MatType})
- .Select(p => new
- {
- p.Key.MatName,
- p.Key.MatType,
- p.Key.RecoderLocation2,
- count = p.Count(),
- num = int.Parse(p.Select(q => q.MatNum ?? 0).Sum().ToString3()),
- wt = double.Parse( p.Select(q => q.NetWt).Sum().ToString3())
- }).ToList()
- .ForEach(
- p =>
- {
- IRow IRow = sheet.CreateRow(index1++);
- IRow.Height = 20*20;
- for (int i = 0; i < 6; i++)
- {
- ICell Icell = IRow.CreateCell(i + 1);
- if (i <= 2)
- {
- Icell.SetCellType(CellType.String);
- Icell.SetCellValue(
- i == 0
- ? p.RecoderLocation2
- : i == 1
- ? p.MatType:
- p.MatName);
- }
- else
- {
- Icell.SetCellType(CellType.Numeric);
- if (i == 3)
- {
- Icell.SetCellValue(p.num);
- }
- if (i == 4)
- {
- Icell.SetCellValue(p.count);
- }
- if (i == 5)
- {
- Icell.SetCellValue(p.wt);
- }
- };
- var style = i <= 2 ? textStyle(hssfworkbook) : numStyle(hssfworkbook);
- style.BorderTop = BorderStyle.Thin;
- style.BorderBottom = BorderStyle.Thin;
- style.BorderLeft =i==0?BorderStyle.Medium : BorderStyle.Thin;
- style.BorderRight = i == 5 ? BorderStyle.Medium : BorderStyle.Thin;
- var font = ContextFont(hssfworkbook);
- //使用SetFont方法将字体样式添加到单元格样式中
- style.SetFont(font);
- //将新的样式赋给单元格
- Icell.CellStyle = style;
- }
- }
- );
- }
- index = index1;
- }
- private void SetHeadRow(ISheet sheet, HSSFWorkbook hssfworkbook,List<string> name,List<int> columsWidth,int rowIndex )
- {
- IRow IRow = sheet.CreateRow(rowIndex);
- IRow.Height = 20 * 20;
- for (int i = 0; i < name.Count; i++)
- {
- sheet.SetColumnWidth(i + 1, columsWidth[i] * 256);
-
- ICell Icell = IRow.CreateCell(i+1);
- Icell.SetCellValue(name[i]);
- var style = CenterStyle(hssfworkbook);
- style.BorderTop = BorderStyle.Medium;
- style.BorderBottom = BorderStyle.Medium;
- style.BorderLeft = BorderStyle.Medium;
- style.BorderRight = BorderStyle.Medium;
- var font = ContextFont(hssfworkbook);
- //使用SetFont方法将字体样式添加到单元格样式中
- style.SetFont(font);
- //将新的样式赋给单元格
- Icell.CellStyle = style;
- }
-
- }
- private void SetHead(ISheet sheet, HSSFWorkbook hssfworkbook,int rowindex)
- {
- IRow IRow = sheet.CreateRow(rowindex);
- IRow.Height = 50*20;
- ICell Icell = IRow.CreateCell(1);
- Icell.SetCellValue("磅房统计");
- var style = CenterStyle(hssfworkbook);
- var font = TitleFont(hssfworkbook);
- //使用SetFont方法将字体样式添加到单元格样式中
- style.SetFont(font);
- //将新的样式赋给单元格
- Icell.CellStyle = style;
- //合并单元格
- sheet.AddMergedRegion(new CellRangeAddress(0, 0, 1, 6));
- }
- private static IFont TitleFont(HSSFWorkbook hssfworkbook)
- {
- //新建一个字体样式对象
- IFont font = hssfworkbook.CreateFont();
- font.FontName = "宋体";
- font.FontHeightInPoints = 30;
- //设置字体加粗样式
- font.Boldweight = (short) FontBoldWeight.Bold;
- return font;
- }
- private static IFont ContextFont(HSSFWorkbook hssfworkbook)
- {
- //新建一个字体样式对象
- IFont font = hssfworkbook.CreateFont();
- font.FontName = "宋体";
- font.FontHeightInPoints = 12;
- //设置字体加粗样式
- font.Boldweight = (short)FontBoldWeight.Bold;
- return font;
- }
- private ICellStyle CenterStyle(HSSFWorkbook hssfworkbook)
- {
- ICellStyle style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private ICellStyle textStyle(HSSFWorkbook hssfworkbook)
- {
- ICellStyle style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private ICellStyle numStyle(HSSFWorkbook hssfworkbook)
- {
- ICellStyle style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Right;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private void CurrentGrid_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
- {
- }
- private void CurrentGrid_DoubleClickCell(object sender, Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs e)
- {
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || ("" == current.CarNo)) return;
- foreach (var cbxCar1Item in cbxCar1.Items)
- {
- if (current.CarNo.StartsWith(cbxCar1Item.ToString2().Trim()))
- {
- cbxCar1.SelectedItem = cbxCar1Item;
- txtCar2.Text = current.CarNo.Replace(cbxCar1Item.ToString2().Trim(),"").Trim();
- }
- }
- if (!tbWt.Tabs["2"].Selected)
- {
- tbWt.Tabs["2"].Selected = true;
- tbScondWt_SelectedTabChanged(null, null);
- }
- }
- private void utbExport_Click(object sender, EventArgs e)
- {
- GridHelper.ulGridToExcel(ugData, "称重记录");
- }
- private void utbExport2_Click(object sender, EventArgs e)
- {
- GridHelper.ulGridToExcel(CurrentGrid, "称重记录");
- }
- private void cbxCar1_SelectedValueChanged(object sender, EventArgs e)
- {
- if (cbxCar1.Text.Trim() == "厂内")
- {
- txtCar2.Text = "自用车";
- }
- }
- private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
- {
- if (isLoading) return;
- XmlHelper.SetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
- }
- private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
- {
- if (isLoading) return;
- XmlHelper.SetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
- }
- private void frmLocalTruckScale_Shown(object sender, EventArgs e)
- {
- isLoading = false;
- splitContainer1.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
- splitContainer2.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
- FontConverter x = new FontConverter();
- CurrentGrid.Font = x.ConvertFromString(XmlHelper.GetXmlData(_path, CurrentGrid.Name,x.ConvertToString(CurrentGrid.Font))) as Font;
- ugData.Font = x.ConvertFromString(XmlHelper.GetXmlData(_path, ugData.Name, x.ConvertToString(ugData.Font))) as Font;
- }
- private void CurrentGrid_KeyPress(object sender, KeyPressEventArgs e)
- {
-
- }
- private void CurrentGrid_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.F5)
- {
- using (var dr = new FontDialog() { Font = (sender as System.Windows.Forms.Control).Font })
- {
- if (dr.ShowDialog() == DialogResult.OK)
- {
- (sender as System.Windows.Forms.Control).Font = dr.Font;
- FontConverter x = new FontConverter();
- string font = x.ConvertToString(dr.Font);
- // t = x.ConvertFromString(s) as Font;
- XmlHelper.SetXmlData(_path, (sender as System.Windows.Forms.Control).Name, font);
- }
- }
-
- }
- }
- private void txtCar2_TextChanged(object sender, EventArgs e)
- {
-
- foreach (var currentGridRow in CurrentGrid.Rows)
- {
- if (currentGridRow.Cells["CarNo"].Value.ToString2() == cbxCar1.Text + txtCar2.Text.Trim())
- {
- if (!tbWt.Tabs["2"].Selected)
- {
- tbWt.Tabs["2"].Selected = true;
- tbScondWt_SelectedTabChanged(null, null);
- }
- }
- }
- tbWt.Tabs["1"].Selected = true;
- }
-
- }
- }
|