Пример #1
0
        /// <summary>
        /// Receiving message from Gateway: the confirmation and shortage.
        /// </summary>
        /// <param name="gateway"></param>
        /// <param name="node"></param>
        /// <param name="direction"></param>
        /// <param name="message"></param>
        public void ReceiveMess(int gateway, int node, Direction direction, string message)
        {
            char s = 's';

            if (direction == Direction.Up)
            {
                s = '0';
            }
            else if (direction == Direction.Down)
            {
                s = '1';
            }
            if (s != 's')
            {
                DataRow[] r = PTLs.Select("Gateway = " + gateway + " AND ID = " + node + " AND up_down = " + s);
                if (r.Length > 0)
                {
                    DataRow[] r2 = replenishTable.Select("PTL = " + r[0][1] + " AND " + "(status = 2)");
                    if (r2.Length == 0)
                    {
                        r2 = replenishTable.Select("PTL = " + r[0][1] + " AND " + "(status = 0)");
                    }
                    if (r2.Length > 0)
                    {
                        foreach (ReplenishContentItem ordc in OrdersPanel.Children.OfType <ReplenishContentItem>())
                        {
                            if (ordc.RefID == Convert.ToInt32(r2[0][0]))
                            {
                                if (!ordc.Confirmed && !ordc.Expanded && ordc.Series_confirmed)
                                {
                                    ordc.QuantityReplenished = Convert.ToInt32(message.Trim());
                                    ConfirmORDC(ordc, r2, message, r);
                                    ordc.Series_confirmed = false;
                                }
                                else if (!ordc.Confirmed && ordc.Expanded)
                                {
                                    ordc.QuantityPodpitka = Convert.ToInt32(new string(message.Where(c => Char.IsDigit(c)).ToArray()));
                                    ConfirmPodp(ordc, r2, message, r);
                                    ordc.Series_confirmed = false;
                                }
                                else
                                {
                                    ordc.Series_confirmed = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
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;
            }
        }
Пример #3
0
        public ReplenishmentWindow(NewComing replenishTable, DataTable PTLS)
        {
            InitializeComponent();
            //expandedItem = null;
            cart_barcode        = replenishTable.TableName;
            this.replenishTable = replenishTable;
            PTLs = PTLS;

            this.Owner      = (MainWindow)Application.Current.MainWindow;
            this.ResizeMode = ResizeMode.NoResize;
            this.Closing   += (se, e) =>
            {
                if (!Confirmed && !(Owner as MainWindow).close)
                {
                    MessageBox.Show("Тауарлар толығымен орналастырылмады!");
                }
            };
            this.Loaded += (se, ev) =>
            {
                Owner.IsEnabled = false;
                if (!Start())
                {
                    Close();
                }
            };

            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, string> > [dt.Rows.Count];
            for (int ind = 0; ind < dt.Rows.Count; ind++)
            {
                action_list[ind] = new List <Tuple <int, int, string> >();
            }



            foreach (DataRow row in replenishTable.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]);
                            string short_series         = row[9].ToString().Substring(Math.Max(0, row[9].ToString().Length - 4));
                            Tuple <int, int, string> t2 = new Tuple <int, int, string>(Convert.ToInt32(row[0]), Convert.ToInt32(row[2]), short_series);
                            action_list[index].Add(t2);
                        }
                    }
                }
            }


            orderTab.Header = "Корзина " + cart_barcode;
            int i = 1;

            //OrdersPanel.Visibility = Visibility.Collapsed;
            string[] s = { "" };
            foreach (DataRow row in replenishTable.Rows)
            {
                ReplenishContentItem ordc = new ReplenishContentItem(i, Convert.ToInt32(row[0]), s, row[6].ToString(), row[5].ToString(), row[9].ToString(), Convert.ToInt32(row[2]), Convert.ToInt32(row[1]));

                if (Convert.ToInt32(row[3]) == 0)
                {
                    ordc.QuantityReplenished = Convert.ToInt32(row[2]);
                }
                else if (Convert.ToInt32(row[3]) == 1)
                {
                    ordc.Confirmed           = true;
                    ordc.QuantityReplenished = Convert.ToInt32(row[4]);
                }
                else if (Convert.ToInt32(row[3]) == 2)
                {
                    ordc.QuantityReplenished = Convert.ToInt32(row[4]);
                    ordc.Expanded            = true;
                }
                ordc.ShowButtonPressed += (se, ev) =>
                {
                    DataRow[] r2 = replenishTable.Select("Desc_id = " + (se as ReplenishContentItem).RefID);
                    if (r2.Length > 0)
                    {
                        DataRow[] r = PTLs.Select("Global = " + r2[0][1]);
                        if (r.Length > 0)
                        {
                            ConfirmORDC(se as ReplenishContentItem, r2, (se as ReplenishContentItem).QuantityReplenished.ToString(), r);
                            //((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)
                             * {
                             *  DataRow[] dr = replenishTable.Select("PTL = " + newrow[1]);
                             *  if (dr.Length > 0 && !Convert.ToBoolean(dr[0][3]))
                             *  {
                             *      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.Amber, LEDStatus.On);
                             *      ((MainWindow)Application.Current.MainWindow).ptlconn.DisplayQuantity(Convert.ToInt32(newrow[2]), Convert.ToInt32(newrow[3]), Convert.ToInt32(dr[0][2]), dir, 0, 0);
                             *  }
                             * }*/
                        }
                    }
                };
                ordc.ConfirmButtonPressed += (se, ev) =>
                {
                    DataRow[] r2 = replenishTable.Select("Desc_id = " + (se as ReplenishContentItem).RefID);
                    if (r2.Length > 0)
                    {
                        DataRow[] r = PTLs.Select("Global = " + r2[0][1]);
                        if (r.Length > 0)
                        {
                            ConfirmPodp((se as ReplenishContentItem), r2, (se as ReplenishContentItem).QuantityPodpitka.ToString(), r);
                        }
                    }
                };
                ordc.CancelButtonPressed += (se, ev) => // HERE
                {
                    ordc.cancellation = true;
                    DataRow[] r2 = replenishTable.Select("Desc_id = " + (se as ReplenishContentItem).RefID);
                    if (r2.Length > 0)
                    {
                        r2[0][3] = 1;
                        (this.Owner as MainWindow).sqlQueriesToSend.Add("UPDATE ptl_database.newcomingsdescription "
                                                                        + "SET status=1, statusPotpitka=0 WHERE idNewComingsDescription=" + r2[0][0] + ";");
                        ordc.Confirmed = true;

                        DataRow[] PTLrow = PTLs.Select("Global = " + r2[0][1]);
                        if (PTLrow.Length > 0)
                        {
                            DataRow[] rw = dt.Select("Gateway = " + PTLrow[0][2] + " AND ID = " + PTLrow[0][3]);
                            if (rw.Length > 0)
                            {
                                ((MainWindow)Application.Current.MainWindow).ptlconn.ClearNode(Convert.ToInt32(PTLrow[0][2]), Convert.ToInt32(PTLrow[0][3]));
                                int index = dt.Rows.IndexOf(rw[0]);
                                if (action_list[index].Count > 0)
                                {
                                    action_list[index].RemoveAt(0);
                                }
                                if (action_list[index].Count > 0)
                                {
                                    SendToPTL(action_list[index][0]);
                                }
                            }
                        }
                    }


                    bool all_confirmed = true;
                    foreach (ReplenishContentItem o in OrdersPanel.Children.OfType <ReplenishContentItem>())
                    {
                        if (!o.Confirmed)
                        {
                            all_confirmed = false;
                        }
                    }
                    if (all_confirmed)
                    {
                        this.Confirmed = true;
                    }
                };

                /*ordc.ExpandMe += (se, ev) =>
                 * {
                 *  if (expandedItem != null)
                 *  {
                 *      expandedItem.Expanded = false;
                 *  }
                 *  expandedItem = (se as ReplenishContentItem);
                 *  expandedItem.Expanded = true;
                 * };*/
                OrdersPanel.Children.Add(ordc);
                i++;
            }
        }