Ejemplo n.º 1
0
        private void ConfirmORDC(PodpitkaContentItem ordc, DataRow[] r, string message)
        {
            DataRow[] r2 = podpitkaTable.Select("PTL = " + r[0][1]);
            if (r2.Length > 0)
            {
                //r2[0][3] = 1;
                //r2[0][4] = Convert.ToInt32(message.Trim());
                (this.Owner as MainWindow).sqlQueriesToSend.Add("UPDATE ptl_database.podpitkatable" +
                                                                " SET status=1, userId=" + (this.Owner as MainWindow).currentUser + ", actQuant=" + Convert.ToInt32(message.Trim()) + ", podpitkaDate=CURRENT_TIMESTAMP WHERE idPod=" + ordc.RefID + ";");

                foreach (OrderBorder ordbrd in (this.Owner as MainWindow).podpitka_sp.Children.OfType <OrderBorder>())
                {
                    if (ordbrd.ID == Convert.ToInt32(r2[0][0]))
                    {
                        (this.Owner as MainWindow).podpitka_sp.Children.Remove(ordbrd);
                        break;
                    }
                }
                podpitkaTable.Rows.Remove(r2[0]);

                if (podpitkaTable.Rows.Count > 0)
                {
                    (this.Owner as MainWindow).podpitka_tab.Header = "Подпитка (" + podpitkaTable.Rows.Count + ")";
                }
                else
                {
                    (this.Owner as MainWindow).podpitka_tab.Header = "Подпитка";
                }
            }
            ordc.Confirmed = true;
            bool all_confirmed = true;

            foreach (PodpitkaContentItem o in OrdersPanel.Children.OfType <PodpitkaContentItem>())
            {
                if (!o.Confirmed)
                {
                    all_confirmed = false;
                }
            }
            if (all_confirmed)
            {
                this.Confirmed = true;
            }
        }
Ejemplo n.º 2
0
        public PodpitkaWindow(NewComing podpitka_table, DataTable PTLS)
        {
            InitializeComponent();
            this.podpitkaTable = podpitka_table;
            //podpitka_t = podpitka_table;
            PTLs = PTLS;
            //this.order_id = order_id;
            string[] st = { "Gateway", "ID" };
            dt = PTLs.DefaultView.ToTable(true, st);

            dt.Columns[0].ColumnName = "Gateway";
            dt.Columns[1].ColumnName = "ID";

            action_list = new List <Tuple <int, int> > [dt.Rows.Count];

            for (int ind = 0; ind < dt.Rows.Count; ind++)
            {
                action_list[ind] = new List <Tuple <int, int> >();
            }

            this.Owner      = (MainWindow)Application.Current.MainWindow;
            this.ResizeMode = ResizeMode.NoResize;

            this.Loaded += (se, ev) =>
            {
                Start();
            };

            foreach (DataRow row in podpitkaTable.Rows)
            {
                if (Convert.ToInt32(row[3]) == 0)
                {
                    DataRow[] r = PTLs.Select("Global = " + row[1]);
                    if (r.Length > 0)
                    {
                        DataRow[] rw = dt.Select("Gateway = " + r[0][2] + " AND ID = " + r[0][3]);
                        if (rw.Length > 0)
                        {
                            int index           = dt.Rows.IndexOf(rw[0]);
                            Tuple <int, int> t2 = new Tuple <int, int>(Convert.ToInt32(row[0]), Convert.ToInt32(row[2]));
                            action_list[index].Add(t2);
                        }
                    }
                }
            }

            int i = 1;

            string[] s = { "" };
            foreach (DataRow row in podpitkaTable.Rows)
            {
                PodpitkaContentItem ordc = new PodpitkaContentItem(i, Convert.ToInt32(row[0]), s, row[6].ToString(), row[5].ToString(), Convert.ToInt32(row[2]), Convert.ToInt32(row[1]));

                if (Convert.ToInt32(row[3]) == 0)
                {
                    ordc.QuantityCollected = Convert.ToInt32(row[2]);
                }
                else
                {
                    ordc.Confirmed         = true;
                    ordc.QuantityCollected = Convert.ToInt32(row[4]);
                }
                ordc.ShowButtonPressed += (se, ev) =>
                {
                    DataRow[] r = PTLs.Select("Global = " + (se as PodpitkaContentItem).PTL_global);
                    if (r.Length > 0)
                    {
                        ConfirmORDC(se as PodpitkaContentItem, r, (se as PodpitkaContentItem).QuantityCollected.ToString());
                        ((MainWindow)Application.Current.MainWindow).ptlconn.ClearNode(Convert.ToInt32(r[0][2]), Convert.ToInt32(r[0][3]));

                        DataRow[] newrows = PTLs.Select("Gateway = " + r[0][2] + "AND ID = " + r[0][3]);

                        /*foreach (DataRow newrow in newrows)
                         * {
                         *  foreach (PodpitkaContentItem pp in OrdersPanel.Children.OfType<PodpitkaContentItem>())
                         *  {
                         *      if (!pp.Confirmed && pp.PTL_global == Convert.ToInt32(newrow[1]))
                         *      {
                         *          Direction dir = Direction.Up;
                         *          if (Convert.ToBoolean(newrow[4]))
                         *              dir = Direction.Down;
                         *          ((MainWindow)Application.Current.MainWindow).ptlconn.SetLEDStatus(Convert.ToInt32(newrow[2]), Convert.ToInt32(newrow[3]), LEDColor.Cyan, LEDStatus.On);
                         *          ((MainWindow)Application.Current.MainWindow).ptlconn.DisplayQuantity(Convert.ToInt32(newrow[2]), Convert.ToInt32(newrow[3]), pp.Quantity, dir, 0, 0);
                         *
                         *      }
                         *  }
                         * }*/

                        DataRow[] rw = dt.Select("Gateway = " + r[0][2] + " AND ID = " + r[0][3]);
                        if (rw.Length > 0)
                        {
                            int index = dt.Rows.IndexOf(rw[0]);
                            int c     = action_list[index].Count;

                            for (int ind = c - 1; ind >= 0; ind--)
                            {
                                if (action_list[index][ind].Item1 == (se as PodpitkaContentItem).RefID)
                                {
                                    action_list[index].RemoveAt(ind);
                                }
                            }
                            if (action_list[index].Count > 0)
                            {
                                SendToPTL(action_list[index][0]);
                            }
                        }
                    }
                };
                OrdersPanel.Children.Add(ordc);
                i++;
            }
        }