public void UpdateLocationCases(LocationObject lo, AreaInfo ai, CaseInfo ci) { var collection = db.GetCollection <AreaInfo>("Areas"); var filter = Builders <AreaInfo> .Filter.And(Builders <AreaInfo> .Filter.Where(c => c.areaName == ai.areaName), Builders <AreaInfo> .Filter.Where(c => c.locationsList.Any(x => x.locName == lo.locName))); var update = Builders <AreaInfo> .Update.PullFilter("locationsList.$[].casesList", Builders <BsonDocument> .Filter.Eq("caseID", ci.caseID)); collection.UpdateOne(filter, update); collection.FindOneAndUpdate(c => c.areaName == ai.areaName && c.locationsList.Any(s => s.locName == lo.locName), Builders <AreaInfo> .Update.Push(c => c.locationsList[-1].casesList, ci)); }
private void UpdateAreaLocCases(CaseInfo ci, string areaID) { List <AreaInfo> areas = MongoCRUD.GetInstance().LoadRecords <AreaInfo>("Areas", "areaName", areaID); if (areas.Count != 0) { foreach (LocationObject lo in areas[0].locationsList) { if (lo.locName == ci.curLoc) { if (!lo.casesList.Contains(ci)) { MongoCRUD.GetInstance().UpdateLocationCases(lo, areas[0], ci); } } } } }
public void InsertRecord <T>(string table, T record, string id, string caseID) { var collection = db.GetCollection <T>(table); Type typeParameterType = typeof(T); if (typeParameterType.Name == "SerialInfo") { var serialCollection = db.GetCollection <SerialInfo>("Serial"); collection.InsertOne(record); serialCollection.FindOneAndUpdate(c => c.serial == id, Builders <SerialInfo> .Update.Set(c => c.caseID, caseID)); } else if (typeParameterType.Name == "CaseInfo") { if (!RecordExists <T>(table, id, "caseID")) { var caseCollection = db.GetCollection <CaseInfo>("Cases"); collection.InsertOne(record); } else { CaseInfo a = (CaseInfo)(object)record; var caseCollection = db.GetCollection <CaseInfo>("Cases"); caseCollection.FindOneAndUpdate(c => c.caseID == id, Builders <CaseInfo> .Update.Set(c => c.curLoc, a.curLoc)); caseCollection.FindOneAndUpdate(c => c.caseID == id, Builders <CaseInfo> .Update.Set(c => c.ageInfo, a.ageInfo)); } } else if (typeParameterType.Name == "AreaInfo") { if (!RecordExists <T>(table, id, "areaName")) { var caseCollection = db.GetCollection <AreaInfo>("Areas"); collection.InsertOne(record); } } }
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(); } } } }