示例#1
0
 private void btnInsert_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < 30; i++)
     {
         WorkOrder order = new WorkOrder();
         order.Length       = i + 100;
         order.Thickness    = 50;
         order.Width        = 100 + i * 10;
         order.Gross        = 50;
         order.GrossWidth   = order.Width * order.Gross;
         order.Undo         = order.GrossWidth;
         order.ScheduleDate = DateTime.Now;
         order.ProductOrder = DateTime.Now.ToString("yyyyMMddHHmmss") + i.ToString();
         order.Status       = 1;
         Global.mysqlHelper.ExecuteSql(order.InsertSQL());
     }
 }
示例#2
0
        private void sendNewOrders(int thickness)
        {
            FlushProcData();
            Global.runMode = RunMode.WRITE;
            string sql = "insert into working " +
                         "(id, productorder, type, scheduledate, lenth, width, thickness, gross, done, undone," +
                         "completedate, machinecode, worker, worth, remark, status, receivedate, grosswidth)" +
                         "select* from workorder a where a.status = 1 and a.thickness = " + thickness.ToString();

            Global.mysqlHelper.ExecuteSql(sql);
            sql = "update workorder a, working b set a.status = 2 where a.id = b.id";
            Global.mysqlHelper.ExecuteSql(sql);

            StringBuilder sb = new StringBuilder();

            sb.Append("update working set status = 2 where id in (");
            DataTable dt = Global.mysqlHelper.GetDataTable("select * from working order by workingid asc");

            byte[] sendbuf = new byte[400];
            int    count   = dt.Rows.Count;

            //判断订单数是否大于设备最大订单数30
            if (count > 30)
            {
                Global.isDataOver = true;
            }
            else
            {
                Global.isDataOver = false;
            }

            //判断是否可以一次发完
            Global.isSendAll = true;
            if (count > Global.dataCount)
            {
                Global.isSendAll = false;
                count            = Global.dataCount;
            }
            sendbuf[0] = Global.stationAddr;
            sendbuf[1] = Global.writeCmd;
            sendbuf[2] = (byte)(Global.offset / 256);
            sendbuf[3] = (byte)(Global.offset % 256);
            sendbuf[4] = (byte)(Global.dataCount * 6 / 256);
            sendbuf[5] = (byte)(Global.dataCount * 6 % 256);
            sendbuf[6] = (byte)(Global.dataCount * 12);

            for (int i = 0; i < count; i++)
            {
                WorkOrder order = new WorkOrder(dt.Rows[i]);
                sendbuf[7 + 12 * i]     = (byte)((order.Length << 16) >> 24);
                sendbuf[7 + 12 * i + 1] = (byte)((order.Length << 24) >> 24);
                sendbuf[7 + 12 * i + 2] = (byte)(order.Length >> 24);
                sendbuf[7 + 12 * i + 3] = (byte)((order.Length << 8) >> 24);

                sendbuf[7 + 12 * i + 4] = (byte)((order.GrossWidth << 16) >> 24);
                sendbuf[7 + 12 * i + 5] = (byte)((order.GrossWidth << 24) >> 24);
                sendbuf[7 + 12 * i + 6] = (byte)(order.GrossWidth >> 24);
                sendbuf[7 + 12 * i + 7] = (byte)((order.GrossWidth << 8) >> 24);

                sendbuf[7 + 12 * i + 8]  = (byte)((order.Done << 16) >> 24);
                sendbuf[7 + 12 * i + 9]  = (byte)((order.Done << 24) >> 24);
                sendbuf[7 + 12 * i + 10] = (byte)(order.Done >> 24);
                sendbuf[7 + 12 * i + 11] = (byte)((order.Done << 8) >> 24);

                sb.Append(order.id.ToString() + ",");
                Global.procData[i].id         = order.id;
                Global.procData[i].Lenth      = order.Length;
                Global.procData[i].Thickness  = order.Thickness;
                Global.procData[i].GrossWidth = order.GrossWidth;
                Global.procData[i].status     = (int)OrderStatus.WORKING;
            }
            uint crc = SystemUnit.getCRC(sendbuf, 0, Global.dataCount * 12 + 7);

            sendbuf[Global.dataCount * 12 + 7] = (byte)(crc / 256);
            sendbuf[Global.dataCount * 12 + 8] = (byte)(crc % 256);
            Global.commHelper.SendControlCmd(sendbuf, Global.dataCount * 12 + 9);
            timerBreak.Enabled = true;
            sb.Append("0)");
            Global.mysqlHelper.ExecuteSql(sb.ToString());
            lblWorkingShowInfo.Text      = "订单发送中……";
            lblWorkingShowInfo.ForeColor = Color.Green;
        }
示例#3
0
 private bool bCheckOrder(WorkOrder order)
 {
     return(true);
 }
示例#4
0
        private void ReceiveMasssage(object clientSocket)
        {
            //Socket myClientSocket = (Socket)clientSocket;
            while (isRun)
            {
                try
                {
                    byte[] buff = new byte[2048];

                    int count = cSocket.Receive(buff);
                    if (count > 5)
                    {
                        if (buff[0] == 0xff && buff[1] == 0xff && buff[2] == 0x01 &&
                            buff[count - 1] == 0xEE && buff[count - 2] == 0xEE)
                        {
                            Response  res   = new Response();
                            string    info  = Encoding.UTF8.GetString(buff, 3, count - 5);
                            WorkOrder order = JsonHelper.DeserializeJsonToObject <WorkOrder>(info);
                            if (!bOrderExist(order.ProductOrder))
                            {
                                if (bCheckOrder(order))
                                {
                                    order.Status      = 1;
                                    order.ReceiveDate = DateTime.Now;
                                    order.GrossWidth  = order.Width * order.Gross;
                                    order.Undo        = order.GrossWidth;
                                    order.Done        = 0;
                                    Global.mysqlHelper.ExecuteSql(order.InsertSQL());

                                    res.Result    = true;
                                    res.Cmd       = 1;
                                    res.ErrorCode = 0;
                                    res.Remark    = "发送成功!";
                                }
                                else
                                {
                                    res.Result    = false;
                                    res.Cmd       = 1;
                                    res.ErrorCode = -1;
                                    res.Remark    = "发送错误!";
                                }
                            }
                            else
                            {
                                res.Result    = false;
                                res.Cmd       = 1;
                                res.ErrorCode = -2;
                                res.Remark    = "该编号订单已存在!";
                            }


                            string resp = JsonHelper.SerializeObject(res);
                            byte[] data = Encoding.UTF8.GetBytes(resp);
                            sendbuff[0] = 0xff;
                            sendbuff[1] = 0xff;
                            sendbuff[2] = 0x10;
                            Buffer.BlockCopy(data, 0, sendbuff, 3, data.Length);
                            sendbuff[data.Length + 3] = 0xEE;
                            sendbuff[data.Length + 4] = 0xEE;
                            cSocket.Send(sendbuff, data.Length + 5, SocketFlags.None);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                }
            }
        }