public void Refresh(string channelCode)
 {
     OrderDal orderDal = new OrderDal();
     string condition = "";
     if (channelCode != "")
     {
         condition=string.Format("WHERE A.CHANNELCODE='{0}'", channelCode);
     }
     gridControl.DataSource = orderDal.FindHandSupply(condition);
 }
 public void Refresh(int sortNo)
 {
     if (sortNo != -1)
     {
         gridControl.DataSource = channelDal.FindChannelQuantity(sortNo);
     }
     else
     {
         OrderDal orderDal = new OrderDal();
         string sortNo_A = orderDal.FindMaxSortedMaster("A");
         string sortNo_B = orderDal.FindMaxSortedMaster("B");
         DataTable channel = channelDal.FindAllChannelQuantity(sortNo_A, sortNo_B);
         short[] quantity = new short[140];
         object state_A = Ops.Read(Global.ServiceName_SortingOPC,"A_Led_Process_Check");
         if (state_A is Array)
         {
             Array arrayA = (Array)state_A;
             if (arrayA.Length == 70)
             {
                 arrayA.CopyTo(quantity, 0);
             }
         }
         object state_B = Ops.Read(Global.ServiceName_SortingOPC, "B_Led_Process_Check");
         if (state_B is Array)
         {
             Array arrayB = (Array)state_B;
             if (arrayB.Length == 70)
             {
                 arrayB.CopyTo(quantity, 70);
             }
         }
         for (int i = 0; i < channel.Rows.Count; i++)
         {
             if (i < 70)
             {
                 channel.Rows[i]["SORTQUANTITY"] = Convert.ToInt32(channel.Rows[i]["SORTQUANTITY"]) - quantity[Convert.ToInt32(channel.Rows[i]["CHANNELADDRESS"]) - 1];
                 channel.Rows[i]["REMAINQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) + quantity[Convert.ToInt32(channel.Rows[i]["CHANNELADDRESS"]) - 1];
                 channel.Rows[i]["BOXQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) / 50;
                 channel.Rows[i]["ITEMQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) % 50;
             }
             if (i >= 70)
             {
                 channel.Rows[i]["SORTQUANTITY"] = Convert.ToInt32(channel.Rows[i]["SORTQUANTITY"]) - quantity[Convert.ToInt32(channel.Rows[i]["CHANNELADDRESS"]) + 69];
                 channel.Rows[i]["REMAINQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) + quantity[Convert.ToInt32(channel.Rows[i]["CHANNELADDRESS"]) + 69];
                 channel.Rows[i]["BOXQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) / 50;
                 channel.Rows[i]["ITEMQUANTITY"] = Convert.ToInt32(channel.Rows[i]["REMAINQUANTITY"]) % 50;
             }
         }
         gridControl.DataSource = channel;
         //todo:刷新LED
         //Global.Context.Processes["LEDProcess"].Resume();
         //Global.Context.ProcessDispatcher.WriteToProcess("LEDProcess", "Check", null);
     }
 }
        public void Refresh(string channelGroup, string position, string itemName)
        {
            object cacheObj = Ops.Read(Global.ServiceName_SortingOPC, itemName);
            int sortNoStart, frontQuantity, laterQuantity, sumQuantity;
            DataTable table = null;
            if (cacheObj is Array)
            {
                Array arraycache = (Array)cacheObj;
                if (arraycache.Length == 3)
                {
                    sortNoStart =Convert.ToInt32( arraycache.GetValue(0));
                    frontQuantity = Convert.ToInt32(arraycache.GetValue(2));
                    laterQuantity = Convert.ToInt32(arraycache.GetValue(1));
                    sumQuantity = frontQuantity + laterQuantity;
                    OrderDal orderDal = new OrderDal();
                    DataTable orderTable = orderDal.FindDetailForCacheOrderQuery(channelGroup, sortNoStart);
                    table = orderTable.Clone();
                    if (position == "front")
                    {
                        if (orderTable.Rows.Count != 0)
                        {
                            int tempQuantity = 0;
                            foreach (DataRow orderDetailRow in orderTable.Rows)
                            {
                                int orderQuantity = Convert.ToInt32(orderDetailRow["QUANTITY"]);
                                tempQuantity = tempQuantity + orderQuantity;

                                if (tempQuantity >= frontQuantity)
                                {
                                    orderDetailRow["QUANTITY"] = orderQuantity + frontQuantity - tempQuantity;
                                    table.ImportRow(orderDetailRow);
                                    break;
                                }
                                else
                                {
                                    table.ImportRow(orderDetailRow);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (orderTable.Rows.Count != 0)
                        {
                            int tempQuantity = 0;
                            foreach (DataRow orderDetailRow in orderTable.Rows)
                            {
                                int orderQuantity = Convert.ToInt32(orderDetailRow["QUANTITY"]);
                                if(tempQuantity+orderQuantity<=frontQuantity)
                                {
                                    tempQuantity+=orderQuantity;
                                }
                                else if(tempQuantity<=frontQuantity)
                                {
                                    if(tempQuantity+orderQuantity<=sumQuantity)
                                    {
                                        orderDetailRow["QUANTITY"] = tempQuantity + orderQuantity - frontQuantity;
                                        table.ImportRow(orderDetailRow);
                                        tempQuantity+=orderQuantity;
                                    }
                                    else
                                    {
                                        orderDetailRow["QUANTITY"]=laterQuantity;
                                        table.ImportRow(orderDetailRow);
                                        break;
                                    }
                                }
                                else if (tempQuantity > frontQuantity && tempQuantity<sumQuantity)
                                {
                                    if (tempQuantity+orderQuantity<=sumQuantity)
                                    {
                                        table.ImportRow(orderDetailRow);
                                        tempQuantity+=orderQuantity;
                                    }
                                    else
                                    {
                                        orderDetailRow["QUANTITY"] = sumQuantity-tempQuantity;
                                        table.ImportRow(orderDetailRow);
                                        break;
                                    }
                                }
                                else if (tempQuantity >= sumQuantity)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            gridControl.DataSource = table;
        }