private void UpdateButton_Click(object sender, EventArgs e, Form createForm, VideoLibraryControl control, string SearchData, string location, string column, string filePath) { Excel.Application objExcel; Excel.Workbook objBook; Excel._Worksheet objSheet; Excel.Range rowRange; SetupExcel(filePath, out objExcel, out objBook, out objSheet, out rowRange); string recipeMessage = "Update selected Title: " + SearchData + Environment.NewLine; if (MessageBox.Show(recipeMessage, "Update Title Search", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var tBox = "textBox"; TextBox tb = new TextBox(); for (int count = 1; count < 13; count++) { tBox = "textBox" + count; tb = (TextBox)control.Controls[tBox]; rowRange = objSheet.Cells[location, column]; objSheet.Cells[location, column] = tb.Text; column = Increment(column); } recipeMessage = "Title Name " + SearchData + " has been updated!" + Environment.NewLine; MessageBox.Show(recipeMessage, "Title Update", MessageBoxButtons.OK, MessageBoxIcon.Information); objBook.SaveAs(filePath); } else { recipeMessage = "Title Name " + SearchData + " was not updated!" + Environment.NewLine; MessageBox.Show(recipeMessage, "Title Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } ReleaseExcelObject(filePath, objExcel, objBook, objSheet); createForm.Close(); }
private void Remove_Click(object sender, EventArgs e) { string filePath; OpenFileDialog openfile = OpenNewFile(); openfile.ShowDialog(); filePath = CheckOpenFile(openfile); while (!(File.Exists(filePath))) { filePath = CheckOpenFile(openfile); } string str; string location = ""; string LibraryMessage = ""; Excel.Application objExcel; Excel.Workbook objBook; Excel._Worksheet objSheet; Excel.Range rowRange; SetupExcel(filePath, out objExcel, out objBook, out objSheet, out rowRange); Form RemoveForm = new Form() { Text = "Remove Library Item", AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, FormBorderStyle = FormBorderStyle.Fixed3D, AutoScroll = true, AllowDrop = true, // allows user to drag and drop Enabled = true // changes if user can enter data (true = yes, false = no) }; Button btn = new Button() { FlatStyle = FlatStyle.Popup, Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0))), Location = new System.Drawing.Point(335, 640), Name = "Remove", Size = new System.Drawing.Size(116, 56), TabIndex = 54, Text = "Remove", UseVisualStyleBackColor = true }; RemoveForm.Controls.Add(btn); string SearchData = Interaction.InputBox("Enter Title To Find", "Search Title", ""); while (string.IsNullOrEmpty(SearchData) || string.IsNullOrWhiteSpace(SearchData)) { LibraryMessage = "You entered blank Title!" + Environment.NewLine + " Would you like to try again ?"; if (MessageBox.Show(LibraryMessage, "New Title Search", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { SearchData = Interaction.InputBox("Enter Title To Find", "Locate Title", ""); } else { return; // Exits out current function } } LibraryMessage = "You selected Title: " + SearchData + Environment.NewLine; MessageBox.Show(LibraryMessage, "New Title Search", MessageBoxButtons.OK, MessageBoxIcon.Information); location = FindExcelData(filePath, SearchData); while (location == "") { LibraryMessage = "\t" + "Title Name " + SearchData + " not found!" + Environment.NewLine + "Do you want to search for a different Title?"; if (MessageBox.Show(LibraryMessage, "New Title Search", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { SearchData = Interaction.InputBox("Enter Title To Find", "Locate Title", ""); location = FindExcelData(filePath, SearchData); } else { return; // Exits out current function } } string column = "A"; VideoLibraryControl vlc = new VideoLibraryControl() { ForeColor = System.Drawing.Color.Black, BackColor = System.Drawing.Color.Lavender }; RemoveForm.Controls.Add(vlc); RemoveForm.Show(); var tBox = "textBox"; TextBox tb = new TextBox(); for (int count = 1; count < 13; count++) { tBox = "textBox" + count; tb = (TextBox)vlc.Controls[tBox]; rowRange = objSheet.Cells[location, column]; var str1 = rowRange.Value; if (str1 == null) { str = " "; tb.Text = str; } else { if (column == "D") { DateTime dt = new DateTime(); DateTime.TryParse(rowRange.Text, out dt); tb.Text = String.Format("{0:hh:mm}", dt); } else { str = str1.ToString(); tb.Text = str; } } tb.ReadOnly = false; column = Increment(column); } column = "A"; btn.Click += (sender2, e2) => RemoveButton_Click(sender2, e2, RemoveForm, SearchData, location, column, filePath); }