Exemplo n.º 1
0
        private void Line_UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new MTSDB())
            {
                var tl = (from t in db.ToLine
                          where t.SMN == Line_TrackingCodeTextBox.Text
                          select t).SingleOrDefault();

                if (tl == null)
                {
                    MessageBox.Show("Part Not Found!! Please Verify", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Line_TrackingCodeTextBox.Clear();
                    return;
                }

                CurrentPart = tl.Part;

                int qty = 0;
                if (int.TryParse(Line_ReturnQtyTextBox.Text, out qty) == false || (qty == 0))
                {
                    MessageBox.Show("Please Verify Quantity", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                FromLine fl = new FromLine();
                fl.ToLineRecord   = tl;
                fl.Quantity       = qty;
                fl.Part           = tl.Part;
                fl.Timestamp      = DateTime.Now;
                tl.Balance       -= qty;
                tl.Part.Quantity += qty;
                tl.Part.FromLineRecords.Add(fl);
                db.SaveChanges();

                MessageBox.Show("Inventory Updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new Action(() =>
                {
                    Line_ReturnQtyTextBox.Clear();
                    Line_TrackingCodeTextBox.Clear();
                    DisplayParts.Clear();
                    Stores_PartGrid.DataContext = null;
                    Stores_PartGrid.DataContext = DisplayParts;
                }));
            }
        }
Exemplo n.º 2
0
        private void PickList_UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            CurrentPart = PickList_PartComboBox.SelectedItem as Part;
            if (CurrentPart == null)
            {
                return;
            }
            using (var db = new MTSDB())
            {
                var parts = from p in db.Parts
                            where p.PartNo == CurrentPart.PartNo
                            select p;
                var fs = from s in db.FromStores
                         select s;
                Part P = parts.SingleOrDefault();
                if (P == null)
                {
                    MessageBox.Show("Part Not Found !! Please Verify", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (PickList_SUNTextBox.Text == String.Empty && P.Kanban == false)
                {
                    MessageBox.Show("Please Scan/Enter SUN", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                if (PickList_SUNTextBox.Text.Length != 10 && (PickList_SUNTextBox.Text.Length != 14))
                {
                    MessageBox.Show("SUN Not Equal to expected number of characters. Please Veifry ", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                int qty = 0;
                if (int.TryParse(PickList_QtyTextBox.Text, out qty) == false || (qty == 0))
                {
                    MessageBox.Show("Please Verify Quantity", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                FromStores f = new FromStores();
                f.SUN       = PickList_SUNTextBox.Text;
                f.Part      = P;
                f.Quantity  = qty;
                f.Balance   = qty;
                f.Timestamp = DateTime.Now;

                db.FromStores.Add(f);


                P.Quantity    += f.Quantity.Value;
                P.LastUpdated  = DateTime.Now;
                P.LastActivity = "Stores Inward Entry";
                P.FromStoresRecords.Add(f);

                db.SaveChanges();

                DisplayParts.Clear();
                DisplayParts.Add(P);
                Stores_PartGrid.DataContext = null;
                Stores_PartGrid.DataContext = DisplayParts;

                MessageBox.Show("Part Added To Inventory", "Alert", MessageBoxButton.OK, MessageBoxImage.Information);
                this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new Action(() =>
                {
                    //PickList_PartComboBox.SelectedIndex = -1;
                    PickList_QtyTextBox.Clear();
                    PickList_SUNTextBox.Clear();
                    DisplayParts.Clear();
                    PickList_SUNTextBox.Focus();
                }));
            }
        }
Exemplo n.º 3
0
        private void FG_UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                        new Action(() =>
            {
                FG_ShortageGrid.Visibility = Visibility.Collapsed;
            }));
            List <ShortagePart> shortageParts = new List <ShortagePart>();

            if (FG_PartComboBox.SelectedItem == null)
            {
                return;
            }
            FGPart fgpart = (FGPart)FG_PartComboBox.SelectedItem;

            if (fgpart == null)
            {
                return;
            }

            String FGRef = FG_RefTextBox.Text;

            if (FGRef == String.Empty || FGRef == null)
            {
                MessageBox.Show("FG Reference Required !!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (FG_AcceptedTextBox.Text != fgpart.PartNo)
            {
                MessageBox.Show("FG Part No Mismatch. Please Verify ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            using (var db = new MTSDB())
            {
                var FGEntry = (from p in db.FGs
                               where p.FGRef == FGRef
                               select p).SingleOrDefault();
                if (FGEntry != null)
                {
                    MessageBox.Show("FG Already Completed. Please Verify Reference No", "Update Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                var fgparts = from p in db.FGParts
                              where p.PartNo == fgpart.PartNo
                              select p;

                FGPart FGP = fgparts.SingleOrDefault();


                if (FGP == null)
                {
                    MessageBox.Show("FG Part Not Found !! Please Verify", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                int qty = 0;
                if (int.TryParse(FG_QuantityTextBox.Text, out qty) == false || (qty == 0))
                {
                    MessageBox.Show("Please Verify Quantity", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                var bom = (from p in db.BOMs
                           where p.FGPartID == fgpart.FGPartID
                           select p).ToList();

                DateTime?tlTs  = DateTime.Now;
                int      shift = 0;
                if (tlTs.Value.TimeOfDay >= new TimeSpan(14, 00, 0) && tlTs.Value.TimeOfDay < new TimeSpan(22, 00, 0))
                {
                    shift = 2;
                }
                else if (tlTs.Value.TimeOfDay >= new TimeSpan(22, 00, 0) && tlTs.Value.TimeOfDay < new TimeSpan(6, 00, 0))
                {
                    shift = 3;
                }
                else
                {
                    shift = 1;
                }

                foreach (BOM b in bom)
                {
                    FG fgEntry = new FG();
                    fgEntry.FGPart         = FGP;
                    fgEntry.EntryTimestamp = tlTs;
                    fgEntry.JulianDate     = tlTs.Value.DayOfYear;
                    var part = (from prt in db.Parts
                                where prt.PartID == b.PartID
                                select prt).SingleOrDefault();
                    fgEntry.Part     = part;
                    fgEntry.Shift    = shift;
                    fgEntry.Quantity = (int)(b.PartQuantity.Value * qty);
                    fgEntry.FGRef    = FGRef;

                    var toline = (from tl in part.ToLineRecords
                                  where (tl.Timestamp <= tlTs) && tl.Balance > 0
                                  select tl).OrderBy(l => l.Timestamp).ToList();

                    int?FGQty             = fgEntry.Quantity;
                    int totalPartQuantity = 0;

                    foreach (ToLine l in toline)
                    {
                        totalPartQuantity += l.Balance.Value;
                    }

                    if (totalPartQuantity < FGQty)
                    {
                        shortageParts.Add(new ShortagePart
                        {
                            PartNo           = fgEntry.Part.PartNo,
                            Description      = fgEntry.Part.Description,
                            LineQuantity     = totalPartQuantity,
                            RequiredQuantity = (FGQty - totalPartQuantity).Value
                        });
                    }

                    foreach (ToLine l in toline)
                    {
                        if (FGQty > 0)
                        {
                            if (l.Balance >= FGQty)
                            {
                                l.Balance -= FGQty;

                                l.FGs.Add(fgEntry);

                                break;
                            }
                            else
                            {
                                FGQty    -= l.Balance;
                                l.Balance = 0;
                                l.FGs.Add(fgEntry);
                            }
                        }
                    }
                    part.FGRecords.Add(fgEntry);
                }
                if (shortageParts.Count > 0)
                {
                    FG_ShortageGrid.DataContext = shortageParts;
                    MessageBox.Show("Parts Shortage for FG Update" + Environment.NewLine +
                                    "Unable to Update FG ,  Please Verify",
                                    "Update Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                new Action(() =>
                    {
                        FG_ShortageGrid.Visibility = Visibility.Visible;
                    }));

                    return;
                }


                FG Fg = new FG();
                Fg.FGPart         = FGP;
                Fg.EntryTimestamp = tlTs;
                Fg.JulianDate     = tlTs.Value.DayOfYear;
                Fg.Shift          = shift;
                Fg.Quantity       = qty;
                Fg.FGRef          = FG_RefTextBox.Text;
                db.FGs.Add(Fg);
                db.SaveChanges();

                MessageBox.Show("FG Updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemplo n.º 4
0
        private void GenerateTrackingCodeButton_Click(object sender, RoutedEventArgs e)
        {
            CurrentPart = (Part)Line_PartComboBox.SelectedItem;
            using (var db = new MTSDB())
            {
                var parts = from p in db.Parts
                            where p.PartNo == CurrentPart.PartNo
                            select p;

                Part P = parts.SingleOrDefault();


                if (P == null)
                {
                    MessageBox.Show("Part Not Found !! Please Verify", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                int qty = 0;
                if (int.TryParse(Line_ReleaseQtyTextBox.Text, out qty) == false || (qty == 0))
                {
                    MessageBox.Show("Please Verify Quantity", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                CurrentPart = P;

                if (P.Quantity < qty)
                {
                    MessageBox.Show("Quantity Unavailable", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                ToLine tl = new ToLine();

                foreach (FromStores fs in P.FromStoresRecords)
                {
                    if (qty > 0)
                    {
                        if (fs.Balance <= 0)
                        {
                            continue;
                        }
                        if (fs.Balance >= qty)
                        {
                            var FromStoresToLines = new FromStoresToLines();
                            FromStoresToLines.FromStores        = fs;
                            FromStoresToLines.ToLine            = tl;
                            FromStoresToLines.FromStoresBalance = fs.Balance.Value;

                            fs.Balance -= qty;
                            P.Quantity -= qty;

                            tl.Quantity += qty;
                            tl.Timestamp = DateTime.Now;
                            tl.Part      = P;
                            if ((tl.SMN == String.Empty) || tl.SMN == null)
                            {
                                DateTime ts     = DateTime.Now;
                                int      offset = 0;
                                if (ts.Hour >= 22 && ts.Hour < 6)
                                {
                                    offset = 1;
                                }
                                P.ToLineReference++;
                                tl.SMN = P.PartID.ToString("D4") + P.ToLineReference.Value.ToString("D4")
                                         + (ts.DayOfYear - offset).ToString("D3") + (ts.Year - 2000).ToString("D2");
                            }
                            tl.SUN = fs.SUN;

                            FromStoresToLines.ToLineBalance = qty;
                            FromStoresToLines.Part          = P;
                            db.FromStoresToLines.Add(FromStoresToLines);
                            break;
                        }
                        else
                        {
                            var FromStoresToLines = new FromStoresToLines();
                            FromStoresToLines.FromStores        = fs;
                            FromStoresToLines.ToLine            = tl;
                            FromStoresToLines.FromStoresBalance = fs.Balance.Value;

                            tl.Quantity += fs.Balance;
                            tl.Timestamp = DateTime.Now;
                            tl.Part      = P;


                            if ((tl.SMN == String.Empty) || tl.SMN == null)
                            {
                                DateTime ts     = DateTime.Now;
                                int      offset = 0;
                                if (ts.Hour >= 22 && ts.Hour < 6)
                                {
                                    offset = 1;
                                }

                                P.ToLineReference++;
                                tl.SMN = P.PartID.ToString("D4") + P.ToLineReference.Value.ToString("D4")
                                         + (ts.DayOfYear - offset).ToString("D3") + (ts.Year - 2000).ToString("D2");
                            }

                            tl.SUN = fs.SUN;

                            qty -= fs.Balance.Value;
                            FromStoresToLines.ToLineBalance = fs.Balance.Value;
                            P.Quantity            -= fs.Balance.Value;
                            fs.Balance             = 0;
                            FromStoresToLines.Part = P;
                            db.FromStoresToLines.Add(FromStoresToLines);
                        }
                    }
                }
                tl.Balance   = tl.Quantity;
                tl.Timestamp = DateTime.Now;

                P.ToLineRecords.Add(tl);
                P.LastUpdated  = DateTime.Now;
                P.LastActivity = "To Line Entry";
                db.SaveChanges();

                //Code for generation of Tracking Code


                // PrinterManager.PrintSMN(PrinterName, tl.SMN, templatePath);
                MessageBox.Show("SMN Generated - " + tl.SMN, "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new Action(() =>
                {
                    Line_PartComboBox.Text         = "";
                    Line_PartComboBox.SelectedItem = null;
                    Line_ReleaseQtyTextBox.Clear();

                    DisplayParts.Clear();
                }));
            }
        }
Exemplo n.º 5
0
        private void Scrap_UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (Scrap_PartNoCombobox.SelectedItem == null)
            {
                return;
            }
            CurrentPart = (Part)Scrap_PartNoCombobox.SelectedItem;



            int qty = 0;

            if (int.TryParse(Scrap_QtyTextBox.Text, out qty) == false || (qty == 0))
            {
                MessageBox.Show("Please Verify Quantity", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            using (var db = new MTSDB())
            {
                var part = db.Parts.Where(p => p.PartID == CurrentPart.PartID).SingleOrDefault();


                if (part == null)
                {
                    MessageBox.Show("Part Not Found!! Please Verify", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Line_TrackingCodeTextBox.Clear();
                    return;
                }

                var tl = db.ToLine.Include("Part").Where(t => t.Part.PartID == part.PartID && t.Balance > 0).OrderBy(t => t.Timestamp).ToList();

                int lineQty = 0;
                foreach (ToLine t in tl)
                {
                    lineQty += t.Balance.Value;
                }
                if (lineQty < qty)
                {
                    MessageBox.Show("Line Quantity less than Scrap Quantity. Please Verify", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Line_TrackingCodeTextBox.Clear();
                    return;
                }


                LineRejection fl = new LineRejection();
                fl.Part      = part;
                fl.Reason    = Scrap_ReasonTextBox.Text;
                fl.Timestamp = DateTime.Now;

                foreach (ToLine t in tl)
                {
                    if (qty > 0)
                    {
                        if (t.Balance > qty)
                        {
                            t.Balance   -= qty;
                            fl.Quantity += qty;
                            fl.ToLines.Add(t);
                            break;
                        }
                        else
                        {
                            qty         -= t.Balance.Value;
                            fl.Quantity += t.Balance.Value;
                            t.Balance    = 0;
                            fl.ToLines.Add(t);
                        }
                    }
                }



                db.LineRejections.Add(fl);
                db.SaveChanges();

                MessageBox.Show("Scrap Updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                            new Action(() =>
                {
                    Scrap_PartNoCombobox.Text         = "";
                    Scrap_PartNoCombobox.SelectedItem = null;
                    Scrap_QtyTextBox.Clear();
                    Scrap_ReasonTextBox.Clear();
                }));
            }
        }