private void btnOk_Click(object sender, EventArgs e) { if (!ValidateFields()) { return; } string filename = string.Empty; try { DataTable dt = DB_Handle.GetDataTable( string.Format(@"SELECT * from DISCS WHERE disc_id='{0}' and location_id='{1}'", txtDisc.Text, ddLocation.Text)); if (dt.Rows.Count < 1) { Error_Handle.TipError("No Results Found.", toolTip, imgError); } else { Disc = dt.Rows[0][0].ToString(); Page = dt.Rows[0][1].ToString(); Slot = Convert.ToInt32(dt.Rows[0][2]); Location = ddLocation.Text; DialogResult = DialogResult.OK; Close(); } } catch (Exception ex) { Error_Handle.TipError("Error Finding Disc : " + ex.Message, toolTip, imgError); } }
/// <summary> /// Inserts title information to gridview if valid. /// Clears previous fields on success. /// Displays error tip on failure. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInsert_Click(object sender, EventArgs e) { if (ddInsTitle.Text.Length > 0 && ddInsTitle.FindStringExact(ddInsTitle.Text) != -1) { if (txtSeason.Text.Length < 1) { Error_Handle.TipError("Season required\n", toolTip, txtSeason); } else if (txtRangeStart.Text.Length < 1) { Error_Handle.TipError("Start range required\n", toolTip, txtRangeStart); } else if (txtRangeEnd.Text.Length < 1) { Error_Handle.TipError("End range required\n", toolTip, txtRangeEnd); } else { DataGridViewRow gvr = new DataGridViewRow(); gvr.CreateCells(gvContents, ddInsTitle.Text, txtSeason.Text, txtRangeStart.Text.Replace(" ", ""), txtRangeEnd.Text.Replace(" ", ""), "null"); gvContents.Rows.Add(gvr); txtSeason.Text = "1"; ddInsTitle.Text = ""; txtRangeStart.Clear(); txtRangeEnd.Clear(); } } else { Error_Handle.TipError("Invalid title\n", toolTip, ddInsTitle); } }
private bool ValidateFields() { if (txtDisc.Text.Length < 1) { Error_Handle.TipError("Disc ID Required\n", toolTip, txtDisc); return(false); } return(true); }
private void btnOk_Click(object sender, EventArgs e) { if (!ValidateFields()) { return; } string filename = string.Empty; try { if (txtGroup.Text.Length > 1) { filename = '[' + txtGroup.Text + ']' + ' '; } filename += txtTitle.Text + FileNameFormat.ToFormat(txtStart.Text, txtSeason.Text, fileformat); string fullpath = Path.Combine(dirname, filename.Replace(' ', '_')); file.FileName = fullpath; if (txtEnd.Text.Length > 1) { fullpath = file.FileName.Replace(file.EstimateEpisode(), file.EstimateEpisode() + "-" + txtEnd.Text); } fullpath = Path.ChangeExtension(fullpath, radType_Filler.Checked ? "filler" : "missing"); if (File.Exists(fullpath)) { Error_Handle.TipError("Title Already Exists\n", toolTip, txtTitle); return; } imgWorking.Visible = true; File.CreateText(fullpath); Close(); } catch (Exception ex) { Error_Handle.TipError("Error Creating File : " + ex.Message, toolTip, txtTitle); } }
private bool ValidateFields() { if (txtTitle.Text.Length < 1) { Error_Handle.TipError("Title Required\n", toolTip, txtTitle); return(false); } if (txtStart.Text.Length < 1) { Error_Handle.TipError("Start Required\n", toolTip, txtStart); return(false); } if (txtEnd.Text.Length >= 1) { if (Convert.ToInt32(txtEnd.Text) < Convert.ToInt32(txtStart.Text)) { Error_Handle.TipError("Cannot Be Less Than Start\n", toolTip, txtEnd); return(false); } } return(true); }
/// <summary> /// Attempts to save selected disc and each of its content rows. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveClick(object sender, EventArgs e) { bool rollbackpos = false; if (txtDisc.Text.Length < 1) { Error_Handle.TipError("Disc required\n", toolTip, txtDisc); } else if (txtPage.Text.Length < 1) { Error_Handle.TipError("Page required\n", toolTip, txtPage); } else if (txtSlot.Text.Length < 1) { Error_Handle.TipError("Slot required\n", toolTip, txtSlot); } else if (ddLocation.Text.Length < 1) { Error_Handle.TipError("Location required\n", toolTip, ddLocation); } else if (gvContents.Rows.Count < 1) { Error_Handle.TipError("Content required\n", toolTip, gvContents); } else { try { DB_Handle.UpdateTable(string.Format( @"INSERT OR REPLACE INTO DISCS VALUES ('{0}','{1}','{2}','{3}');", txtDisc.Text, txtPage.Text, txtSlot.Text, ddLocation.Text)); if (isNewRecord) { rollbackpos = true; } DB_Handle.OpenConnection(); for (int i = 0; i <= gvContents.Rows.Count - 1; i++) { DB_Handle.ScalarUpdate(string.Format( @"INSERT OR REPLACE INTO CONTENTS (content_id, title_id, season, rangeStart, rangeEnd) VALUES ({0},{1},'{2}','{3}','{4}');", gvContents.Rows[i].Cells[4].Value, "\"" + gvContents.Rows[i].Cells[0].Value + "\"", gvContents.Rows[i].Cells[1].Value, gvContents.Rows[i].Cells[2].Value, gvContents.Rows[i].Cells[3].Value)); DB_Handle.ScalarUpdate(string.Format( @"INSERT OR REPLACE INTO DISC_CONTENTS (content_id, disc_id, location_id) VALUES (last_insert_rowid(),'{0}','{1}');", txtDisc.Text, ddLocation.Text)); } BetterDialog.ShowDialog("Disc Save", "Success", "", "", "OK", null, BetterDialog.ImageStyle.Icon); } catch (Exception ex) { if (rollbackpos) { DB_Handle.UpdateTable(string.Format( @"DELETE FROM DISCS WHERE disc_id = '{0}' AND location_id = '{1}'", txtDisc.Text, ddLocation.Text)); } BetterDialog.ShowDialog("Disc Save", "Error : " + ex.Message, "", "", "OK", null, BetterDialog.ImageStyle.Icon); } finally { DB_Handle.CloseConnection(); DButton.SelBtn.DButton_Click(null, null); loadPage(); } } }
/// <summary> /// Attempts to update title and information. /// Validates information. /// Renames image if exists. /// </summary> /// <remarks>'Insert into' for new records only.</remarks> /// <returns>Pass or fail coniditon.</returns> public bool saveData() { bool status = false; try { if (txtTitle.Text.Trim().Length == 0) { Error_Handle.TipError("Title required\n", toolTip, txtTitle); } else if (isnewrecord && SearchExistingTitles()) { Error_Handle.TipError("Title already exists\n", toolTip, txtTitle); } else if (ddCategory.Text.Length == 0) { Error_Handle.TipError("Category required\n", toolTip, ddCategory); } else if (ddStatus.Text.Length < 1) { Error_Handle.TipError("Status required\n", toolTip, ddStatus); } else if (ddLanguage.Text.Length < 1) { Error_Handle.TipError("Language required\n", toolTip, ddLanguage); } else if (txtYear.Text.Length != 4) { Error_Handle.TipError("Year required\n", toolTip, txtYear); } else if (txtEpisode.Text.Length < 1) { Error_Handle.TipError("Episode required\n", toolTip, txtEpisode); } else { if (isnewrecord) { DB_Handle.UpdateTable(string.Format( @"INSERT INTO TITLES VALUES ({0},'{1}','{2}','{3}','{4}','{5}');", "\"" + txtTitle.Text.Trim() + "\"", txtEpisode.Text.Replace(" ", ""), ddCategory.Text, txtYear.Text, ddStatus.Text, ddLanguage.Text, currentTitle)); } else { DB_Handle.UpdateTable(string.Format( @"UPDATE TITLES SET title_id={0}, episodes='{1}', category='{2}', year='{3}', status='{4}', language='{5}' WHERE title_id={6};", "\"" + txtTitle.Text.Trim() + "\"", txtEpisode.Text.Replace(" ", ""), ddCategory.Text, txtYear.Text, ddStatus.Text, ddLanguage.Text, "\"" + currentTitle + "\"")); DB_Handle.UpdateTable(string.Format( @"UPDATE CONTENTS SET title_id={0} WHERE title_id={1};", "\"" + txtTitle.Text.Trim() + "\"", "\"" + currentTitle + "\"")); Image_IO.rename_Image(currentTitle, txtTitle.Text.Trim()); } BetterDialog.ShowDialog("Saved", "Success", string.Empty, string.Empty, "OK", null, BetterDialog.ImageStyle.Icon); status = true; populateDropDownTitles(); } } catch (Exception ex) { Error_Handle.TipError(ex.Message, toolTip, imgError); } return(status); }