private void btnSubmitRecord_Click(object sender, RoutedEventArgs e) { if (this.recCompany.Text.Equals("") || this.recTechUser.Text.Equals("") || this.recPhone.Text.Equals("") || this.recIssue.Text.Equals("") || this.recResolution.Text.Equals("")) { ModernDialog msgbox = new ModernDialog(); msgbox.Title = "All fields required."; msgbox.Content = "Please complete any empty fields."; msgbox.Buttons = new[] { msgbox.OkButton }; msgbox.ShowDialog(); } else { TimeSpan elapsedTime = new TimeSpan(0); if (isCase.IsChecked.Value && caseNumber.Text.Equals("")) { ModernDialog msgbox = new ModernDialog(); msgbox.Title = "Missing NetSuite Case Number."; msgbox.Content = "Please enter a NetSuite case number."; msgbox.Buttons = new[] { msgbox.OkButton }; msgbox.ShowDialog(); } else { this.Cursor = Cursors.Wait; if (stopWatch.IsRunning) { dt.Stop(); stopWatch.Stop(); elapsedTime = stopWatch.Elapsed; } try { cmd = null; string preparedStatement = string.Empty; string enteredCompany = removeSpecials(this.recCompany.Text); string enteredContact = removeContactSpecials(this.recTechUser.Text); string enteredPhone = removeAllButDigits(this.recPhone.Text); string enteredEmail = removeSpecials(this.recEmail.Text); string enteredIssue = removeSpecials(this.recIssue.Text); string enteredResolution = removeSpecials(this.recResolution.Text); int icheckflag = 0; bool NScheckboxflag = isCase.IsChecked.Value; if (NScheckboxflag) { icheckflag = 1; } dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer + ";Database=" + ICResponse.Properties.Settings.Default.DBName + ";Uid=" + ICResponse.Properties.Settings.Default.DBUser + ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";"); dbConn.Open(); string stringTicketID = getCurrentCallTicketID(); //No UID Found, Create New Record if (stringTicketID.Equals("")) { //Create new record cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.InsertCallRecord, dbConn); cmd.Parameters.AddWithValue("?tech", ICResponse.Properties.Settings.Default.AgentFirstName + " " + ICResponse.Properties.Settings.Default.AgentLastName); cmd.Parameters.AddWithValue("?status", "Not ACD"); cmd.Parameters.AddWithValue("?company", enteredCompany); cmd.Parameters.AddWithValue("?contact", enteredContact); cmd.Parameters.AddWithValue("?phone", enteredPhone); cmd.Parameters.AddWithValue("?email", enteredEmail); cmd.Parameters.AddWithValue("?date", System.DateTime.Today); cmd.Parameters.AddWithValue("?startTime", System.DateTime.Now - elapsedTime); cmd.Parameters.AddWithValue("?stopTime", System.DateTime.Now); cmd.Parameters.AddWithValue("?holdtime", 0); cmd.Parameters.AddWithValue("?duration", Math.Ceiling(elapsedTime.TotalMinutes)); cmd.Parameters.AddWithValue("?brand", selectedbrand); cmd.Parameters.AddWithValue("?issue", enteredIssue); cmd.Parameters.AddWithValue("?resolution", enteredResolution); cmd.Parameters.AddWithValue("?iscase", icheckflag); cmd.Parameters.AddWithValue("?casenumber", caseNumber.Text); } // UID Found update that record else { if (uidEntryIsEmptyandMostRecent(stringTicketID)) { cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.UpdateCallRecord, dbConn); cmd.Parameters.AddWithValue("?company", enteredCompany); cmd.Parameters.AddWithValue("?contact", enteredContact); cmd.Parameters.AddWithValue("?phone", enteredPhone); cmd.Parameters.AddWithValue("?email", enteredEmail); cmd.Parameters.AddWithValue("?brand", selectedbrand); cmd.Parameters.AddWithValue("?issue", enteredIssue); cmd.Parameters.AddWithValue("?resolution", enteredResolution); cmd.Parameters.AddWithValue("?iscase", icheckflag); cmd.Parameters.AddWithValue("?casenumber", caseNumber.Text); cmd.Parameters.AddWithValue("?uid", stringTicketID); } else { //Create new record cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.InsertCallRecord, dbConn); cmd.Parameters.AddWithValue("?tech", ICResponse.Properties.Settings.Default.AgentFirstName + " " + ICResponse.Properties.Settings.Default.AgentLastName); cmd.Parameters.AddWithValue("?status", "Not ACD"); cmd.Parameters.AddWithValue("?company", enteredCompany); cmd.Parameters.AddWithValue("?contact", enteredContact); cmd.Parameters.AddWithValue("?phone", enteredPhone); cmd.Parameters.AddWithValue("?email", enteredEmail); cmd.Parameters.AddWithValue("?date", System.DateTime.Today); cmd.Parameters.AddWithValue("?startTime", System.DateTime.Now - elapsedTime); cmd.Parameters.AddWithValue("?stopTime", System.DateTime.Now); cmd.Parameters.AddWithValue("?holdtime", 0); cmd.Parameters.AddWithValue("?duration", Math.Ceiling(elapsedTime.TotalMinutes)); cmd.Parameters.AddWithValue("?brand", selectedbrand); cmd.Parameters.AddWithValue("?issue", enteredIssue); cmd.Parameters.AddWithValue("?resolution", enteredResolution); cmd.Parameters.AddWithValue("?iscase", icheckflag); cmd.Parameters.AddWithValue("?casenumber", caseNumber.Text); } } dbConn.Open(); cmd.Prepare(); cmd.ExecuteNonQuery(); ModernDialog msgbox = new ModernDialog(); msgbox.Title = "Call Submitted"; msgbox.Content = "Duration: " + Math.Ceiling(elapsedTime.TotalMinutes) + " minute(s)"; msgbox.Buttons = new[] { msgbox.OkButton }; msgbox.ShowDialog(); //dbConn.Close(); SupportContent.AddCallConfirmation returntobase = new SupportContent.AddCallConfirmation(); this.Content = returntobase; } catch (MySqlException err) { ModernDialog msgbox = new ModernDialog(); msgbox.Title = "MySQL Exception"; msgbox.Buttons = new[] { msgbox.OkButton }; msgbox.ShowDialog(); System.Diagnostics.Debug.WriteLine(err); } finally { if (dbConn != null) { dbConn.Close(); //close the connection } } this.Cursor = Cursors.Arrow; } } }
private void CallCancel() { try { SupportContent.AddCallConfirmation returnfromcall = new SupportContent.AddCallConfirmation(); this.Content = returnfromcall; } catch (MySqlException err) { System.Diagnostics.Debug.WriteLine(err); } finally { if (dbConn != null) { dbConn.Close(); //close the connection } } }