private void TextBoxScan_TextChanged(object sender, EventArgs e) { ViewExistingProduct.Hide(); ShowAddForm.Hide(); //Goes into the if when the text is only numbers if (TextBoxScan.Text.All(char.IsDigit) && TextBoxScan.Text != "") { LogoPanel.Hide(); //if the barcode already exists in the database, it gets the expiration time that has been added to the product if (Products.Exists(p => p.ID == TextBoxScan.Text)) { FillExistingProductView(); //Product will be added to the food table AddToProductsInHouse(); } else { //If it doesnt exist, addform will be shown with the barcode already added. ShowAddForm.Show(); ShowAddForm.Controls[1].Text = TextBoxScan.Text; } } else { //Fifo logo will be shown when textbox is empty. LogoPanel.Show(); } }
private void AddNewProduct(object sender, EventArgs e) { DatabaseController db = new DatabaseController(); string expTime = "0"; if (ShowAddForm.Controls[9].Text != string.Empty && ShowAddForm.Controls[8].Text != string.Empty && ShowAddForm.Controls[7].Text != string.Empty) { //Converts Einddatum to amount of days and then into a string expTime = (new DateTime(int.Parse(ShowAddForm.Controls[9].Text), int.Parse(ShowAddForm.Controls[8].Text), int.Parse(ShowAddForm.Controls[7].Text)) - DateTime.Today).Days.ToString(); } //if the exp date is unknown (days till expiring is 0 or elss than 0), the product will get the general exp date from its given category. if (int.Parse(expTime) <= 0) { expTime = Categories.First(c => ShowAddForm.Controls[11].Text.Equals(c.Name)).GeneralDaysToExpire.ToString(); } //First inserts the product into the table with all products in our database string sql = "INSERT INTO product (ID, Name, Expiration_time, Description, Category) VALUES (@val0, @val1, @val2, @val3, @val4)"; db.NonQuery(sql, ShowAddForm.Controls[1].Text, //the ID ShowAddForm.Controls[3].Text, //The name expTime, //The expiration time ShowAddForm.Controls[5].Text, //The description ShowAddForm.Controls[11].Text //The category ); //Then inserts it into the food table of the client sql = "INSERT INTO food (Add_date, Product) VALUES (@val0, @val1)"; db.NonQuery(sql, DateTime.Today.ToString("yyyy-MM-dd"), ShowAddForm.Controls[1].Text ); //Addform gets emptied again ShowAddForm.Controls[1].Text = ""; ShowAddForm.Controls[3].Text = ""; ShowAddForm.Controls[5].Text = ""; (ShowAddForm.Controls[7] as ComboBox).SelectedItem = null; (ShowAddForm.Controls[8] as ComboBox).SelectedItem = null; (ShowAddForm.Controls[9] as ComboBox).SelectedItem = null; (ShowAddForm.Controls[11] as ComboBox).SelectedItem = null; DataManager.Instance.GetData(); Products = DataManager.Instance.Products; Categories = DataManager.Instance.Categories; ProductsInHouse = DataManager.Instance.ProductsInHouse; FillExistingProductView(); ShowAddForm.Hide(); ViewExistingProduct.Show(); }
public ScanView(Rectangle size) { InitializeComponent(); _Font = new Font("Arial", 21, FontStyle.Regular); //The textbox for the barcode TextBoxScan.Size = new Size(size.Width / 4, TextBoxScan.Size.Height); TextBoxScan.Location = new Point(size.Width / 4 - TextBoxScan.Width / 2, 110); TextBoxScan.Font = _Font; CheckDirectAdd.Location = new Point(TextBoxScan.Location.X, TextBoxScan.Location.Y + TextBoxScan.Size.Height + 10); //The tables from the MySQL database Products = DataManager.Instance.Products; Categories = DataManager.Instance.Categories; ProductsInHouse = DataManager.Instance.ProductsInHouse; //Add form when product doesn't exist ShowAddForm.BackColor = Color.AliceBlue; ShowAddForm.Location = new Point(size.Width / 2, 0); ShowAddForm.Size = new Size(size.Width / 2, size.Height); ShowAddForm.Hide(); AddControlsToAddForm(ShowAddForm); //Add form when product does exist ViewExistingProduct.BackColor = Color.LightSkyBlue; ViewExistingProduct.Location = new Point(size.Width / 2, 0); ViewExistingProduct.Size = new Size(size.Width / 2, size.Height); ViewExistingProduct.Hide(); AddControlsToViewForm(ViewExistingProduct); //The logo on the right LogoPanel.BackgroundImage = Image.FromFile("..\\..\\Content\\logo.png"); LogoPanel.Size = new Size(size.Width / 2, size.Height); LogoPanel.Location = new Point(size.Width / 2, 0); LogoPanel.BackgroundImageLayout = ImageLayout.Stretch; //Manual add button Button AddButton = new Button(); AddButton.Font = _Font; AddButton.Text = "Toevoegen"; AddButton.Location = new Point(ViewExistingProduct.Controls[10].Location.X, ViewExistingProduct.Controls[10].Location.Y + 70); AddButton.Size = ViewExistingProduct.Controls[10].Size; AddButton.FlatStyle = FlatStyle.Flat; AddButton.FlatAppearance.BorderSize = 0; AddButton.TabStop = false; AddButton.Click += AddButtonManuallyClick; ViewExistingProduct.Controls.Add(AddButton); }