Ejemplo n.º 1
0
        public void UpdateLastLocations(string id, string serial)
        {
            if (RecordExists <SerialInfo>("Serial", serial, "serial"))
            {
                SerialInfo list       = LoadRecords <SerialInfo>("Serial", "serial", serial)[0];
                var        collection = db.GetCollection <SerialInfo>("Serial");


                //loop through each locationData object and if object doesn't match the id of most recent entry then set last location to false, otherwise true
                foreach (LocationData ld in list.locationData)
                {
                    // Save the entire document back to the database

                    if (ld.ID != id)
                    {
                        collection.FindOneAndUpdate(c => c.serial == serial && c.locationData.Any(s => s.ID == ld.ID),
                                                    Builders <SerialInfo> .Update.Set(c => c.locationData[-1].lastLocation, false));
                    }
                    else
                    {
                        collection.FindOneAndUpdate(c => c.serial == serial && c.locationData.Any(s => s.ID == ld.ID),
                                                    Builders <SerialInfo> .Update.Set(c => c.locationData[-1].lastLocation, true));

                        collection.FindOneAndUpdate(c => c.serial == serial,
                                                    Builders <SerialInfo> .Update.Set(c => c.caseID, ld.curCase));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void serialTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (serialTextBox.Text.ToUpper() == "CLEAR" || serialTextBox2.Text.ToUpper() == "CLEAR")
                {
                    serialListBox.Items.Clear();
                    serialListView.Clear();

                    numScannedLabel.Text = serialListBox.Items.Count.ToString();
                    numUnitsLabel.Text   = "0";

                    if (validateInputTabs.SelectedTab == validateInputTabs.TabPages["VerifyTab"])
                    {
                        serialTextBox.Clear();

                        serialTextBox.Enabled   = false;
                        caseTextBox.Enabled     = false;
                        areaLocationBox.Enabled = true;

                        caseTextBox.Clear();
                        areaLocationBox.Clear();

                        areaLocationBox.Focus();
                    }
                    else
                    {
                        serialTextBox2.Clear();

                        serialTextBox2.Enabled   = false;
                        caseTextBox2.Enabled     = false;
                        areaLocationBox2.Enabled = true;

                        caseTextBox2.Clear();
                        areaLocationBox2.Clear();

                        areaLocationBox2.Focus();
                    }
                }
                else if (serialTextBox.Text.ToUpper() == "CLEARLIST" || serialTextBox2.Text.ToUpper() == "CLEARLIST")
                {
                    serialListBox.Items.Clear();
                    serialListView.Clear();

                    numScannedLabel.Text = serialListBox.Items.Count.ToString();
                    numUnitsLabel.Text   = "0";

                    if (validateInputTabs.SelectedTab == validateInputTabs.TabPages["VerifyTab"])
                    {
                        List <SerialInfo> list = MongoCRUD.GetInstance().LoadRecords <SerialInfo>("Serial", "caseID", caseTextBox.Text);


                        if (list.Count != 0)
                        {
                            numUnitsLabel.Text = list.Count.ToString();

                            foreach (SerialInfo item in list)
                            {
                                serialListView.Items.Add(item.serial);
                            }
                        }

                        serialTextBox.Clear();
                        serialTextBox.Focus();
                    }
                    else
                    {
                        serialTextBox2.Clear();
                        serialTextBox2.Focus();
                    }
                }
                else if (serialTextBox.Text.ToUpper() == "CLEARCASE" || serialTextBox2.Text.ToUpper() == "CLEARCASE")
                {
                    serialListBox.Items.Clear();
                    serialListView.Clear();

                    numScannedLabel.Text = serialListBox.Items.Count.ToString();
                    numUnitsLabel.Text   = "0";

                    if (validateInputTabs.SelectedTab == validateInputTabs.TabPages["VerifyTab"])
                    {
                        serialTextBox.Clear();

                        serialTextBox.Enabled = false;
                        caseTextBox.Enabled   = true;
                        caseTextBox.Clear();
                        caseTextBox.Focus();
                    }
                    else
                    {
                        serialTextBox2.Clear();

                        serialTextBox2.Enabled = false;
                        caseTextBox2.Enabled   = true;
                        caseTextBox2.Clear();
                        caseTextBox2.Focus();
                    }
                }
                else if (serialTextBox.Text.ToUpper() == "VALIDATE")
                {
                    bool isBad = false;

                    List <SerialInfo> list       = MongoCRUD.GetInstance().LoadRecords <SerialInfo>("Serial", "caseID", caseTextBox.Text);
                    List <string>     serialList = new List <string>();

                    if (list.Count != 0)
                    {
                        foreach (SerialInfo serial in list)
                        {
                            serialList.Add(serial.serial);
                        }

                        foreach (string item in serialListBox.Items)
                        {
                            if (!serialList.Contains(item))
                            {
                                isBad = true;
                            }
                        }
                    }


                    if (isBad)
                    {
                        ShowDialog("Unable to commit case, try again", "Cannot Validate", false);

                        serialListBox.Items.Clear();
                        serialListView.Clear();

                        numScannedLabel.Text = serialListBox.Items.Count.ToString();
                        numUnitsLabel.Text   = "0";

                        if (validateInputTabs.SelectedTab == validateInputTabs.TabPages["VerifyTab"])
                        {
                            serialTextBox.Clear();

                            serialTextBox.Enabled = false;
                            caseTextBox.Enabled   = true;
                            caseTextBox.Clear();
                            caseTextBox.Focus();
                        }
                    }
                    else
                    {
                        foreach (string item in serialListBox.Items)
                        {
                            SerialInfo si = new SerialInfo();

                            si.serial = item;

                            LocationData d = new LocationData();
                            d.curCase      = caseTextBox.Text;
                            d.date         = DateTime.UtcNow.Date.ToString("MM/dd/yyyy");
                            d.time         = DateTime.Now.ToString("h:mm:ss tt");
                            d.location     = areaLocationBox.Text;
                            d.lastLocation = true;
                            d.userID       = "311015";

                            si.locationData.Add(d);

                            if (MongoCRUD.GetInstance().RecordExists <SerialInfo>("Serial", item, "serial"))
                            {
                                MongoCRUD.GetInstance().AppendRecord <SerialInfo>("Serial", item, d);
                            }
                        }

                        CaseInfo ci = new CaseInfo();
                        ci.caseID  = caseTextBox.Text;
                        ci.curLoc  = areaLocationBox.Text;
                        ci.ageInfo = DateTime.Now.ToString("MM-dd-yyyy hh: mm tt");


                        MongoCRUD.GetInstance().InsertRecord("Cases", ci, caseTextBox.Text, null);

                        UpdateAreaLocCases(ci, areaComboBox.SelectedItem.ToString());

                        ShowDialog("Case Passed", "Case Validated", false);

                        serialListBox.Items.Clear();
                        serialListView.Clear();
                        serialTextBox.Clear();

                        numScannedLabel.Text = serialListBox.Items.Count.ToString();
                        numUnitsLabel.Text   = "0";

                        serialTextBox.Enabled = false;
                        caseTextBox.Enabled   = true;
                        caseTextBox.Clear();
                        caseTextBox.Focus();
                    }
                }
                else if (serialTextBox2.Text.ToUpper() == "ADD")
                {
                    foreach (string item in serialListBox.Items)
                    {
                        SerialInfo si = new SerialInfo();

                        si.serial = item;

                        LocationData d = new LocationData();
                        d.curCase      = caseTextBox2.Text;
                        d.date         = DateTime.UtcNow.Date.ToString("MM/dd/yyyy");
                        d.time         = DateTime.Now.ToString("h:mm:ss tt");
                        d.location     = areaLocationBox2.Text;
                        d.lastLocation = true;
                        d.userID       = "311015";


                        si.locationData.Add(d);



                        if (MongoCRUD.GetInstance().RecordExists <SerialInfo>("Serial", item, "serial"))
                        {
                            MongoCRUD.GetInstance().AppendRecord <SerialInfo>("Serial", item, d);
                        }
                        else
                        {
                            MongoCRUD.GetInstance().InsertRecord("Serial", si, item, caseTextBox2.Text);
                        }
                    }

                    CaseInfo ci = new CaseInfo();
                    ci.caseID  = caseTextBox2.Text;
                    ci.curLoc  = areaLocationBox2.Text;
                    ci.ageInfo = DateTime.Now.ToString("MM-dd-yyyy hh: mm tt");


                    MongoCRUD.GetInstance().InsertRecord("Cases", ci, caseTextBox2.Text, null);

                    UpdateAreaLocCases(ci, areaComboBox.SelectedItem.ToString());

                    serialListBox.Items.Clear();
                    serialListView.Clear();
                    serialTextBox2.Clear();

                    numScannedLabel.Text = serialListBox.Items.Count.ToString();
                    numUnitsLabel.Text   = "0";

                    serialTextBox2.Enabled = false;
                    caseTextBox2.Enabled   = true;
                    caseTextBox2.Clear();
                    caseTextBox2.Focus();
                }
                else
                {
                    List <string> serialsList = new List <string>();

                    if (validateInputTabs.SelectedTab == validateInputTabs.TabPages["VerifyTab"])
                    {
                        serialListBox.Items.Add(serialTextBox.Text);

                        numScannedLabel.Text = serialListBox.Items.Count.ToString();

                        for (int i = 0; i < serialListView.Items.Count; i++)
                        {
                            serialsList.Add(serialListView.Items[i].Text);

                            if (serialTextBox.Text == serialListView.Items[i].Text)
                            {
                                serialListView.Items[i].BackColor = Color.Green;
                            }
                        }

                        if (!serialsList.Contains(serialTextBox.Text))
                        {
                            serialListView.Items.Add(serialTextBox.Text).BackColor = Color.Red;
                        }

                        serialTextBox.Clear();
                        serialTextBox.Focus();
                    }
                    else
                    {
                        serialListBox.Items.Add(serialTextBox2.Text);

                        numScannedLabel.Text = serialListBox.Items.Count.ToString();

                        for (int i = 0; i < serialListView.Items.Count; i++)
                        {
                            if (serialTextBox2.Text == serialListView.Items[i].Text)
                            {
                                serialListView.Items[i].BackColor = Color.Green;
                            }
                        }


                        serialTextBox2.Clear();
                        serialTextBox2.Focus();
                    }
                }
            }
        }