static public Bottles GetBottleWithName(string name) { DBRequest req = new DBRequest(); Bottles bot = req.GetBottleWithName(name); return(bot); }
public void LoadBottlesFromAlerts(string alertName) { int alertID = req.GetAlertIDFromName(alertName); /** * defining the datagridview for "removing an alert" */ dvgBottlesSelected.ColumnCount = 3; //option for display dvgBottlesSelected.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy; dvgBottlesSelected.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; dvgBottlesSelected.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dvgBottlesSelected.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; dvgBottlesSelected.CellBorderStyle = DataGridViewCellBorderStyle.Single; dvgBottlesSelected.GridColor = Color.Black; //columns name dvgBottlesSelected.Columns[0].Name = "Nom du vin"; dvgBottlesSelected.Columns[1].Name = "Année"; dvgBottlesSelected.Columns[2].Name = "Volume"; dvgBottlesSelected.Columns[0].Width = 130; dvgBottlesSelected.Rows.Clear(); List <Bottles> lstWinesFromAlert = new List <Bottles>(); lstWinesFromAlert = Bottles.GetBottlesWithAlert(alertID); foreach (Bottles bot in lstWinesFromAlert) { string[] row = { bot.Name, bot.Year.ToString(), bot.Volume.ToString() }; dvgBottlesSelected.Rows.Add(row); } }
/** * method to order the list by manufacturer */ private void radManufacturer_Click(object sender, EventArgs e) { List <Bottles> lstBottle = new List <Bottles>(); lstBottle = Bottles.OrderByManufacturer(); // method to reload the data, specifying the data to use LoadData(lstBottle); }
private Document GeneratePDF(string use) { List <Bottles> listBottle = new List <Bottles>(); //check which order by is selected, select the correct list depending on that if (radColor.Checked) { listBottle = Bottles.OrderByColor(); } else if (radCountry.Checked) { listBottle = Bottles.OrderByCountry(); } else if (radManufacturer.Checked) { listBottle = Bottles.OrderByManufacturer(); } else if (radVariety.Checked) { listBottle = Bottles.OrderByVarietal(); } else if (txtResearch.Text != "") { listBottle = Bottles.ResearchByKeyword(txtResearch.Text); } //if no ordering, select all bottles as they are in DB else { listBottle = Bottles.ShowAllBottles(); } string jour = DateTime.Today.Day.ToString() + "." + DateTime.Today.Month.ToString() + "." + DateTime.Today.Year.ToString(); // Must have write permissions to the path folder PdfWriter writer; if (use == "def") { writer = new PdfWriter("C:\\ListeBouteilles_" + jour + ".pdf"); } else { writer = new PdfWriter("C:\\temp\\list" + jour + ".pdf"); } //it is necessary to specify, because the class PdfDocument exist in both iText and Spire iText.Kernel.Pdf.PdfDocument pdf = new iText.Kernel.Pdf.PdfDocument(writer); Document document = new Document(pdf); Paragraph header = new Paragraph("Liste de bouteilles stockées") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(14); document.Add(header); Table table = CreateTable(listBottle); document.Add(table); document.Close(); return(document); }
public void UpdateBottle_Allparams_OK() { bool resExpected = true; bool resCalculated; resCalculated = Bottles.UpdateBottle(bottleToUpdate.Name, bottleToUpdate.BottleNumber, bottleToUpdate.Volume, bottleToUpdate.Year); Assert.AreEqual(resExpected, resCalculated); }
public void ShowAllBottles_NoSorting_OK() { List <Bottles> resExpected = lstBottles; List <Bottles> resCalculated = new List <Bottles>(); resCalculated = Bottles.ShowAllBottles(); Assert.AreEqual(resExpected, resCalculated); }
public void AddAlertToBottle_Allparams_OK() { bool resExpected = true; bool resCalculated; resCalculated = Bottles.AddAlertToBottle(bottleByName.Name, alert.Name); Assert.AreEqual(resExpected, resCalculated); }
public void OrderByCountry_alphabetical_OK() { List <Bottles> resExpected = lstCountry; List <Bottles> resCalculated; resCalculated = Bottles.OrderByManufacturer(); Assert.AreEqual(resExpected, resCalculated); }
public void GetBottlesWithAlert_NoSorting_OK() { List <Bottles> resExpected = lstBottlesWithAlerts; List <Bottles> resCalculated = new List <Bottles>(); resCalculated = Bottles.GetBottlesWithAlert(2); Assert.AreEqual(resExpected, resCalculated); }
public void OrderByVarietal_alphabetical_OK() { List <Bottles> resExpected = lstVarietal; List <Bottles> resCalculated; resCalculated = Bottles.OrderByVarietal(); Assert.AreEqual(resExpected, resCalculated); }
public void OrderByColor_alphabetical_OK() { List <Bottles> resExpected = lstColor; List <Bottles> resCalculated; resCalculated = Bottles.OrderByColor(); Assert.AreEqual(resExpected, resCalculated); }
public void ResearchByKeyWord_existingword_OK() { List <Bottles> resExpected = lstKeyword; List <Bottles> resCalculated; resCalculated = Bottles.ResearchByKeyword("test"); Assert.AreEqual(resExpected, resCalculated); }
public void RemoveBottle_Allparams_OK() { bool resExpected = true; bool resCalculated; resCalculated = Bottles.RemoveBottle(bottleToAdd.Name, bottleToAdd.BottleNumber, bottleToAdd.Volume, bottleToAdd.Manufacturer, bottleToAdd.Year); Assert.AreEqual(resExpected, resCalculated); }
private void Researchfrm_Load(object sender, EventArgs e) { List <string> lstTab = new List <string>(); // get a list of all bottles in DB lstBottle = Bottles.ShowAllBottles(); LoadData(lstBottle); }
public void GetBottlesWithName_NoSorting_OK() { Bottles resExpected = bottleByName; Bottles resCalculated = new Bottles(); resCalculated = Bottles.GetBottleWithName("bouteille1"); Assert.AreEqual(resExpected, resCalculated); }
public void Initialize() { lstBottles = new List <Bottles>() { new Bottles("bouteille1", "rouge", 4, 1.0, "producteur1", 2020, "cepage3", "casier 2", "description test"), new Bottles("bouteille2", "blanc", 6, 1.5, "producteur3", 1960, "cepage2", "casier 3", "description bouteille 2"), new Bottles("bouteille3", "rose", 1, 1.0, "producteur1", 1999, "cepage1", "casier 1", "description bouteille 3") }; lstColor = new List <Bottles>() { new Bottles("bouteille2", "blanc", 6, 1.5, "producteur3", 1960, "cepage2", "casier 3", "description bouteille 2"), new Bottles("bouteille3", "rose", 1, 1.0, "producteur1", 1999, "cepage1", "casier 1", "description bouteille 3"), new Bottles("bouteille1", "rouge", 4, 1.0, "producteur1", 2020, "cepage3", "casier 2", "description test"), }; lstManufacturer = new List <Bottles>() { new Bottles("bouteille1", "rouge", 4, 1, "producteur1", 2020, "cepage3", "casier 2", "description test"), new Bottles("bouteille3", "rose", 1, 1, "producteur1", 1999, "cepage1", "casier 1", "description bouteille 3"), new Bottles("bouteille2", "blanc", 6, 1.5, "producteur3", 1960, "cepage2", "casier 3", "description bouteille 2"), }; lstCountry = new List <Bottles>() { new Bottles("bouteille1", "rouge", 4, 1, "producteur1", 2020, "cepage3", "casier 2", "description test"), new Bottles("bouteille3", "rose", 1, 1, "producteur1", 1999, "cepage1", "casier 1", "description bouteille 3"), new Bottles("bouteille2", "blanc", 6, 1.5, "producteur3", 1960, "cepage2", "casier 3", "description bouteille 2"), }; lstKeyword = new List <Bottles>() { new Bottles("bouteille1", "rouge", 4, 1, "producteur1", 2020, "cepage3", "casier 2", "description test") }; lstVarietal = new List <Bottles>() { new Bottles("bouteille3", "rose", 1, 1, "producteur1", 1999, "cepage1", "casier 1", "description bouteille 3"), new Bottles("bouteille2", "blanc", 6, 1.5, "producteur3", 1960, "cepage2", "casier 3", "description bouteille 2"), new Bottles("bouteille1", "rouge", 4, 1, "producteur1", 2020, "cepage3", "casier 2", "description test"), }; lstBottlesWithAlerts = new List <Bottles>() { new Bottles("bouteille2", null, 0, 1.5, null, 1960, null, null, null) }; bottleByName = new Bottles("bouteille1", "rouge", 4, 1.0, "producteur1", 2020, "cepage3", "casier 2", "description test"); bottle3Params = new Bottles("bouteille3", 0.75, 1995); bottleToAdd = new Bottles("bouteille4", "rouge", 5, 0.5, "producteur1", 2015, "cepage1, cepage2", "casier 1", "description Bouteille4"); bottleToUpdate = new Bottles("bouteille1", "rouge", 4, 1.0, "producteur1", 2020, "cepage3", "casier 2", "description test"); alert = new Alerts("alerte1", "message1", "bouteille1"); }
private void btnResearch_Click(object sender, EventArgs e) { string keyword; if (txtResearch.Text != "") { keyword = txtResearch.Text; lstBottle = Bottles.ResearchByKeyword(keyword); // method to reload the data, specifying the data to use LoadData(lstBottle); } else { MessageBox.Show("Sans texte de recherche, cela ne fonctionnera pas"); } }
public void AddBottleWithDescAndVarietal_Allparams_OK() { bool resExpected = true; bool resCalculated; List <string> lstVarietal = new List <string>(); string[] subs = bottleToAdd.Varietal.Split(','); foreach (string sub in subs) { lstVarietal.Add(sub); } resCalculated = Bottles.AddBottleWithDescAndVarietal(bottleToAdd.Name, bottleToAdd.Color, bottleToAdd.BottleNumber, bottleToAdd.Volume, bottleToAdd.Manufacturer, bottleToAdd.Year, bottleToAdd.Storage, lstVarietal, bottleToAdd.Description); Assert.AreEqual(resExpected, resCalculated); }
private void btnAddBottle_Click(object sender, EventArgs e) { string wineName; LoadSelectedBottles(); if (comboWineChoice.SelectedIndex != -1) { wineName = comboWineChoice.SelectedItem.ToString(); Bottles bot = Bottles.GetBottleWithName(wineName); lstSelectedWines.Add(bot); } else { MessageBox.Show("Aucune bouteille n'est actuellement sélectionnée"); } LoadSelectedBottles(); }
/** * method to load all data pertaining to the bottles, to show them on screen */ private void LoadData() { dvgBottles.ColumnCount = 8; //option for display dvgBottles.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy; dvgBottles.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; dvgBottles.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dvgBottles.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; dvgBottles.CellBorderStyle = DataGridViewCellBorderStyle.Single; dvgBottles.GridColor = Color.Black; //column width - default : 100px dvgBottles.Columns[0].Width = 55; dvgBottles.Columns[3].Width = 45; dvgBottles.Columns[4].Width = 50; dvgBottles.Columns[5].Width = 55; //columns name dvgBottles.Columns[1].Name = "Nom du vin"; dvgBottles.Columns[2].Name = "Producteur"; dvgBottles.Columns[3].Name = "Année"; dvgBottles.Columns[4].Name = "Volume"; dvgBottles.Columns[5].Name = "Couleurs"; dvgBottles.Columns[6].Name = "Cépage(s)"; dvgBottles.Columns[7].Name = "Description"; dvgBottles.Columns[0].Name = "Quantité"; //delete all datas already contained in the datagridview dvgBottles.Rows.Clear(); List <Bottles> lstBottle = Bottles.ShowAllBottles(); foreach (Bottles bot in lstBottle) { string[] row = { bot.BottleNumber.ToString(), bot.Name, bot.Manufacturer, bot.Year.ToString(), bot.Volume.ToString(), bot.Color, bot.Varietal.ToString(), bot.Description }; dvgBottles.Rows.Add(row); } }
/** * method to order the list by wineColor */ private void radColor_Click(object sender, EventArgs e) { lstBottle = Bottles.OrderByColor(); // method to reload the data, specifying the data to use LoadData(lstBottle); }
private void btnAddAlert_Click(object sender, EventArgs e) { //initializing variables to stock informations from the alert string alert = ""; string message = ""; List <Bottles> lstBottles = new List <Bottles>(); // initializing the boolean to check if everything is correct -> all is false by default, so that if it works, it changes to true bool successAlert = false; bool successMessage = false; bool successBottles = false; bool successFormat = false; bool successPresence = false; bool successAdd = false; /** * verification of data type * if a field is empty and shouldn't be -> the bottle won't be added */ if (txtAlert.Text != "") { alert = txtAlert.Text; successAlert = true; } if (rtxtMessage.Text != "") { message = rtxtMessage.Text; successMessage = true; } if (lstSelectedWines.Count != 0) { successBottles = true; } //verify if the bottle to add already exists in database -> true : present, false : non present // occur uniquely if the volume, the name and the year have been validated if (successAlert && successMessage) { successPresence = req.CheckAlertPresence(alert); } // if all verification are ok -> will be true, otherwise, will be false successFormat = successMessage && successAlert && successBottles && !successPresence; // all checks passed if (successFormat) { // adding the alert to the DB successAdd = Alerts.AddAlert(alert, message); foreach (Bottles bot in lstSelectedWines) { Bottles.AddAlertToBottle(bot.Name, alert); } // message box to show, depending on the result when adding the alert if (successAdd) { MessageBox.Show("L'ajout de l'alerte a été effectué correctement."); } else { MessageBox.Show("Une erreur est survenue lors de l'ajout de l'alerte. Veuillez réessayer."); } } // problems with at least 1 check else { MessageBox.Show("Une des valeurs spécifiées est incorrecte."); txtAlert.Text = ""; rtxtMessage.Text = ""; comboWineChoice.Items.Clear(); } LoadData(); }
/** * when clicking on "adding the bottle", check if every parameter needed is present and if the datatype is correct */ private void btnAdd_Click(object sender, EventArgs e) { //initializing variables to stock informations from the wine bottle string wineName = ""; string color = ""; string manufacturer = ""; string description = ""; string storage = ""; int number = 0; double volume = 0; int year = 0; List <string> varietal = new List <string>(); // initializing variables to compare the logic behind some values int actualYear = DateTime.Now.Year; // initializing the boolean to check if everything is correct -> all is false by default, so that if it works, it changes to true bool successName = false; bool successColor = false; bool successManu = false; bool successStorage = false; bool successDescription = false; bool successNumber = false; bool successYear = false; bool successVolume = false; bool successVarietal = false; bool successFormat = false; bool successPresence = false; bool successAdd = false; bool successLog = false; /** * verification of data type * if a field is empty and shouldn't be -> the bottle won't be added */ if (txtBottleName.Text != "") { wineName = txtBottleName.Text; successName = true; } if (comboColor.SelectedIndex != -1) { color = comboColor.SelectedItem.ToString(); successColor = true; } if (comboVolume.SelectedIndex != -1) { successVolume = Double.TryParse(comboVolume.SelectedItem.ToString(), out volume); } if (comboManufacturer.SelectedIndex != -1) { manufacturer = comboManufacturer.SelectedItem.ToString(); successManu = true; } if (txtNumber.Text != "") { successNumber = Int32.TryParse(txtNumber.Text, out number); if (number < 1) { MessageBox.Show("Le nombre de bouteilles spécifié n'est pas valide."); txtNumber.Text = ""; } } if (comboStorage.SelectedIndex != -1) { storage = comboStorage.SelectedItem.ToString(); successStorage = true; } if (rtxtDescription.Text != "" && rtxtDescription.TextLength < 200) { description = rtxtDescription.Text; successDescription = true; } if (txtYear.Text != "") { successYear = Int32.TryParse(txtYear.Text, out year); if (year < 1900 || year > actualYear) { MessageBox.Show("L'année de production n'est pas valide."); txtYear.Text = ""; } } if (comboVariety1.SelectedIndex != -1 || comboVariety2.SelectedIndex != -1 || comboVariety3.SelectedIndex != -1) { successVarietal = true; if (comboVariety1.SelectedIndex != -1) { varietal.Add(comboVariety1.SelectedItem.ToString()); } if (comboVariety2.SelectedIndex != -1) { varietal.Add(comboVariety2.SelectedItem.ToString()); } if (comboVariety3.SelectedIndex != -1) { varietal.Add(comboVariety3.SelectedItem.ToString()); } } successYear = Int32.TryParse(txtYear.Text, out year); //verify if the bottle to add already exists in database -> true : present, false : non present // occur uniquely if the volume, the name and the year have been validated if (successVolume && successName && successYear) { successPresence = req.CheckBottlePresence(wineName, year, volume); } // if all verification are ok -> will be true, otherwise, will be false successFormat = successNumber && successYear && successName && successColor && successManu && successStorage; // all checks passed, bottle not present if (successFormat == true && !successPresence) { // different requests, depending on parameters given if (successDescription && successVarietal) { successAdd = Bottles.AddBottleWithDescAndVarietal(wineName, color, number, volume, manufacturer, year, storage, varietal, description); } else if (successVarietal) { successAdd = Bottles.AddBottleWithVarietal(wineName, color, number, volume, manufacturer, year, storage, varietal); } else if (successDescription) { successAdd = Bottles.AddBottleWithDesc(wineName, color, number, volume, manufacturer, year, storage, description); } else { successAdd = Bottles.AddBottle(wineName, color, number, volume, manufacturer, year, storage); } // message box to show, depending on the result when adding the bottle if (successAdd) { int wineID = req.GetIDBottleByName(wineName); successLog = Logs.AddLog("ajoutNouvelle", wineID); MessageBox.Show("L'ajout de la bouteille a été effectué correctement."); } else { MessageBox.Show("Une erreur est survenue lors de l'ajout de la bouteille. Veuillez réessayer."); } } // all checks passed, bottle already present else if (successFormat == true && successPresence) { successAdd = Bottles.UpdateBottle(wineName, number, volume, year); if (successAdd) { int wineID = req.GetIDBottleByName(wineName); successLog = Logs.AddLog("ajoutExistante", wineID); MessageBox.Show("La mise à jour du nombre de bouteilles a été effectuée correctement."); } else { MessageBox.Show("Une erreur est survenue lors de la mise à jour du nombre de bouteilles. Veuillez réessayer."); } } // problems with at least 1 check else { MessageBox.Show("Une des valeurs spécifiées est incorrecte."); txtNumber.Text = ""; txtYear.Text = ""; } LoadData(); }
private void btnDel_Click(object sender, EventArgs e) { //initializing variables to stock informations from the wine bottle string wineName = ""; string manufacturer = ""; int number = 0; double volume = 0; int year = 0; // initializing the boolean to check if everything is correct -> all is false by default, so that if it works, it changes to true bool successName = false; bool successManu = false; bool successNumber = false; bool successYear = false; bool successVolume = false; bool successFormat = false; bool successPresence = false; bool successOut = false; bool successAlert = false; bool successLog = false; /** * verification of data type * if a field is empty and shouldn't be -> the bottle won't get out */ if (comboWine.SelectedIndex != -1) { wineName = comboWine.SelectedItem.ToString(); successName = true; } if (comboVolumeOUT.SelectedIndex != -1) { successVolume = Double.TryParse(comboVolumeOUT.SelectedItem.ToString(), out volume); } if (comboManufacturerOUT.SelectedIndex != -1) { manufacturer = comboManufacturerOUT.SelectedItem.ToString(); successManu = true; } if (txtNumberOUT.Text != "") { successNumber = Int32.TryParse(txtNumberOUT.Text, out number); if (number < 1) { MessageBox.Show("Le nombre de bouteilles spécifié n'est pas valide."); txtNumberOUT.Text = ""; } } if (comboYearOUT.SelectedIndex != -1) { successYear = Int32.TryParse(comboYearOUT.SelectedItem.ToString(), out year); } //verify if the bottle to delete already exists in database -> true : present, false : non present // occur uniquely if the volume, the name and the year have been validated if (successVolume && successName && successYear) { successPresence = req.CheckBottlePresence(wineName, year, volume); } // if all verification are ok -> will be true, otherwise, will be false successFormat = successNumber && successYear && successName && successManu; successAlert = req.CheckAlertPresenceByBottleName(wineName); // all checks passed, bottle present in DB if (successFormat == true && successPresence) { if (successAlert) { MessageBox.Show("Attention, cette bouteille est prévue pour un évènement !!"); } successOut = Bottles.RemoveBottle(wineName, number, volume, manufacturer, year); // message box to show, depending on the result when getting the right number of bottle out if (successOut) { int wineID = req.GetIDBottleByName(wineName); successLog = Logs.AddLog("retrait", wineID); MessageBox.Show("Le retrait de bouteille(s) a été effectué correctement."); } else { MessageBox.Show("Une erreur est survenue lors du retrait de bouteille(s). Veuillez réessayer."); } } // all checks passed, but the combination of data does not concord with DB else if (successFormat == true && !successPresence) { MessageBox.Show("Cette combinaison de données n'existe pas dans les bouteilles présentes. Veuillez vérifier vos informations."); } // problems with at least 1 check else { MessageBox.Show("Une des valeurs spécifiées est incorrecte."); txtNumber.Text = ""; txtYear.Text = ""; } LoadData(); }