| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Timers;
- 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.LgResMgt.Mcms.entity;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.Misc;
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid;
- 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;
- using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
- using Timer = System.Timers.Timer;
- using System.Net.Sockets;
- using System.Threading;
- using System.Text;
- using System.Collections;
- using Core.Mes.Client.Comm.Format;
- using System.Threading.Tasks;
- using NPOI.SS.Formula.Functions;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
- namespace Core.StlMes.Client.LgResMgt.Mcms
- {
- public partial class frmLocalTruckScaleNew : FrmBase
- {
- private static readonly string _path = Environment.CurrentDirectory + "\\data\\SerialPort.xml";
- private readonly Timer timer = new Timer();
- private List<CmmInputRecordEntity> _cmmInputRecordEntities;
- private frmMessage _frmMessage;
- private List<CmmRecordTemplateEntity> _templateList;
- private bool canUpdateWt;
- private CmmPoundBaseEntity cmmPoundBase;
- private CommunicationEntity communicationnow;
- private List<CommunicationEntity> CommunicationEntitys = new List<CommunicationEntity>();
- // private SerialPortEntity defultPortEntity;
- private bool isLoading = true;
- private List<CmmPoundBaseEntity> poundInfos;
- //TODO:等陆硬盘录像机
- private Log l = Log.GetInstance();
- private DataCollectionControl collection = new DataCollectionControl();
- //private SocketClient defultClenttEntity;
- private List<CmmBaseSpotInfoEntity> CmmBaseSpotInfo;
- //private CmmBaseSpotInfoEntity CmmBase = new CmmBaseSpotInfoEntity();
- //private TcpListener tcpListener;
- //图片控制器含图片压缩及上传sftp
- private ImageControl imageControl;
- List<CmmLoadinfoCEntity> loadinfo;
- string strip;
- // private CmmWorkImageEntity CmmImage=new CmmWorkImageEntity();
- public frmLocalTruckScaleNew()
- {
- InitializeComponent();
- IsLoadUserView = true;
- // timer.Elapsed += timer_Elapsed;
- // timer.Interval = 1 * 60 * 1000;
- // timer.Start();
- }
- private void timer_Elapsed(object sender, ElapsedEventArgs e)
- {
- try
- {
- CurrentGrid.SafeRefreshControl(() =>
- {
- var dic = new Dictionary<string, object>();
- if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
- dic.Add("poundNo", cboPoundList.Text);
- dic.Add("validflag", new List<string> { "1" });
- dic.Add("effRemaind", "1");
- List<CmmWeightRecordEntity> list = EntityHelper.GetData<CmmWeightRecordEntity>(
- "com.steering.Mcms.RecordServer.doQueryRecord",
- new object[] { dic },
- ob);
- if ((list != null) && list.Any())
- foreach (
- var ultraGridRow in
- CurrentGrid.Rows.Where(
- p => list.Any(q => q.RecordNo == p.Cells["RecordNo"].Value.ToString2())))
- ultraGridRow.Cells["RecordDate"].Appearance.BackColor = Color.Red;
- });
- GC.Collect();
- }
- catch (Exception)
- {
- }
- }
- protected override async void OnLoad(EventArgs e)
- {
- //try
- //{
- System.Net.IPHostEntry hostIP = System.Net.Dns.GetHostEntry(Environment.MachineName);
- strip = hostIP.AddressList[0].ToString();
- // strip = UserInfo.GetMachineIP();
- 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 = SystemColors.ControlText;
- ;
- tbFirstWt.Appearance.ForeColor = SystemColors.ControlText;
- ;
- tbScondWt.Appearance.ForeColor = SystemColors.ControlText;
- ;
- tbOther.Appearance.ForeColor = SystemColors.ControlText;
- ;
- //TUDO
- poundInfos = EntityHelper.GetData<CmmPoundBaseEntity>(
- "com.steering.Mcms.PoundBaseServer.getPoudInfo",
- new object[] { ValidDataPurviewIds },
- ob);
- CmmBaseSpotInfo = EntityHelper.GetData<CmmBaseSpotInfoEntity>(
- "com.steering.Mcms.CmmBaseSpotInfoServer.doQuery",
- new object[] { },
- ob);
- List<CmmPoundBaseEntity> list = EntityHelper.GetData<CmmPoundBaseEntity>(
- "com.steering.Mcms.PoundBaseServer.getPoudInfo",
- new object[] { new string[] { } },
- ob);
- 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"));
- LoadRecord();
- LoadTempate();
- //加载配置
- // 构造 ImageControl 对象
- imageControl = new ImageControl(
- CmmBaseSpotInfo[0].FtpIp,
- CmmBaseSpotInfo[0].FtpPort,
- CmmBaseSpotInfo[0].FtpUserName,
- CmmBaseSpotInfo[0].FtpPassword,
- CmmBaseSpotInfo[0].Ftptype,
- CmmBaseSpotInfo[0].Ftppath,
- ob);
- // 异步启动,避免卡UI
- await Task.Run(() => imageControl.Start());
- // }
- // catch
- //{ }
- comboCount.Text = "1";
- }
- private void defultClenttEntity_ReceiveData(object sender, object data, string message, DataType datatype,
- byte[] bdata)
- {
- SocketClient client = sender as SocketClient;
- if (client.Show == true)
- {
- ShowMessage(data, message, datatype, sender);
- }
- }
- private async void LoadRecord()
- {
- var dic1 = new Dictionary<string, object>
- {
- { "recordType", new List<string> { "1" } }
- };
- var dic2 = new Dictionary<string, object>
- {
- { "recordType", new List<string> { "2", "7", "8", "9" } }
- };
- // 并行执行
- var task1 = Task.Run(() => EntityHelper.GetData<CmmInputRecordEntity>(
- "com.steering.Mcms.InputRecordServer.doQuery",
- new object[] { dic1 },
- ob
- ));
- var task2 = Task.Run(() => EntityHelper.GetData<CmmInputRecordEntity>(
- "com.steering.Mcms.InputRecordServer.doQuery",
- new object[] { dic2 },
- ob
- ));
- var datas = await task1;
- _cmmInputRecordEntities = await task2;
- // 更新UI
- txtCar2.DataSource = datas
- .Where(p => p.RecordType == "1")
- .Select(p => p.RecordValue)
- .Distinct()
- .ToList();
- txtCar2.Text = "";
- }
- private void utbConnect_Click(object sender, EventArgs e)
- {
- if (communicationnow.Communication == null) return;
- if ((communicationnow.Communication != null) && communicationnow.Communication.Status)
- {
- communicationnow.Communication.Stop();
- }
- else
- {
- communicationnow.Communication.Start();
- }
- }
- private void utbMessage_Click(object sender, EventArgs e)
- {
- _frmMessage = new frmMessage();
- _frmMessage.Show();
- }
- //TUDO
- private void ShowMessage(object data, string message, DataType dataType, object sender)
- {
- SocketClient client = sender as SocketClient;
- 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.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Red);
- lblMsg.SafeRefreshControl(
- () =>
- lblMsg.Text =
- client.Status
- ? "已打开"
- : "已关闭");
- // cboNo.SafeRefreshControl(() => cboNo.Enabled = false);
- }
- else if (dataType == DataType.Close)
- {
- utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Lime);
- lblMsg.SafeRefreshControl(
- () =>
- lblMsg.Text =
- client.Status
- ? "已打开"
- : "已关闭");
- }
- else if (dataType == DataType.Error)
- {
- MessageBox.Show(message);
- }
- else if (dataType == DataType.ClientReconnect)
- {
- lblMsg.SafeRefreshControl(() => lblMsg.Text = "网络异常,正在重连服务!");
- }
- lblStatus.SafeRefreshControl(() => lblStatus.Text = client.ToString());
- 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 async 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 if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
- (tbOther.ActiveTab.Key == "205"))
- {
- decimal wt, fwt;
- decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
- await ShowOutInfo(current.CarNo, wt - fwt, comboCount.Text);
- }
- else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
- (tbOther.ActiveTab.Key == "206"))
- {
- decimal wt, fwt;
- decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
- if (wt - fwt > 0)
- matInfo13.SetWt(wt - fwt);
- // ShowOutInfoGp(current.CarNo, wt - fwt);
- }
- else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
- (tbOther.ActiveTab.Key == "109"))
- {
- 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;
- if (chkGross.Checked)
- {
- checkBox1.Visible = false;
- recordType.Visible = false;
- }
- else
- {
- checkBox1.Visible = true;
- recordType.Visible = true;
- }
- }
- Thread thsave;
- Point screenPoint;
- void Savepicture(object str)
- {
- //*
- //截取屏幕信息
- // PbCache.actualFirstNo = CmmImage.ActualFirstNo;
- Rectangle rect = new Rectangle(screenPoint, this.Size);
- Image img = new Bitmap(rect.Width, rect.Height);
- Graphics g = Graphics.FromImage(img);
- g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
- img.Save(string.Format("{0}\\imgShort\\formalImg\\{1}_{2}_{3}.jpg",
- AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
- PbCache.sportInfo.BaseSpotNo,
- PbCache.actualFirstNo,
- (5)), System.Drawing.Imaging.ImageFormat.Jpeg);// 最后一张图片名称写死了
- //*
- //最后进行截图操作
- CameraShotCls cameraShot = new CameraShotCls();
- cameraShot.CapMethod(PbCache.actualFirstNo, communicationnow.PoundNo);
- }
- /// <summary>
- /// 一次称重保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void utbSave1_Click(object sender, EventArgs e)
- {
- if (lblWt.Text != lblWtNow.Text)
- {
- if ( MessageUtil.ShowYesNoAndQuestion("吨位不一致!请确认是否继续保存 ?") == DialogResult.No)
- return;
-
- }
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- if (string.IsNullOrWhiteSpace(txtCar2.Text) || string.IsNullOrWhiteSpace(cbxCar1.Text))
- {
- MessageBox.Show(@"未录入车牌号!");
- return;
- }
- decimal wt = 0;
- //测试注释 TZH
- 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();
- }
- if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
- cmmWeightRecord.MatInfos.Any())
- {
- MessageBox.Show("支数不能为空!");
- return;
- }
- 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
- : checkBox1.Checked ? recordType.Text : "";
- cmmWeightRecord.Memo = chkSteelCar.Checked ? "钢管" : "";
- if ("102" == cmmWeightRecord.RecordType)
- if ((cmmWeightRecord.RecordNumber == null) || (cmmWeightRecord.RecordNumber <= 0) ||
- (cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()
- || cmmWeightRecord.MatInfos.Any(p => (p.ActCount == null) || (p.ActCount <= 0)))
- {
- MessageBox.Show("支数不能为空!");
- return;
- }
- // 先毛后皮
- if (checkBox1.Checked)
- {
- var key = "";
- key = recordType.Value.ToString2();
- if (key == "" || key == null)
- {
- MessageBox.Show("请选择过磅类型!");
- return;
- }
- cmmWeightRecord.WtType = "1";
- cmmWeightRecord.RecordType = key;
- }
- var list =
- cmmWeightRecordEntityBindingSource.DataSource as List<CmmWeightRecordEntity>;
- if ((list != null) && list.Any(p => p.CarNo == cmmWeightRecord.CarNo))
- if (MessageUtil.ShowYesNoAndQuestion("车牌已经存在皮重,是否继续保存皮重?") == DialogResult.No)
- 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[]
- {
- "",
- json
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
-
- PbCache.actualFirstNo = ccp.ReturnObject.ToString();//tudo
- #region 截取图片信息
- try
- {
- screenPoint = this.PointToScreen(new Point());
- thsave = new Thread(new ParameterizedThreadStart(Savepicture));
- thsave.Start("");
- playVioce("称重完成");
- }
- catch (Exception ex)
- {
- l.WriteLog(5, PbCache.lockCarNo + "截图失败");
- }
- #endregion
- if (true)//(ccp.ReturnCode != -1)
- if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
- {
- ccp.ReturnInfo.ToString2().Speak();
- lblWt.Text = "0.000t";
- LoadRecord();
- Query();
- //tzh 24.11.25 清空提单信息
- CX_HT.Text = "";
- tb_order.Text = "";
- var matInfo = GetMatInfo();
- if (matInfo != null) matInfo.SetDefault(null);
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- addActual(communicationnow.PoundNo, PbCache.actualFirstNo);
- checkBox1.Checked = false;
- chkSteelCar.Checked = false;
- chkGross.Checked = false;
- tbFirstWt.Visible = chkGross.Checked;
- utbSaveAsT.Visible = chkGross.Checked;
- //TUDO//
- }
- /// <summary>
- /// 二次称重
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave2_Click(object sender, EventArgs e)
- {
- string CX = "";
- if ( CX_HT.Value != null)
- {
- CX = CX_HT.Value.ToString();
-
- }
-
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- if (lblWt.Text != lblWtNow.Text)
- {
- if (MessageUtil.ShowYesNoAndQuestion("吨位不一致!请确认是否继续保存 ?") == DialogResult.No)
- return;
- }
- if (tbScondWt.ActiveTab == null) return;
- if (CurrentGrid.ActiveRow == null)
- {
- MessageBox.Show(@"请选择第一次称重记录");
- return;
- }
- decimal wt = 0;
- //测试注释 TZH
- 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;
- if (current.CarNo != (cbxCar1.Text + txtCar2.Text))
- {
- MessageBox.Show("选中的车号与显示的车号不一致");
- return;
- }
- var key = GetKey();
- CmmWeightRecordEntityFull cmmWeightRecord;
- if ("207" == key)
- {
- cmmWeightRecord = new CmmWeightRecordEntityFull();
- if (checkBox3.Checked)
- {
- var matInfo = GetMatInfo();
- cmmWeightRecord = matInfo.GetData();
- cmmWeightRecord.WtType = "0";
- }
- }
- else
- {
- var matInfo = GetMatInfo();
- if (matInfo == null) return;
- cmmWeightRecord = matInfo.GetData();
- cmmWeightRecord.WtType = "1";
- if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
- cmmWeightRecord.MatInfos.Any())
- {
- MessageBox.Show("数量不能为空!");
- return;
- }
- }
- var 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;
- }
- var 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)
- {
- var msg = " 净重与钩子称 误差超过千分之5";
- msg.Speak();
- if (
- MessageUtil.ShowYesNoAndQuestion(" 净重: " + NetWt + "t 钩子称重量: " + hookWt + "t 磅差 " +
- (NetWt - hookWt) + "t 误差超过千分之5, 请确认是否继续保存 ?") ==
- DialogResult.No)
- return;
- }
- }
- cmmWeightRecord.RecordType = GetKey();
- cmmWeightRecord.Recoder = UserInfo.GetUserName();
- 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 newKey = "";
- if (checkBox3.Checked && cmmWeightRecord.RecordType == "207")
- {
- newKey = qitahuipi.ActiveTab.Key;
- cmmWeightRecord.MatType = qitahuipi.ActiveTab.Text;
- }
- var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None,
- new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
- object[] o = null;
- if (cmmWeightRecord.RecordType == "207" && checkBox3.Checked)
- {
- if ("102" == newKey)
- {
- cmmWeightRecord.WtType = "0";
- decimal NetWt;
- decimal wt2, wt1;
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
- decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
- {
- NetWt = wt1 - wt2;
- }
- else
- {
- MessageBox.Show("数据异常!");
- return;
- }
- if (NetWt <= 0)
- {
- MessageBox.Show("净重小于0!");
- return;
- }
- cmmWeightRecord.RealWt = NetWt;
- }
- if ("102" == newKey)
- if ((cmmWeightRecord.RecordNumber == null) || (cmmWeightRecord.RecordNumber <= 0) ||
- (cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()
- || cmmWeightRecord.MatInfos.Any(p => (p.ActCount == null) || (p.ActCount <= 0)))
- {
- MessageBox.Show("支数不能为空!");
- return;
- }
- o = new object[]
- {
- current.RecordNo,
- hookWtStr,
- json,
- newKey,
- CX
- };
- }
- else
- {
- o = new object[]
- {
- current.RecordNo,
- hookWtStr,
- json,
- CX
- };
- }
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.LocalTruckScale",
- MethodName = "DoAdd",
- ServerParams = o
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- PbCache.actualFirstNo = ccp.ReturnObject.ToString();
- addActual(communicationnow.PoundNo, PbCache.actualFirstNo);
- checkBox3.Checked = false;
- checkBox3.Visible = false;
- qitahuipi.Visible = checkBox3.Checked;
- #region 截取图片信息
- try
- {
- screenPoint = this.PointToScreen(new Point());
- thsave = new Thread(new ParameterizedThreadStart(Savepicture));
- thsave.Start("");
- playVioce("称重完成");
- }
- catch (Exception ex)
- {
- l.WriteLog(5, PbCache.lockCarNo + "截图失败");
- }
- #endregion
- if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
- {
- decimal wt2;
- decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2);
- lblWt.Text = "0.000t";
- var result = ccp.ReturnInfo.ToString2().Split('|');
- result[0].Speak();
- if (result.Length > 1)
- if ((key == "201") && (wt2 > 50) && (MessageUtil.ShowYesNoAndQuestion("称重完成! 毛重超过50吨, 是否继续打印磅单?") ==
- DialogResult.No))
- {
- }
- else
- {
- Print(result[1]);
- }
- LoadRecord();
- Query();
- Query2();
- //tzh 24.11.25 清空提单信息
- CX_HT.Text = "";
- tb_order.Text = "";
- //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 Print2(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();
- }
- //TUDO
- private void frmLocalTruckScale_FormClosed(object sender, FormClosedEventArgs e)
- {
- //if ((communication != null) && communication.Status)
- // communication.Stop();
- timer.Stop();
- }
- private async 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" });
- // 在后台线程执行数据库查询
- var list = await Task.Factory.StartNew(() =>
- {
- return EntityHelper.GetData<CmmWeightRecordEntity>(
- "com.steering.Mcms.RecordServer.doQueryRecord",
- new object[] { dic },
- ob
- );
- });
- // 回到 UI 线程更新控件
- cmmWeightRecordEntityBindingSource.DataSource = list;
- Comm.RefreshAndAutoSize(CurrentGrid);
- }
- private async void LoadTempate()
- {
- // 如果 cmmPoundBase 要判断的话,恢复这行
- // if (cmmPoundBase == null) return;
- _templateList = await Task.Run(() =>
- {
- return EntityHelper.GetData<CmmRecordTemplateEntity>(
- "com.steering.Mcms.TemplateServer.doQueryTempate",
- new object[] { "" },
- ob
- );
- });
- // 数据加载完后,再调用 UI 更新方法
- 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;
- // ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- // (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null)
- // matInfo = qitahuipi.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();这个以后试试可以用不--byzc
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
- matInfo = matInfo20;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "110")
- matInfo = matInfo28;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "103")
- matInfo = matInfo21;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "104")
- matInfo = matInfo22;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "105")
- matInfo = matInfo23;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "106")
- matInfo = matInfo24;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "107")
- matInfo = matInfo25;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "108")
- matInfo = matInfo26;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "109")
- matInfo = matInfo27;
- else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "301")
- matInfo = matInfo19;
- return matInfo;
- }
- private MatInfo GetMatInfo2()
- {
- MatInfo matInfo = null;
- if (CX_HT.Text == null) return null;
- matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
- 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;
- if (key == "301") return matInfo19;
- 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();
- //TZH 24.11.7 加入取产销的废品合同号
- if (tbOther.ActiveTab.Key == "202")
- {
- CX_HTH.Visible = true;
- CX_HT.Visible = true;
- lb_order.Visible = true;
- tb_order.Visible = true;
- DataTable dt = ServerHelper.GetData("com.steering.Mcms.TemplateServer.SelectCX", new object[] { }, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- CX_HT.DataSource = dt;
- CX_HT.ValueMember = "BILL_NO";
- CX_HT.DisplayMember = "BILL_NO";
- }
- }
- else
- {
- CX_HTH.Visible = false;
- CX_HT.Visible = false;
- lb_order.Visible = false;
- tb_order.Visible = false;
- }
- 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 ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
- (tbOther.ActiveTab.Key == "205"))
- {
- decimal wt, fwt;
- decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
- ShowOutInfo(current.CarNo, wt - fwt, comboCount.Text);
- }
- else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
- (tbOther.ActiveTab.Key == "206"))
- {
- decimal wt, fwt;
- decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
- decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
- if (wt - fwt > 0)
- matInfo13.SetWt(wt - fwt);
- //ShowOutInfoGp(current.CarNo, wt - fwt);
- }
- 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);
- }
- }
- }
- utbSelect.Visible = (tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "1") && (tbFirstWt.ActiveTab != null) &&
- (tbFirstWt.ActiveTab.Key == "102");
- utbSelect2.Visible = utbSelect.Visible;
- }
- private void LoadTem()
- {
- if (_templateList == null) return;
- var key = GetKey();
- if (string.IsNullOrWhiteSpace(key)) return;
- if ((_cmmInputRecordEntities != null) && _cmmInputRecordEntities.Any())
- {
- var 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 => CheckShowKey(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"
- : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "4")
- ? "102"
- : "";
- }
- 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")
- ? "其它内转"
- : ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
- ? "钢坯采购"
- : "";
- }
- 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 async void CurrentGrid_AfterRowActivate(object sender, EventArgs e)
- {
- CurrentGrid.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- if ((current == null) || string.IsNullOrEmpty(current.CarNo)) return;
- checkBox3.Visible = current.firstGross == "是";
- ultraButton2.Visible = current.firstGross == "是";
- var tabKey = tbScondWt?.ActiveTab?.Key;
- var otherKey = tbOther?.ActiveTab?.Key;
- if (tbWt?.ActiveTab?.Key == "2" && !string.IsNullOrEmpty(tabKey))
- {
- if (tabKey == "3")
- {
- await ShowWasteInfo(current.CarNo);
- }
- else if (tabKey == "0")
- {
- await ShowLoadvehicleInfo(current.CarNo);
- }
- else if (tabKey == "1" && otherKey == "205")
- {
- var diff = GetWeightDiff(current);
- if (diff.HasValue)
- await ShowOutInfo(current.CarNo, diff.Value, comboCount.Text);
- }
- else if (tabKey == "1" && otherKey == "206")
- {
- var diff = GetWeightDiff(current);
- if (diff.HasValue && diff > 0)
- matInfo13.SetWt(diff.Value);
- }
- else
- {
- var matInfo = GetMatInfo();
- var diff = GetWeightDiff(current);
- if (matInfo != null && diff.HasValue && diff > 0)
- matInfo.SetWt(diff.Value);
- }
- }
- }
- private decimal? GetWeightDiff(CmmWeightRecordEntity current)
- {
- if (decimal.TryParse(lblWt.Text.Replace("t", ""), out var wt) &&
- decimal.TryParse(current.RecordWeight.ToString3(), out var fwt))
- {
- return wt - fwt;
- }
- return null;
- }
- // 显示废品信息(异步版本)
- public async Task ShowWasteInfo(string carNo)
- {
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- // 后台线程执行数据库查询
- var dt = await Task.Run(() =>
- {
- return ServerHelper.GetData(
- "com.steering.Mcms.MatOutServer.doQueryWasteInfo",
- new object[] { carNo },
- ob
- );
- });
- if (dt != null && dt.Rows.Count > 0)
- {
- var firstRow = dt.Rows[0];
- cmmWeightRecordEntityFull.ShippersName = firstRow["STORAGE_NAME_FROM"].ToString2();
- cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["OUTSTOCK_DOC"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = firstRow["STORAGE_NAME_TO"].ToString2();
- cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(firstRow["ACT_COUNT"].ToString3());
- cmmWeightRecordEntityFull.MatName = "废品管";
- foreach (DataRow dtcRow in dt.Rows)
- {
- var cmmWeightMatEntity = new CmmWeightMatEntity
- {
- Produccode = dtcRow["PRODUCCODE"].ToString2(),
- Producname = dtcRow["PRODUCNAME"].ToString2(),
- Gradecode = dtcRow["GRADECODE"].ToString2(),
- Gradename = dtcRow["GRADENAME"].ToString2(),
- Steelcode = dtcRow["STEELCODE"].ToString2(),
- Steelname = dtcRow["STEELNAME"].ToString2(),
- 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);
- }
- }
- // UI 更新(保持在 UI 线程)
- matInfo15.SetDefault(cmmWeightRecordEntityFull);
- }
- // 显示装车单信息(异步版本)
- public async Task ShowLoadvehicleInfo(string carNo)
- {
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- // 后台线程查询第一个数据表
- var dt = await Task.Run(() =>
- {
- return ServerHelper.GetData(
- "com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleInfo",
- new object[] { carNo },
- ob);
- });
- if (dt != null && dt.Rows.Count > 0)
- {
- var firstRow = dt.Rows[0];
- cmmWeightRecordEntityFull.ShippersName = firstRow["BASENAME"].ToString2();
- cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["LOADVEHICLE_NO"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = firstRow["RECEIV_NM"].ToString2();
- cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(firstRow["STACKING_PIECE"].ToString3());
- cmmWeightRecordEntityFull.OrderName = firstRow["CUSTOMER_NM"].ToString2();
- cmmWeightRecordEntityFull.MatName = "钢管";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
- // 后台线程查询第二个数据表
- var dtc = await Task.Run(() =>
- {
- return 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(),
- 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 = await Task.Run(() =>
- {
- return 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)
- {
- var total = double.Parse(dthRow["HOOK_WEIGHT"].ToString3());
- double num = int.Parse(cmmWeightRecordEntityFull.MatInfos
- .Where(p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
- .Sum(p => p.ActCount).ToString3());
- var perWt = Math.Round(total / num, 3);
- var 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 e)
- {
- // 可选:日志记录异常
- Console.WriteLine("异常" + e.StackTrace);
- }
- }
- else
- {
- cmmWeightRecordEntityFull = null;
- }
- // UI 线程更新控件
- matInfo16.SetDefault(cmmWeightRecordEntityFull);
- }
- public async Task ShowOutInfo(string carNo, decimal nutWt,String boCount)
- {
- string comboCountText = comboCount.Text;
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- // 异步查询数据
- var dt = await Task.Run(() =>
- ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfo", new object[] { carNo, boCount }, ob));
- if (dt != null && dt.Rows.Count > 0)
- {
- var firstRow = dt.Rows[0];
- cmmWeightRecordEntityFull.ShippersName = firstRow["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"
- ? "江苏天淮钢管有限公司"
- : firstRow["STORAGE_NAME_FROM"].ToString2();
- cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["OUTSTOCK_DOC"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = firstRow["STORAGE_NAME_TO"].ToString2();
- cmmWeightRecordEntityFull.OrderName = firstRow["STORAGE_NAME_D"].ToString2();
- // 安全计算总件数,避免空序列异常
- cmmWeightRecordEntityFull.RecordNumber = dt.AsEnumerable()
- .Where(p => p["ACT_COUNT"] != DBNull.Value && !string.IsNullOrWhiteSpace(p["ACT_COUNT"].ToString()))
- .Select(p => decimal.Parse(p["ACT_COUNT"].ToString3()))
- .DefaultIfEmpty(0)
- .Sum();
- cmmWeightRecordEntityFull.MatName = firstRow["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"
- ? "调拨钢管"
- : "内转钢管";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
- // 安全计算总重量,避免空序列异常
- var totalWt = dt.AsEnumerable()
- .Where(p => p["ACT_WEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(p["ACT_WEIGHT"].ToString()))
- .Select(p => decimal.Parse(p["ACT_WEIGHT"].ToString3()))
- .DefaultIfEmpty(0)
- .Sum();
- var perWt = totalWt > 0 ? nutWt / totalWt : 0;
- var remainWt = nutWt;
- for (var i = 0; i < dt.Rows.Count; i++)
- {
- var dtcRow = dt.Rows[i];
- decimal actWeight;
- if (i == dt.Rows.Count - 1)
- {
- actWeight = remainWt;
- }
- else
- {
- var rawWeight = (dtcRow["ACT_WEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_WEIGHT"].ToString()))
- ? decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3())
- : 0m;
- actWeight = Math.Round(rawWeight * perWt, 3);
- }
- var cmmWeightMatEntity = new CmmWeightMatEntity
- {
- Produccode = dtcRow["PRODUCCODE"].ToString2(),
- Producname = dtcRow["PRODUCNAME"].ToString2(),
- Gradecode = dtcRow["GRADECODE"].ToString2(),
- Gradename = dtcRow["GRADENAME"].ToString2(),
- Steelcode = dtcRow["STEELCODE"].ToString2(),
- Steelname = dtcRow["STEELNAME"].ToString2(),
- ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" + dtcRow["ACT_LEN_MAX"].ToString3(),
- ActWeight = actWeight,
- ActCount = (dtcRow["ACT_COUNT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_COUNT"].ToString()))
- ? decimal.Parse(dtcRow["ACT_COUNT"].ToString3())
- : 0,
- JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
- ActDimater = (dtcRow["ACT_DIMATER"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_DIMATER"].ToString()))
- ? decimal.Parse(dtcRow["ACT_DIMATER"].ToString3())
- : 0,
- ActHeight = (dtcRow["ACT_HEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_HEIGHT"].ToString()))
- ? decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
- : 0
- };
- l.WriteLog(3, "车号:"+ carNo+ " nutWt:"+ nutWt+ " boCount:" + boCount+ "actWeight:"+ actWeight+ " remainWt:"+ remainWt+ " totalWt:"+ totalWt);
- remainWt -= actWeight;
- cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
- }
- // UI 线程更新
- matInfo12.SetDefault(cmmWeightRecordEntityFull);
- }
- else
- {
- if (nutWt > 0)
- matInfo12.SetWt(nutWt);
- }
- }
- public void ShowOutInfoGp(string carNo, decimal nutWt)
- {
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", 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 =
- dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
- decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
- cmmWeightRecordEntityFull.MatName = "内转钢坯";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
- var perWt = Math.Round(nutWt / (decimal)cmmWeightRecordEntityFull.RecordNumber, 3);
- var remainWt = nutWt;
- for (var i = 0; i < dt.Rows.Count; i++)
- {
- var dtcRow = dt.Rows[i];
- var cmmWeightMatEntity = new CmmWeightMatEntity
- {
- Steelcode = dtcRow["GRADECODE"].ToString2(),
- Steelname = dtcRow["GRADENAME"].ToString2(),
- ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
- ActWeight =
- i == dt.Rows.Count - 1 ? remainWt : decimal.Parse(dtcRow["ACT_COUNT"].ToString3()) * perWt,
- ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
- JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
- ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
- ActHeight = decimal.Parse(dtcRow["HEIGHT"].ToString3())
- };
- remainWt = remainWt - perWt;
- cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
- }
- matInfo13.SetDefault(cmmWeightRecordEntityFull);
- }
- else
- {
- if (nutWt > 0)
- matInfo13.SetWt(nutWt);
- }
- }
- 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 async void Query2()
- {
- try
- {
- 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("yyyy-MM-dd HH:mm:ss"));
- }
- dic.Add("carNo", uteCarNo.Text);
- dic.Add("matType", uceQueryCarType.Text);
- dic.Add("resultNo", utePound.Text);
- dic.Add("orderName", uteOrder.Text);
- dic.Add("shippersName", uteShippersName.Text);
- dic.Add("receiveName", uteReceiveName.Text);
- dic.Add("memo", uteMemo.Text);
- dic.Add("validflag", new List<string> { "1" });
- dic.Add("judgeStoveNo", uteJudgeStoveNo.Text);
- // 在后台线程执行查询
- var list = await Task.Factory.StartNew(() =>
- {
- return EntityHelper.GetData<CmmWeightResultEntity>(
- "com.steering.Mcms.ResultServer.doQuery",
- new object[] { dic },
- ob
- );
- });
- // 回到 UI 线程更新控件
- lblCount.Text = string.Format("共{0}条记录", list.Count);
- QueryBS.DataSource = list;
- Comm.RefreshAndAutoSize(ugData);
- }
- catch
- {
- // 建议这里至少写日志
- }
- }
- 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 = "";
- utePound.Text = "";
- uteOrder.Text = "";
- uteShippersName.Text = "";
- uteReceiveName.Text = "";
- uteMemo.Text = "";
- uteJudgeStoveNo.Text = "";
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null) return;
- var ub = sender as UltraButton;
- if (ub == null) return;
- var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if (data == null) return;
- ("是否" + ub.Text + " 车辆 " + data.CarNo + " 的过磅单?").Speak();
- if (MessageUtil.ShowYesNoAndQuestion("是否" + ub.Text + " 车牌[" + data.CarNo + "]过磅单?") == DialogResult.No)
- 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 lvTemplate_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
- {
- var matInfo = GetMatInfo();
- if ((matInfo != null) && matInfo.AddNew) 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, 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, 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;
- }
- var cmm = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- var matInfo = GetMatInfoByKey("101" == cmm.RecordType1 ? cmm.RecordType2 : cmm.RecordType1);
- if (matInfo == null)
- {
- MessageBox.Show("该类型不允许修改!");
- return;
- }
- var recordNo = "101" == cmm.RecordType1 ? cmm.RecordNo2 : cmm.RecordNo1;
- if ("207" == cmm.RecordType2 && (cmm.MatType == "钢坯采购"|| cmm.MatType == "钢坯退货" ||
- cmm.MatType == "钢管退货" || cmm.MatType == "采购辅料" || cmm.MatType == "修复返厂" ||
- cmm.MatType == "设备采购" || cmm.MatType == "其他内转" || cmm.MatType == "内转钢管"
- || cmm.MatType == "外购钢管"))
- {
- recordNo = cmm.RecordNo2;
- }
- using (var frmUpdate = new FrmUpdate(ob, cmm, recordNo, canUpdateWt)
- {
- 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;
- if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
- DialogResult.No))
- {
- }
- else
- {
- 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;
- if ((data.RecordType2 == "205") || (data.RecordType2 == "201") || (data.RecordType2 == "200"))
- if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
- DialogResult.No))
- {
- }
- else
- {
- Print(data.ResultNo, true);
- }
- }
- private void unExcel_Click(object sender, EventArgs e)
- {
- var hssfworkbook = new HSSFWorkbook();
- var sheet = hssfworkbook.CreateSheet("磅房统计");
- var 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 (var saveFileDialog1 = new SaveFileDialog())
- {
- saveFileDialog1.FileName = "磅房统计" + DateTime.Now.ToString("yyMMdd");
- saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- var sFullName = saveFileDialog1.FileName;
- var ms = new MemoryStream();
- hssfworkbook.Write(ms);
- using (var fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
- {
- var bArr = ms.ToArray();
- fs.Write(bArr, 0, bArr.Length);
- fs.Flush();
- }
- var p = new ProcessStartInfo(sFullName);
- p.WorkingDirectory = Path.GetDirectoryName(sFullName);
- Process.Start(p);
- }
- }
- }
- private void SetSumm(ISheet sheet, int index, HSSFWorkbook hssfworkbook)
- {
- var IRow = sheet.CreateRow(index);
- IRow.Height = 20 * 20;
- var 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;
- var 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;
- var 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));
- var list = new List<string>();
- for (var i = 2; i < index; i++)
- list.Add(i + 1 + "");
- var 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);
- Icell2.SetCellType(CellType.Formula);
- Icell2.SetCellFormula(string.Format("SUM({0})", "E"+list[0]+":E"+list[list.Count-1]));
- 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;
- var 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())));
- Icell3.SetCellFormula(string.Format("SUM({0})", "F" + list[0] + ":F" + list[list.Count - 1]));
- 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;
- var 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())));
- Icell4.SetCellFormula(string.Format("SUM({0})", "G" + list[0] + ":G" + list[list.Count - 1]));
- 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)
- {
- var index1 = index;
- var 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 =>
- {
- var IRow = sheet.CreateRow(index1++);
- IRow.Height = 20 * 20;
- for (var i = 0; i < 6; i++)
- {
- var 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)
- {
- var IRow = sheet.CreateRow(rowIndex);
- IRow.Height = 20 * 20;
- for (var i = 0; i < name.Count; i++)
- {
- sheet.SetColumnWidth(i + 1, columsWidth[i] * 256);
- var 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)
- {
- var IRow = sheet.CreateRow(rowindex);
- IRow.Height = 50 * 20;
- var 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)
- {
- //新建一个字体样式对象
- var font = hssfworkbook.CreateFont();
- font.FontName = "宋体";
- font.FontHeightInPoints = 30;
- //设置字体加粗样式
- font.Boldweight = (short)FontBoldWeight.Bold;
- return font;
- }
- private static IFont ContextFont(HSSFWorkbook hssfworkbook)
- {
- //新建一个字体样式对象
- var font = hssfworkbook.CreateFont();
- font.FontName = "宋体";
- font.FontHeightInPoints = 12;
- //设置字体加粗样式
- font.Boldweight = (short)FontBoldWeight.Bold;
- return font;
- }
- private ICellStyle CenterStyle(HSSFWorkbook hssfworkbook)
- {
- var style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = HorizontalAlignment.Center;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private ICellStyle textStyle(HSSFWorkbook hssfworkbook)
- {
- var style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = HorizontalAlignment.Left;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private ICellStyle numStyle(HSSFWorkbook hssfworkbook)
- {
- var style = hssfworkbook.CreateCellStyle();
- //设置单元格的样式:水平对齐居中
- style.Alignment = HorizontalAlignment.Right;
- style.VerticalAlignment = VerticalAlignment.Center;
- return style;
- }
- private void CurrentGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
- {
- }
- private void CurrentGrid_DoubleClickCell(object sender, 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;
- if (current.RecordType != "101")
- tbScondWt.Tabs["2"].Selected = true;
- else
- 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)
- {
- txtCar2.Focus();
- 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)
- {
- // timer.Start();
- splitContainer1.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer1",
- splitContainer1.SplitterDistance);
- splitContainer2.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer2",
- splitContainer2.SplitterDistance);
- var 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;
- isLoading = false;
- CurrentGrid.DisplayLayout.Bands[0].Columns["RecordType"].EditorComponent = uceType2;
- CurrentGrid.DisplayLayout.Bands[0].Columns["RecordNo"].EditorComponent = delete;
- CurrentGrid.DisplayLayout.Bands[0].Columns["CarNo"].EditorComponent = uteEdit;
- Query();
- Query2();
- try
- {
- if (toolMenu == null) return;
- if (toolMenu.Toolbars[0].Tools.Exists("UpdateWt"))
- canUpdateWt = true;
- toolMenu.Visible = false;
- }
- catch (Exception ex)
- {
- Console.WriteLine("异常" + ex.StackTrace);
- }
- }
- private void CurrentGrid_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.F5)
- using (var dr = new FontDialog { Font = (sender as Control).Font })
- {
- if (dr.ShowDialog() == DialogResult.OK)
- {
- (sender as Control).Font = dr.Font;
- var x = new FontConverter();
- var font = x.ConvertToString(dr.Font);
- // t = x.ConvertFromString(s) as Font;
- XmlHelper.SetXmlData(_path, (sender as 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;
- currentGridRow.Activated = true;
- if (currentGridRow.Cells["RecordType"].Value.ToString2() != "101")
- tbScondWt.Tabs["2"].Selected = true;
- else
- tbScondWt_SelectedTabChanged(null, null);
- return;
- }
- tbWt.Tabs["1"].Selected = true;
- }
- private void uteEdit_EditorButtonClick(object sender, EditorButtonEventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- string carNo;
- using (var update = new UpdateCar { CarNo = current.CarNo })
- {
- var result = update.ShowDialog();
- if (result != DialogResult.OK) return;
- carNo = update.CarNo;
- }
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.RecordServer",
- MethodName = "DoUpdateCarNo",
- ServerParams = new object[]
- {
- current.RecordNo,
- carNo
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
- Query();
- }
- }
- public bool CheckShowKey(string key1, string key2)
- {
- if (key1 == key2) return true;
- if (((key1 == "107") && (key2 == "204")) || ((key2 == "107") && (key1 == "204"))) return true;
- if (((key1 == "108") && (key2 == "205")) || ((key2 == "108") && (key1 == "205"))) return true;
- if (((key1 == "206") && (key2 == "206")) || ((key2 == "109") && (key1 == "206"))) return true;
- return false;
- }
- private void txtCar2_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar >= 97) && (e.KeyChar <= 122))
- e.KeyChar = (char)(e.KeyChar - 32);
- }
- private void CurrentGrid_InitializeRow(object sender, InitializeRowEventArgs e)
- {
- var cmmWeightRecord = e.Row.ListObject as CmmWeightRecordEntity;
- if (cmmWeightRecord == null) return;
- if ((cmmWeightRecord.EffRemaind != null) && (cmmWeightRecord.EffRemaind <= 1))
- e.Row.Cells["RecordDate"].Appearance.BackColor = Color.Red;
- }
- private void utbSelect_Click(object sender, EventArgs e)
- {
- using (var BlankPredictionSelect = new BlankPredictionSelect(ob, matInfo3.GetData()))
- {
- if (BlankPredictionSelect.ShowDialog() == DialogResult.OK)
- matInfo3.UpdateData(new CmmWeightRecordEntityFull
- {
- MatName = "连铸圆坯",
- ShippersName = BlankPredictionSelect.ShipperName,
- RecordNumber = BlankPredictionSelect.ListMatNo == null ? null : BlankPredictionSelect.ListMatNo.Sum(p => p.ActCount),
- ReceiveName = "江苏天淮钢管有限公司",
- Memo = BlankPredictionSelect.Memo,
- MatInfos =
- BlankPredictionSelect.ListMatNo ?? new List<CmmWeightMatEntity> { new CmmWeightMatEntity() }
- });
- }
- }
- private void uteChangeType_EditorButtonClick(object sender, EditorButtonEventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- string type;
- string name;
- using (var changeType = new ChangeType { Type = current.RecordType })
- {
- var result = changeType.ShowDialog();
- if (result != DialogResult.OK) return;
- type = changeType.Type;
- name = changeType.TypeName;
- }
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.RecordServer",
- MethodName = "DoUpdateType",
- ServerParams = new object[]
- {
- current.RecordNo,
- type,
- name
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.ToString2().Contains("成功"))
- Query();
- }
- }
- private void ugData_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
- {
- var dex = e.RowScrollRegion.FirstRow;
- dex.Activate();
- }
- private void CurrentGrid_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
- {
- /* UltraGridRow dex = e.RowScrollRegion.FirstRow;
- dex.Activate();*/
- }
- private void ugData_AfterRowActivate(object sender, EventArgs e)
- {
- ugData.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
- }
- private void ugData_BeforeRowDeactivate(object sender, CancelEventArgs e)
- {
- ugData.ActiveRow.RowSelectorAppearance.ResetBackColor();
- }
- private void CurrentGrid_BeforeRowDeactivate(object sender, CancelEventArgs e)
- {
- CurrentGrid.ActiveRow.RowSelectorAppearance.ResetBackColor();
- }
- private void utbSelect2_Click(object sender, EventArgs e)
- {
- var carNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
- var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
- var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", new object[] { carNo }, ob);
- if ((dt != null) && (dt.Rows.Count > 0) && (dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"))
- {
- cmmWeightRecordEntityFull.ShippersName = "天津钢管制造有限公司";
- cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
- cmmWeightRecordEntityFull.ReceiveName = "江苏天淮钢管有限公司";
- cmmWeightRecordEntityFull.RecordNumber =
- dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
- decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
- cmmWeightRecordEntityFull.MatName = "连铸圆坯";
- cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
- for (var i = 0; i < dt.Rows.Count; i++)
- {
- var dtcRow = dt.Rows[i];
- var cmmWeightMatEntity = new CmmWeightMatEntity
- {
- JudgeStoveNoOld = dtcRow["STOVE_NO"].ToString2(),
- JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
- ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
- ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
- ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
- DocumentNo = dtcRow["OUTSTOCK_DOC"].ToString2(),
- ProOrderNo = dtcRow["ORDER_NO"].ToString2(),
- OrderNo = dtcRow["ORDER_NO"].ToString2(),
- OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
- OrdNoPk = dtcRow["ORD_PK"].ToString2(),
- Produccode = dtcRow["PRODUCCODE"].ToString2(),
- Producname = dtcRow["PRODUCNAME"].ToString2(),
- Gradecode = dtcRow["GRADECODE"].ToString2(),
- Gradename = dtcRow["GRADENAME"].ToString2(),
- Steelcode = dtcRow["GRADECODE"].ToString2(),
- Steelname = dtcRow["GRADENAME"].ToString2()
- };
- cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
- }
- matInfo3.SetDefault(cmmWeightRecordEntityFull);
- }
- else
- {
- MessageBox.Show("未找到该车的出库记录!");
- }
- }
- //TODO
- /// <summary>
- /// 必须先打开连接
- /// </summary>
- private bool GetIPVideo(CmmBaseSpotInfoEntity video)
- {
- try
- {
- DhCameraShot tt = new DhCameraShot();
- CarCache.cameraShots = tt;
- CarCache.cameraShots.ip = video.VideoIp;
- CarCache.cameraShots.port = video.VideoPort;
- CarCache.cameraShots.uid = video.VideoUserName;
- CarCache.cameraShots.pwd = video.VideoPassword;
- CarCache.cameraShots.Connection();
- }
- catch (Exception ex)
- {
- Console.WriteLine("异常" + ex.StackTrace);
- // setMsgInfo(txtMsgInfo, "视频连接打开失败:" + ex.Message, "");
- //MessageBox.Show(ex.Message);
- return false;
- }
- return true;
- }
- //如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
- public void setMsgInfo(Control control, string ResultMessage, string sType)
- {
- setMsgMsg(control, ResultMessage, sType);
- }
- /// <summary>
- /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable 3为check
- /// </summary>
- /// <param name="control"></param>
- /// <param name="ResultMessage"></param>
- /// <param name="sType"></param>
- private void setMsgMsg(Control control, string ResultMessage, string sType)
- {
- if (control.InvokeRequired)
- {
- Action<Control, string, string> action = new Action<Control, string, string>(setMsgInfo);
- Invoke(action, new object[] { control, ResultMessage, sType });
- }
- else
- {
- if (ResultMessage != "true" && ResultMessage != "false")
- {
- control.Text = ResultMessage == null ? "" : ResultMessage.Replace("请远程求助", "").Replace(",请点击语音求助", "");
- }
- else
- {
- switch (sType)
- {
- case "1":
- control.Enabled = ResultMessage == "true" ? true : false;
- ; break;
- case "2":
- control.Visible = ResultMessage == "true" ? true : false;
- ; break;
- case "3":
- ((CheckBox)control).Checked = ResultMessage == "true" ? true : false;
- break;
- default: break;
- }
- }
- }
- }
- //private bool bVoice = false;
- /// <summary>
- /// 必须先打开视频,然后再打开语音
- /// </summary>
- private void VoiceOpen()
- {
- try
- {
- //if (CarCache.cameraShots.StartTalk())
- //{
- // // btnOpenVoice.Text = "关闭对讲";
- // bVoice = true;
- // }
- }
- catch (Exception ex)
- {
- // setMsgInfo(txtMsgInfo, "打开语音失败:" + ex.Message, "");
- //MessageBox.Show("打开语音失败:" + ex.Message);
- }
- }
- /// <summary>
- /// 关闭语音对讲
- /// </summary>
- private void VoiceClose()
- {
- try
- {
- //if (CarCache.cameraShots.StopTalk())
- //{
- // // setMsgInfo(btnOpenVoice, "打开对讲", "");
- // bVoice = false;
- //}
- }
- catch (Exception ex)
- {
- // setMsgInfo(txtMsgInfo, "打开对讲失败:" + ex.Message, "");
- //MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 对讲
- /// </summary>
- private void btnOpenVoice_Click(object sender, EventArgs e)
- {
- if (panel1.Controls.Count > 0)
- {
- //if (btnOpenVoice.Text == "打开对讲")
- //{
- // VoiceOpen();
- //}
- //else
- //{
- // VoiceClose();
- //}
- }
- }
- /// <summary>
- /// 关闭视频
- /// </summary>
- private void IPVideoClose()
- {
- try
- {
- CarCache.cameraShots.Close();
- }
- catch (Exception ex)
- {
- // setMsgInfo(txtMsgInfo, "关闭对讲失败:" + ex.Message, "");
- //MessageBox.Show(ex.Message);
- }
- }
- private void setPicBoxSet()
- {
- for (int i = 1; i < 5; i++)
- {
- PictureBox pb = new PictureBox();
- pb.Name = "pb" + i;
- pb.Dock = DockStyle.Top;
- pb.Height = 180;
- pb.DoubleClick += new EventHandler(PictureBoxDoubleClick);
- pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- PicPnl.Controls.Add(pb);
- CarCache.cameraShots.RealPlay(pb, i);
- }
- }
- private void PictureBoxDoubleClick(object sender, EventArgs e)
- {
- if (iPic != 0)
- {
- CarCache.cameraShots.StopRealPlay(iPic);
- }
- PictureBox picture = (PictureBox)sender;
- if (plImgShow.Visible == false)
- {
- // plImgShow.Location = new Point(170, 140);
- plImgShow.Width = tbMain.Width - plImgShow.Location.X;
- plImgShow.Height = tbMain.Height - plImgShow.Location.Y;
- }
- iPic = Convert.ToInt32(picture.Name.Substring(picture.Name.Length - 1, 1));
- plImgShow.Visible = true;
- CarCache.cameraShots.RealPlay(pictureShow, iPic);
- }
- private int iPic = 0;
- /// <summary>
- /// 不显示大图
- /// </summary>
- private void pictureShow_DoubleClick(object sender, EventArgs e)
- {
- plImgShow.Visible = false;
- CarCache.cameraShots.StopRealPlay(iPic);
- iPic = 0;
- }
- private void UpdatePointState(CmmMonitorEntity Cmm)
- {
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.CmmMonitorServer",
- MethodName = "DoUpdateisTakeOver ",
- ServerParams = new object[]
- {
- JSONFormat.Format(Cmm)
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- }
- private void btn_SelectedValueChanged(object sender, EventArgs e)
- {
- //tzh 24.11.8 测试 改成10
- lblWtNow.Text = "0.00t";
- CleanCloseDb();
- if (communicationnow != null)
- {
- communicationnow.Communication.Show = false;
- communicationnow.Communication.Stop();
- communicationnow.Communication.ReceiveData -= defultClenttEntity_ReceiveData;
- }
- communicationnow = null;
- Button btnConect = sender as Button;
- //foreach (Control a in ultraPanel21.Controls)//遍历控件有问题,在demo里面测试没有问题
- //{
- // if (a is Button)
- // {
- // a.ForeColor = a.Tag.ToString() == btnConect.Tag.ToString() ? Color.Blue : Color.Green;
- // }
- //}
- if (btnConect.Tag.ToString() == "A")
- {
- btnA.BackColor = Color.Red;
- // btnB.BackColor = btnC.BackColor = Color.Green;
- }
- if (btnConect.Tag.ToString() == "B")
- {
- btnB.BackColor = Color.Red;
- // btnA.BackColor = btnC.BackColor = Color.Green;
- }
- if (btnConect.Tag.ToString() == "C")
- {
- btnC.BackColor = Color.Red;
- // btnB.BackColor = btnA.BackColor = Color.Green;
- }
- PbCache.Load();
- PbCache.sportInfo = CmmBaseSpotInfo.First(p => p.BaseSpotNo == btnConect.Tag.ToString());
- communicationnow = new CommunicationEntity();
- communicationnow.PoundNo = PbCache.sportInfo.BaseSpotNo;
- communicationnow.Communication = new SocketClient
- {
- Ip = PbCache.sportInfo.WeightIp,
- Port = PbCache.sportInfo.WeightPort,
- Show = false
- };
- communicationnow.PoundNo = PbCache.sportInfo.BaseSpotNo;
- communicationnow.Communication.Show = true;
- WeightLoad(communicationnow.Communication, communicationnow.PoundNo);
- GetIPVideo(PbCache.sportInfo);
- setPicBoxSet();
- }
- /// <summary>
- /// 启动采集
- /// </summary>
- /// <param name="communication"></param>
- private void WeightLoad(iCommunication communication, string PNO)
- {
- communication.ReceiveData += defultClenttEntity_ReceiveData;
- CmmBaseProtocolEntity cmmBaseProtocol = null;
- cmmPoundBase = poundInfos.First(p => p.PoundNo == PNO);
- 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;
- }
- communication.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol));
- utbConnect_Click(null, null);
- }
- /// <summary>
- /// 保存重量数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- //private void timer1_Tick(object sender, EventArgs e)
- //{
- // double wt;
- // if (double.TryParse(lblWtNow.Text.Replace("t", ""), out wt))
- // {
- // if (wt >= 0.5)
- // {
- // if (PbCache.isLockFrm == false)
- // {
- // PbCache.dtStartTime = DateTime.Now;
- // PbCache.isLockFrm = true;
- // }
- // if (communicationnow == null)
- // return;
- // var info = CmmBaseSpotInfo.First(t => t.BaseSpotNo == communicationnow.PoundNo);
- // var template = new CmmMonitorWeightEntity
- // {
- // WeightNo = Guid.NewGuid().ToString(),
- // BaseSpotNo = info.BaseSpotNo,
- // BaseSpotName = info.BaseSpotName,
- // CollectWeight = communicationnow.Communication.WeightValue,
- // CollectStartTime = PbCache.dtStartTime.ToString()
- // };
- // var list = new List<string >();
- // list.Add(JSONFormat.Format(template));
- // var ccp = new CoreClientParam
- // {
- // ServerName = "com.steering.Mcms.CmmMonitorWeightServer",
- // MethodName = "addCmmMonitorInfo",
- // ServerParams = new object[]
- // {
- // list
- // }
- // };
- // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- // }
- // if (wt <= 0.3)
- // {
- // if (communicationnow == null)
- // return;
- // if ( PbCache.isLockFrm == true)
- // {
- // PbCache.isLockFrm = false;
- // var template = new CmmMonitorWeightEntity
- // {
- // BaseSpotNo = PbCache.sportInfo.BaseSpotNo,
- // BaseSpotName = PbCache.sportInfo.BaseSpotName,
- // CollectStartTime = PbCache.dtStartTime.ToString(),
- // CollectEndTime = DateTime.Now.ToString(),
- // ActualFirstNo = PbCache.actualFirstNo
- // };
- // var ccp = new CoreClientParam
- // {
- // ServerName = "com.steering.Mcms.CmmMonitorWeightServer",
- // MethodName = "updateBySpotNoStartTime",
- // ServerParams = new object[]
- // {
- // JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
- // {ContractResolver = new CamelCasePropertyNamesContractResolver()})
- // }
- // };
- // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- // }
- // }
- // else
- // {
- // // MessageBox.Show("数据异常!");
- // return;
- // }
- // }
- //}
- /// <summary>
- /// 接管之前,清空
- /// </summary>
- private void CleanCloseDb()
- {
- //*****************这里需要将语音对讲/视频都关闭*******************
- //退出语音登录
- try
- {
- // VoiceClose();
- IPVideoClose();
- }
- catch (Exception ex)
- {
- }
- // ls = null;
- //*****************************************************************
- // flagCarNo = false;
- setMsgInfo(plImgShow, "false", "2");
- /// DataTable dtJld = dtJGPointInfo.Clone();
- // setGridInfo(ultraGridPW, dtJld, this.dtJGPointInfo);
- // setMsgInfo(lbPointName, "", "");
- // setMsgInfo(lbMeterMan, "", "");
- PbCache.Load();
- PbCache.sportInfo = null;
- CarCache.cameraShots = null;
- // PbCache.relations = null;
- setPanelRemovenfo(PicPnl);
- // bCollectionStart = false;
- //关闭采集进程
- // collection.Stop();
- }
- private void GetRecord_No(string carNO, string state)
- {
- var dic = new Dictionary<string, object>();
- if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
- dic.Add("poundNo", cboPoundList.Text);
- dic.Add("validflag", new List<string> { state });
- var list = EntityHelper.GetData<CmmWeightRecordEntity>(
- "com.steering.Mcms.RecordServer.doQueryRecord",
- new object[] { dic },
- ob).Where(p => p.CarNo == carNO).OrderByDescending(p => p.RecordDate).FirstOrDefault();
- }
- public void setPanelRemovenfo(Panel control)
- {
- setPanelRemoveMsg(control);
- }
- /// <summary>
- /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
- /// </summary>
- /// <param name="control"></param>
- /// <param name="ResultMessage"></param>
- /// <param name="sType"></param>
- private void setPanelRemoveMsg(Panel p)
- {
- if (p.InvokeRequired)
- {
- Action<Panel> action = new Action<Panel>(setPanelRemovenfo);
- Invoke(action, new object[] { p });
- }
- else
- {
- for (int i = p.Controls.Count - 1; i >= 0; i--)
- {
- p.Controls.RemoveAt(i);
- }
- }
- }
- //private void button1_Click(object sender, EventArgs e)
- //{
- // DhCameraShot tt = new DhCameraShot();
- // CarCache.cameraShots = tt;
- // //todu
- // CarCache.cameraShots.ip = "192.168.21.54";
- // CarCache.cameraShots.port = "8000";
- // CarCache.cameraShots.uid = "admin";
- // CarCache.cameraShots.pwd = "hk123456";
- // CarCache.cameraShots.Connection();
- // setPicBoxSet();
- //}
- //private void button2_Click(object sender, EventArgs e)
- //{
- // imageControl = new ImageControl("192.168.21.220","21","admin", "th2021","1", "/pub/",ob);
- // imageControl.Start();
- // try
- // {
- // PbCache.sportInfo = new CmmBaseSpotInfoEntity();
- // PbCache.sportInfo.BaseSpotNo = "testno";
- // PbCache.actualFirstNo = "actualFirstNo";
- // //string strPath = System.Environment.CurrentDirectory +@"\imgShort\formalImg\" +PbCache.sportInfo.BaseSpotNo +"_"+ "PbCache.actualFirstNo" +"_"+ "7.jpg";
- // //Rectangle r = Screen.PrimaryScreen.Bounds;
- // //Image img = new Bitmap(r.Width, r.Height);
- // //Graphics g = Graphics.FromImage(img);
- // //g.CopyFromScreen(new Point(0, 0), new Point(0, 0), r.Size);
- // //img.Save(strPath);
- // // 截取屏幕信息
- // // PbCache.actualFirstNo = CmmImage.ActualFirstNo;
- // Point screenPoint = this.PointToScreen(new Point());
- // Rectangle rect = new Rectangle(screenPoint, this.Size);
- // Image img = new Bitmap(rect.Width, rect.Height);
- // Graphics g = Graphics.FromImage(img);
- // g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
- // img.Save(string.Format("{0}\\imgShort\\formalImg\\{1}_{2}_{3}.jpg",
- // AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
- // PbCache.sportInfo.BaseSpotNo,
- // "C" + PbCache.actualFirstNo,
- // 5), System.Drawing.Imaging.ImageFormat.Jpeg);// 最后一张图片名称写死了
- // //最后进行截图操作
- // CameraShotCls cameraShot = new CameraShotCls();
- // // CarCache.cameraShots.CapMethod("PbCache.actualFirstNo");
- // cameraShot.CapMethod(PbCache.actualFirstNo);
- // //*/
- // }
- // catch (Exception ex)
- // {
- // // l.WriteLog(5, PbCache.lockCarNo + "截图失败");
- // MessageBox.Show(ex.ToString());
- // }
- //}
- //private void button3_Click(object sender, EventArgs e)
- //{
- // communicationnow = new CommunicationEntity();
- // communicationnow.Communication = new SocketClient
- // {
- // Ip = "127.0.0.1",
- // Port = "4001",
- // Show = true
- // };
- // communicationnow.PoundNo = "A";
- // communicationnow.Communication.Show = true;
- // WeightLoad(communicationnow.Communication, communicationnow.PoundNo);
- //}
- private void playVioce(string btName)
- {
- try
- {
- bool rets;
- // CarCache.cameraShots.Connection();
- rets = CarCache.cameraShots.PlayMusic(System.Environment.CurrentDirectory + "\\sound\\称重完成.wav");
- // if (rets) MessageBox.Show("【 称重完成】语音播放成功!");
- }
- catch (Exception ex)
- {
- ex.ToString();
- }
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- try
- {
- if (communicationnow != null && communicationnow.Communication.Show == true)
- {
- var c4 = new CmmLoadinfoEntity
- {
- Loadip = strip,
- BaseSpotNo = communicationnow.PoundNo,
- };
- var ccp4 = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.CmmLoadinfoServer",
- MethodName = "addLoadinfo",
- ServerParams = new object[]
- {
- JSONFormat.Format(c4)
- }
- };
- ccp4 = ExecuteNonQuery(ccp4, CoreInvokeType.Internal);
- }
- GetColorsAsync();
- }
- catch
- { }
- }
- private async Task GetColorsAsync()
- {
- try
- {
- loadinfo = await Task.Run(() => EntityHelper.GetData<CmmLoadinfoCEntity>(
- "com.steering.Mcms.CmmLoadinfoServer.queryAll",
- new object[] { },
- ob));
- // 确保这里的getColor是同步且不耗时,处理UI时要在UI线程
- getColor(btnB);
- getColor(btnA);
- getColor(btnC);
- }
- catch (Exception ex)
- {
- // 你可以选择记录异常,或者提示
- Console.WriteLine(ex);
- }
- }
- /// <summary>
- /// 通过系统时间和最近一次时间对比,判断是否在线
- /// </summary>
- /// <param name="b"></param>
- void getColor(Control b)
- {
- Button btnco = (Button)b;
- if (communicationnow != null && btnco.Tag.ToString() == communicationnow.PoundNo && communicationnow.Communication.Show == true)
- {
- btnco.BackColor = Color.Red;
- return;
- }
- int countco = 0;
- foreach (var p in loadinfo)
- {
- DateTime updatetime = Convert.ToDateTime(p.Actualtime);
- DateTime time = Convert.ToDateTime(p.UpdateTime);
- TimeSpan ts = updatetime - time;
- // 逻辑没变,只简化判断
- if (ts.TotalSeconds <= 7)
- {
- if (btnco.Tag.ToString() == p.BaseSpotNo.ToString() && p.Loadip != strip)
- {
- countco++;
- }
- }
- }
- if (countco == 0)
- btnco.UseVisualStyleBackColor = true;
- else
- btnco.BackColor = Color.Green;
- }
- void addActual(string spot, string record)
- {
- var c2 = new CmmActualWeightEntity
- {
- BaseSpotNo = spot,
- RecordNo = record,
- };
- var ccp3 = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.CmmActualWeightServer",
- MethodName = "addActualWeight",
- ServerParams = new object[]
- {
- JSONFormat.Format(c2)
- }
- };
- ccp3 = ExecuteNonQuery(ccp3, CoreInvokeType.Internal);
- }
- private void btn_Click(object sender, EventArgs e)
- {
- //tzh 24.11.8 测试 改成10
- lblWtNow.Text = "0.00t";
- CleanCloseDb();
- if (communicationnow != null)
- {
- communicationnow.Communication.Show = false;
- communicationnow.Communication.Stop();
- communicationnow.Communication.ReceiveData -= defultClenttEntity_ReceiveData;
- }
- communicationnow = null;
- lblStatus.SafeRefreshControl(() => lblStatus.Text = "重量采集已断开");
- }
- private void ugData_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
- {
- var current = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if ((current == null) || ("" == current.ResultNo)) return;
- var loadinfo1 = EntityHelper.GetData<CmmWorkImageEntity>(
- "com.steering.Mcms.CmmWorkImageServer.doQuery",
- new object[] { current.RecordNo1 },
- ob);
- var loadinfo2 = EntityHelper.GetData<CmmWorkImageEntity>(
- "com.steering.Mcms.CmmWorkImageServer.doQuery",
- new object[] { current.RecordNo2 },
- ob);
- if ((loadinfo1.Count == 0) && (loadinfo2.Count == 0))
- {
- MessageBox.Show("没有单号" + current.ResultNo + "图片记录");
- return;
- }
- Form form = frmLocalTruckImageShow.GetSingleton(ob, current, CmmBaseSpotInfo[0]); // 有参数
- form.Show();
- form.Activate();
- }
- private void uctMemo_EditorButtonClick(object sender, EditorButtonEventArgs e)
- {
- if (cmmPoundBase == null)
- {
- MessageBox.Show(@"无磅房权限");
- return;
- }
- var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
- string Memo;
- using (var update = new ChangeMemo { Memo = current.Memo })
- {
- var result = update.ShowDialog();
- if (result != DialogResult.OK) return;
- Memo = update.Memo;
- }
- var ccp = new CoreClientParam
- {
- ServerName = "com.steering.Mcms.RecordServer",
- MethodName = "DoUpdateMemo",
- ServerParams = new object[]
- {
- current.RecordNo,
- Memo
- }
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
- Query();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- playVioce("称重完成");
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- lblWt.Text = "1.00t";
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // playVioce("称重完成");
- lblWt.Text = "2.00t";
- }
- private void checkBox3_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox3.Checked)
- {
- qitahuipi.Visible = true;
- }
- else
- {
- qitahuipi.Visible = false;
- }
- }
- private void ultraButton2_Click(object sender, EventArgs e)
- {
- using (var BlankPredictionSelect = new BlankPredictionSelect(ob, matInfo20.GetData()))
- {
- if (BlankPredictionSelect.ShowDialog() == DialogResult.OK)
- matInfo20.UpdateData(new CmmWeightRecordEntityFull
- {
- MatName = "连铸圆坯",
- ShippersName = BlankPredictionSelect.ShipperName,
- RecordNumber = BlankPredictionSelect.ListMatNo == null ? null : BlankPredictionSelect.ListMatNo.Sum(p => p.ActCount),
- ReceiveName = "江苏天淮钢管有限公司",
- Memo = BlankPredictionSelect.Memo,
- MatInfos =
- BlankPredictionSelect.ListMatNo ?? new List<CmmWeightMatEntity> { new CmmWeightMatEntity() }
- });
- }
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox1.Checked)
- {
- chkSteelCar.Visible = false;
- chkGross.Visible = false;
- }
- else
- {
- chkGross.Visible = true;
- chkSteelCar.Visible = true;
- }
- }
- private void qitahuipi_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
- {
- LoadTem2();
- if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
- (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
- {
- ultraButton2.Visible = true;
- }
- else
- {
- ultraButton2.Visible = false;
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- cmmPoundBase = poundInfos.First(p => p.PoundNo == "A");
- }
- private void chkSteelCar_CheckedChanged(object sender, EventArgs e)
- {
- if (chkSteelCar.Checked == true)
- {
- checkBox1.Visible = false;
- }
- else
- {
- checkBox1.Visible = true;
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Query();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- button1_Click(null, null);
- }
- private void LoadTem2()
- {
- if (_templateList == null) return;
- var key = GetKey2();
- if (string.IsNullOrWhiteSpace(key)) return;
- if ((_cmmInputRecordEntities != null) && _cmmInputRecordEntities.Any())
- {
- var 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 => CheckShowKey(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 GetKey2()
- {
- 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")&& qitahuipi.Visible==true
- ? qitahuipi.ActiveTab.Key
- : "";
- }
- private void utbSaveAsT2_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 = GetKey2(),
- 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("保存成功!"))
- LoadTempate2();
- }
- }
- }
- private void LoadTempate2()
- {
- /* if (cmmPoundBase == null)
- return;
- */
- _templateList = EntityHelper.GetData<CmmRecordTemplateEntity>(
- "com.steering.Mcms.TemplateServer.doQueryTempate",
- new object[] { "" },
- ob);
- qitahuipi_SelectedTabChanged(null, null);
- }
- private void btnPlay_Click(object sender, EventArgs e)
- {
- try
- {
- bool rets;
- // CarCache.cameraShots.Connection();
- rets = CarCache.cameraShots.PlayMusic(System.Environment.CurrentDirectory + "\\sound\\"+ cmbVioce.Text+".wav");
- // if (rets) MessageBox.Show("【 称重完成】语音播放成功!");
- }
- catch (Exception ex)
- {
- ex.ToString();
- }
- }
- private void ultraButton3_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null) return;
- var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
- if (data == null) return;
- if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
- DialogResult.No))
- {
- }
- else
- {
- Print2(data.ResultNo);
- }
- }
- private void CX_HT_ValueChanged(object sender, EventArgs e)
- {
- //string v_carno;
- string v_cus;
- string v_material;
- string v_name;
- var matInfo = GetMatInfo2();
- if (!CX_HT.Text.ToString().Equals(""))
- {
- DataTable dt = ServerHelper.GetData("com.steering.Mcms.TemplateServer.SelectCX2", new object[] { CX_HT.Value.ToString() }, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- v_cus = dt.Rows[0]["CUS_NAME"].ToString2();
- v_material = dt.Rows[0]["MATERIAL_NAME"].ToString2();
- v_name = v_material + '-' + v_cus;
- tb_order.Text = dt.Rows[0]["BILL_STATUS"].ToString2();
- CmmWeightRecordEntityFull xx = new CmmWeightRecordEntityFull() { MatName = v_material, ReceiveName = v_cus, ShippersName = "江苏天淮钢管有限公司" };
- if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, v_name);
- }
- }
- else
- {
- tb_order.Text = "";
- CmmWeightRecordEntityFull xx = new CmmWeightRecordEntityFull() { MatName = "", ReceiveName = "", ShippersName = "" };
- if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, "");
- }
- // if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, '1');
- }
- }
- }
|