public void Reset() { if (elOpertor.GetShowModeName() == "mode3") // 数显标签 显示模式 《数显标签》 复位方式不同 { ////设置按键灯 elOpertor.SetKeysState(FuntionState.Close, Convert.ToInt32(0), (FuntionState)0, Convert.ToInt32(0), (FuntionState)0, Convert.ToInt32(0)); elOpertor.SendData(0, new string [] { " " }); ////设置按键灯 elOpertor.SetKeysState(FuntionState.Start, Convert.ToInt32(0), (FuntionState)0, Convert.ToInt32(0), (FuntionState)0, Convert.ToInt32(0)); return; } else { elOpertor.ClearDataQueue(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter1 = new Filter(Storages._Port, _Port.ToString(), ComparisonOperators.Equal); IList <Storages> storages = storagesAccesser.Select <Storages>(filter1, Storages._Address); IEnumerable <Storages> storageslist = storages.Distinct(); foreach (Storages storage in storageslist) { elOpertor.ResetElectronicLabel(int.Parse(storage.Address.Substring(storage.Address.Length - 3, 3))); } } }
private void 清空模拟数据ToolStripMenuItem_Click(object sender, EventArgs e) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); sy_showinfosAccesser.ExecuteNonQuery("Delete from Sy_ShowInfo"); storagesAccesser.ExecuteNonQuery("Update [Storages] Set [Act] = '',[ProductName] = '',[Contents] = '',[Sign] = 0 ,[Err] = 0 ,[NumberShow] =''"); MessageBox.Show("数据清空成功!", "电子标签服务", MessageBoxButtons.OK); }
private void btClear_Click(object sender, EventArgs e) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); sy_showinfosAccesser.ExecuteNonQuery("Delete from Sy_ShowInfo"); //sy_showinfosAccesser.ExecuteNonQuery("Delete from [dbo].[tab_Label]"); storagesAccesser.ExecuteNonQuery("Update [Storages] Set [Act] = '',[ProductName] = '',[Contents] = '',[Sign] = 0 ,[Err] = 0"); MessageBox.Show("数据清空成功!", "电子标签服务", MessageBoxButtons.OK); }
/// <summary> /// 服务启动入口。 /// </summary> /// <param name="form">启动线程的主线程窗体</param> /// <param name="timer">主线程窗体的计时器</param> /// <param name="adapters">串口适配器数组</param> public static void Run() { int getKeyTimer = 0; try { while (true) { // 检查是否有新的数据到达。 while (!IsExistNewData()) { SendData(); Thread.Sleep(1000); MainThreadForm.Invoke(ServiceStatusChanged, 0, "没有新数据到达,等待任务!"); SendData(); Thread.Sleep(1000); getKeyTimer++; if (getKeyTimer > 10) { getKeyTimer = 0; GetKey(); } if (false) { IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); storagesAccesser.ExecuteNonQuery("update storages set sign = 1"); SendData(); } } // 新数据到达延时1000毫秒处理,以便数据接收完整以进行一次处理,以免多次处理影响性能。 Thread.Sleep(1000); // 从接口中间表,同步数据到任务队列(填入编码映射表)。 MainThreadForm.Invoke(ServiceStatusChanged, 1, "开始同步数据到任务队列!"); PushData(); MainThreadForm.Invoke(ServiceStatusChanged, 2, "完成同步数据到任务队列!"); // 从编码映射表取得任务队列进行发送。 MainThreadForm.Invoke(ServiceStatusChanged, 1, "开始任务进行发送!"); SendData(); while (!IsComplete()) { Thread.Sleep(2000); } // 当前任务队列完成发送。 MainThreadForm.Invoke(ServiceStatusChanged, 2, "完成当前任务发送!"); } } catch (Exception e) { MainThreadForm.Invoke(ServiceStatusChanged, 0, "服务停止!" + e.Message); } }
/// <summary> /// 查询,标签按钮状态。 /// </summary> public static void GetKey() // 联控标签 未使用 《联控标签》 { IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter = new Filter(Storages._Sign, 2, ComparisonOperators.Equal); IList <Storages> storages = storagesAccesser.Select <Storages>(filter); foreach (Storages storage in storages) { if (adapters[Convert.ToInt32(storage.Port)].elOpertor.GetShowModeName() == "mode4") { adapters[Convert.ToInt32(storage.Port)].elOpertor.GetKey(int.Parse(storage.Address.Substring(storage.Address.Length - 3, 3))); } } }
private void 填入模似数据ToolStripMenuItem_Click(object sender, EventArgs e) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IList <Storages> storages = storagesAccesser.Select <Storages>(new Filter(), Storages._Address); foreach (Storages storage in storages) { try { sy_showinfosAccesser.ExecuteNonQuery("insert [Sy_ShowInfo] values ('0', 'OrderDetailID','" + storage.StorageID.Trim() + "',1,'红金龙红金龙',30,12,0,0,0,'')"); } catch { } } }
private void btResent_Click(object sender, EventArgs e) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter = new Filter(Sy_ShowInfo._OrderMasterID, txtOrderID.Text.Trim(), ComparisonOperators.Equal); IList <Sy_ShowInfo> sy_showInfo = sy_showinfosAccesser.Select <Sy_ShowInfo>(filter); if (sy_showInfo.Count == 0) { MessageBox.Show("订单号不存在,请检查订单号是否正确!或数据发送失败!", "电子标签服务", MessageBoxButtons.OK); return; } sy_showinfosAccesser.ExecuteNonQuery("update Sy_ShowInfo set ReadState = 0 ,HardwareReadState = 0 ,ConfirmState = 0 where OrderMasterID = '" + txtOrderID.Text.Trim() + "'"); MessageBox.Show("订单重发成功!如无显示请检查订单号是否正确!", "电子标签服务", MessageBoxButtons.OK); }
/// <summary> /// 检查中间表是否有新数据需要处理。 /// </summary> /// <returns>返回是否有新数据需要处理。</returns> public static bool IsExistNewData() { bool bIsExist = false; using (TransactionScope Scope = DBFactory.NewTransactionScope(false)) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter = new Filter(Sy_ShowInfo._ReadState, 0, ComparisonOperators.Equal); IList <Sy_ShowInfo> sy_showinfos = sy_showinfosAccesser.Select <Sy_ShowInfo>(filter); if (sy_showinfos.Count > 0) { bIsExist = true; } } return(bIsExist); }
private void btStart_Click(object sender, EventArgs e) { try { TimerCounter.Enabled = false; toolStripStatusLabel1.Text = "启动服务!"; btStart.Enabled = false; IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); sy_showinfosAccesser.ExecuteNonQuery("update Sy_ShowInfo set ReadState = 1 ,HardwareReadState = 1 ,ConfirmState = 1 "); storagesAccesser.ExecuteNonQuery("Update [Storages] Set [Act] = '',[ProductName] = '',[Contents] = '',[Sign] = 0 ,[Err] = 0 , [NumberShow] = ''"); IList <Storages> storages = storagesAccesser.Select <Storages>("select Port from storages group by port"); if (adapters == null) { adapters = new Adapter[int.Parse(storages.Last().Port) + 256]; foreach (Storages storage in storages) { int port = int.Parse(storage.Port); adapters[port] = new Adapter(); adapters[port].Port = port; adapters[port].Start(); } Service.InitializeService(this, this.toolStripStatusLabel1, this.TimerCounter, adapters); } myThread = new Thread(new ThreadStart(Run)); myThread.Start(); btStop.Enabled = true; btExit.Enabled = false; } catch (Exception ex) { MessageBox.Show("服务启动失败!" + ex.Message, "电子标签服务", MessageBoxButtons.OK); btExit_Click(sender, e); } }
private void button1_Click(object sender, EventArgs e) { IList <Storages> ModifiyStorages = new List <Storages>(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); Storages storage; int j = 1; for (int i = Convert.ToInt32(textBox2.Text); i <= Convert.ToInt32(textBox4.Text); i++) { storage = new Storages();// ZA-A-01-01 storage.StorageID = textBox1.Text.ToString() + "-1-" + j.ToString().PadLeft(1, "0"[0]); storage.StorageName = textBox1.Text.ToString() + "-1-" + j.ToString().PadLeft(1, "0"[0]); storage.Address = textBox3.Text.ToString() + i.ToString().PadLeft(3, "0"[0]); storage.Port = textBox3.Text.ToString(); storage.Row = "1"; ModifiyStorages.Add(storage); storage = new Storages();// ZA-A-01-01 storage.StorageID = textBox1.Text.ToString() + "-2-" + j.ToString().PadLeft(1, "0"[0]); storage.StorageName = textBox1.Text.ToString() + "-2-" + j.ToString().PadLeft(1, "0"[0]); storage.Address = textBox3.Text.ToString() + i.ToString().PadLeft(3, "0"[0]); storage.Port = textBox3.Text.ToString(); storage.Row = "2"; ModifiyStorages.Add(storage); storage = new Storages();// ZA-A-01-01 storage.StorageID = textBox1.Text.ToString() + "-3-" + j.ToString().PadLeft(1, "0"[0]); storage.StorageName = textBox1.Text.ToString() + "-3-" + j.ToString().PadLeft(1, "0"[0]); storage.Address = textBox3.Text.ToString() + i.ToString().PadLeft(3, "0"[0]); storage.Port = textBox3.Text.ToString(); storage.Row = "3"; ModifiyStorages.Add(storage); j++; } storagesAccesser.Insert <Storages>(ModifiyStorages, false); }
/// <summary> /// KeyRaised (int address,int keyNo ,string recv); /// 按键触发事件 /// </summary> /// <param name="address">address:电子标签地址</param> /// <param name="keyNo">keyNo:按键号,共3个按键</param> /// <param name="recv">recv:控制板返回的数据,供调试用</param> private void elOpertor_KeyRaised(int address, int keyNo, string recv) { try { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter1 = new Filter(Storages._Sign, 2, ComparisonOperators.Equal); IFilter filter2 = new Filter(Storages._Address, _Port.ToString() + address.ToString().PadLeft(3, "0"[0]), ComparisonOperators.Equal); IFilter filter3 = new Filter(Storages._Row, (keyNo - 4).ToString().Substring(1, 1), ComparisonOperators.Equal); if (elOpertor.GetShowModeName() == "mode3") { filter3 = new Filter("1", "1", ComparisonOperators.Equal); } IList <Storages> storages = storagesAccesser.Select <Storages>(new FilterTree("{0} and {1} and {2}", new IFilter [] { filter1, filter2, filter3 })); if (storages.Count == 1) { Storages storage = storages.First(); storage.Act = ""; storage.ProductName = ""; storage.Contents = ""; storage.Sign = 0; storage.Err = 0; storage.NumberShow = ""; storagesAccesser.Update(storage); storagesAccesser.ExecuteNonQuery("Update [Storages] Set [Sign] = 1 where [Address] = '" + _Port.ToString() + address.ToString().PadLeft(3, "0"[0]) + "' and [Sign] = 3 "); //++ IFilter filter4 = new Filter(Sy_ShowInfo._HardwareReadState, 1, ComparisonOperators.Equal); IFilter filter5 = new Filter(Sy_ShowInfo._StorageID, storage.StorageID, ComparisonOperators.Equal); IFilter filter6 = new Filter(Sy_ShowInfo._ConfirmState, 0, ComparisonOperators.Equal); IList <Sy_ShowInfo> sy_showinfos = sy_showinfosAccesser.Select <Sy_ShowInfo>(new FilterTree("{0} and {1} and {2}", filter4, filter5, filter6)); if (sy_showinfos.Count == 1) { Sy_ShowInfo sy_showinfo = sy_showinfos.First(); sy_showinfo.ConfirmState = 1; sy_showinfosAccesser.Update(sy_showinfo); url = configUtil.GetConfig("URL")["URL"]; IList <BillDetail> billDetails = new List <BillDetail>(); BillDetail billDetail = new BillDetail(); billDetail.BillNo = sy_showinfo.OrderMasterID.ToString(); billDetail.BillType = sy_showinfo.OperateType.ToString(); billDetail.DetailID = Convert.ToInt32(sy_showinfo.OrderDetailID.ToString()); billDetail.Operator = Environment.MachineName; billDetail.OperatePieceQuantity = Convert.ToInt32(sy_showinfo.OperatePiece); billDetail.OperateBarQuantity = Convert.ToInt32(sy_showinfo.OperateItem); billDetails.Add(billDetail); BillDetail[] tmp = new BillDetail[billDetails.Count]; billDetails.CopyTo(tmp, 0); Task task = new Task(null, url); task.Execute(tmp, "1"); } //++ sy_showinfosAccesser.ExecuteNonQuery("Update [Sy_ShowInfo] set [ConfirmState] = 1 where HardwareReadState =1 and [StorageID] = '" + storage.StorageID + "'"); Service.SendData(); if (false) { string[] data = new string[5]; for (int i = 0; i < 5; i++) { data[i] = ""; } data[keyNo - 1] = "按钮返回成功!!!"; elOpertor.SendData(int.Parse(storage.Address.Substring(storage.Address.Length - 2, 2)), data); } if (false) { DataRabbit.HashOrm.IHashOrmAccesser delAccesser = DataRabbit.HashOrm.DBFactory.NewHashOrmAccesser(DataRabbit.HashOrm.DBFactory.NewTransactionScopeFactory("ServerDataConfig").NewTransactionScope()); delAccesser.ExecuteNonQuery(""); } } } catch (Exception e) { WriteLog(e.Message); } }
private void button2_Click(object sender, EventArgs e) { IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); storagesAccesser.ExecuteNonQuery("delete from storages "); }
/// <summary> /// 组织数据并传入到串口适配器。 /// </summary> /// <param name="adapters">串口适配器数组</param> public static void SendData() { lock (lock1) { using (TransactionScope Scope = DBFactory.NewTransactionScope(false)) { IList <Storages> ModifiyStorages = new List <Storages>(); IList <Sy_ShowInfo> ModifiySy_ShowInfo = new List <Sy_ShowInfo>(); IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter1 = new Filter(Sy_ShowInfo._ReadState, 1, ComparisonOperators.Equal); IFilter filter2 = new Filter(Sy_ShowInfo._HardwareReadState, 0, ComparisonOperators.Equal); sy_showinfosAccesser.SelectToHash <Sy_ShowInfo>(new FilterTree("{0} and {1}", filter1, filter2)); IFilter filter3 = new Filter(Storages._Sign, 0, ComparisonOperators.NotEqual); storagesAccesser.SelectToHash <Storages>(filter3); IFilter filter4 = new Filter(Storages._Sign, 1, ComparisonOperators.Equal); IList <Storages> storages = storagesAccesser.Select <Storages>(filter4); IEnumerable <string> addresses = from storage in storages orderby storage.Address.Substring(storage.Address.Length - 3 - 1, 3), storage.Port.PadLeft(4, "0"[0]) select storage.Address; //++ foreach (string address in addressDictionary.Keys) { IList <Storages> stotagelist = storagesAccesser.Select <Storages, string>(Storages._Address, address); if (addressDictionary[address].ContainsKey(true) && (stotagelist.Count == 0 || addresses.Distinct().Contains(address))) { adapters[Convert.ToInt32(addressDictionary[address][true])].elOpertor.ResetElectronicLabel(int.Parse(address.Substring(address.Length - 3, 3))); //adapters[Convert.ToInt32(addressDictionary[address][true])].elOpertor.SendData(int.Parse(address.Substring(address.Length - 3, 3)),new string[] {"1","2","3","",""}); addressDictionary[address].Remove(true); } } //++ foreach (string address in addresses.Distinct()) { IList <Storages> stotagelist = storagesAccesser.Select <Storages, string>(Storages._Address, address); string _port = ""; string[] data = new string[5]; for (int i = 0; i < 5; i++) { data[i] = ""; } foreach (Storages storage in stotagelist) { string s1, s2, s3, s4; _port = storage.Port; switch (adapters[Convert.ToInt32(storage.Port)].elOpertor.GetShowModeName()) { case "mode1": //货架汉显示标签 显示模式 <大标签> s1 = storage.StorageName.Trim() + " " + storage.Act.Trim() + " " + storage.Contents.Trim() + storage.ProductName.Trim() + "".PadRight(56, " "[0]); s1 = StrHandle.GetStringWith(s1, 56); if (storage.Row == "4") { continue; } if (storage.Row == "3") { if (data[0] != "") { continue; } data[0] = s1; } if (storage.Row == "2") { if (data[1] != "") { continue; } data[1] = s1; } if (storage.Row == "1") { if (data[2] != "") { continue; } data[2] = s1; } break; case "mode2": //条烟柜汉显标签 显示模式 《大标签》 s1 = "储位:" + storage.StorageName.Trim(); s1 = StrHandle.GetStringWith(s1, 30); s2 = "操作:" + storage.Act.Trim(); s2 = StrHandle.GetStringWith(s2, 30); s3 = "品牌:" + storage.ProductName.Trim(); s3 = StrHandle.GetStringWith(s3, 30); s4 = "数量:" + storage.Contents.Trim(); s4 = StrHandle.GetStringWith(s4, 26); data[0] = s1; data[0] = data[0] + s2; data[0] = data[0] + s3; data[0] = data[0] + s4; break; case "mode3": // 数显标签 显示模式 《数显标签》 data[0] = storage.NumberShow; break; case "mode4": // 联控标签 未使用 《联控标签》 break; default: break; } storage.Sign = 2; try { IList <Sy_ShowInfo> sy_showinfolist = sy_showinfosAccesser.Select <Sy_ShowInfo, string>(Sy_ShowInfo._StorageID, storage.StorageID); if (sy_showinfolist.Count == 1) { sy_showinfolist[0].HardwareReadState = 1; ModifiyStorages.Add(new Storages() { StorageID = storage.StorageID, Sign = storage.Sign }); ModifiySy_ShowInfo.Add(sy_showinfolist[0]); } if (adapters[Convert.ToInt32(storage.Port)].elOpertor.GetShowModeName() == "mode1") { if (data[0] != "" && data[1] != "" && data[2] != "") { break; } } if (adapters[Convert.ToInt32(storage.Port)].elOpertor.GetShowModeName() == "mode2") { break; } if (adapters[Convert.ToInt32(storage.Port)].elOpertor.GetShowModeName() == "mode3") { break; } } catch (Exception e) { throw new Exception("e" + e.StackTrace); } } if (_port != "") { //++ addressDictionary[address] = new Dictionary <bool, string>(); addressDictionary[address][true] = _port; //++ adapters[Convert.ToInt32(_port)].elOpertor.SendData(int.Parse(address.Substring(address.Length - 3, 3)), data); } storagesAccesser.ExecuteNonQuery("Update [Storages] Set [Sign] = 3 where [Address] = '" + address + "' and [Sign] = 1 "); } storagesAccesser.Update(ModifiyStorages); sy_showinfosAccesser.Update(ModifiySy_ShowInfo); } } }
/// <summary> /// 同步数据到任务队列。 /// </summary> public static void PushData() { //开始任务前同步标签系统数据。 using (TransactionScope Scope = DBFactory.NewTransactionScope(false)) { IHashOrmAccesser sy_showinfosAccesser = DBFactory.NewHashOrmAccesser(); IHashOrmAccesser storagesAccesser = DBFactory.NewHashOrmAccesser(); IFilter filter1 = new Filter(Sy_ShowInfo._ReadState, 0, ComparisonOperators.Equal); IList <Sy_ShowInfo> sy_showinfos = sy_showinfosAccesser.Select <Sy_ShowInfo>(filter1); IFilter filter2 = new Filter(Storages._Sign, 0, ComparisonOperators.Equal); storagesAccesser.SelectToHash <Storages>(filter2); foreach (Sy_ShowInfo sy_showinfo in sy_showinfos) { IList <Storages> storages = storagesAccesser.Select <Storages, string>(Storages._StorageID, sy_showinfo.StorageID); if (storages.Count == 1) { Storages storage = storages[0]; switch (sy_showinfo.OperateType) { case 1: storage.Act = "入库"; break; case 2: storage.Act = "出库"; break; case 4: storage.Act = "盘点"; break; case 5: storage.Act = "移入"; break; case 6: storage.Act = "移出"; break; case 3: storage.Act = "移库"; break; default: break; } storage.ProductName = sy_showinfo.TobaccoName; if (sy_showinfo.Contents == "") { storage.Contents = (sy_showinfo.OperatePiece > 0 ? sy_showinfo.OperatePiece.ToString() + "件" : "") + (sy_showinfo.OperateItem > 0 ? sy_showinfo.OperateItem + "条" : ""); } else { storage.Contents = sy_showinfo.Contents; } storage.Sign = 1; storage.NumberShow = sy_showinfo.OperateType.ToString().PadLeft(1, "0"[0]) + storage.Row + "-" + sy_showinfo.OperatePiece.ToString().PadLeft(2, "0"[0]); storage.NumberShow = storage.NumberShow[0] + " " + storage.NumberShow[1] + " " + storage.NumberShow[2] + " " + storage.NumberShow[3] + " " + storage.NumberShow[4] + " "; storagesAccesser.Update(storage); sy_showinfo.ReadState = 1; sy_showinfosAccesser.Update(sy_showinfo); } } } }