async void CustomerSave_Click(object sender, RoutedEventArgs e) { _cInfo.LastModified = DateTime.Now; //_cInfo.Notes = rtbNotes.GetRTF(); if (_cInfo == null || _cInfo.SQLID == 0) { _cInfo = DBAbstract.CreateCustomer(_cInfo); CloseableTabItem tbi = new CloseableTabItem(); CustomerNotes ctn = new CustomerTrackerWPF.CustomerNotes(_cInfo); var header = new TextBlock { Text = _cInfo.FirstName + " " + _cInfo.LastName, VerticalAlignment = VerticalAlignment.Bottom}; tbi.SetHeader(header); tbi.Content = ctn; tbi.Click += (ssender, le) => { CustomerTrackerWPF.Window1.mainWindow.CloseTabButton_OnClick(ssender, le); }; ctn.VerticalAlignment = VerticalAlignment.Top; CustomerTrackerWPF.Window1.mainWindow.mTabControl.Items.Add(tbi); CustomerTrackerWPF.Window1.mainWindow.mTabControl.SelectedItem = tbi; ClearItUp(); } else { bool success = DBAbstract.UpdateCustomer(_cInfo); if (!success) { await Window1.mainWindow.ShowMessage("Failed to update customer information", "Update Failed", MessageDialogStyle.Affirmative); return; } _isDirty = false; //rtbNotes.isDirty = false; } }
public CustomerNotes(int cid) { InitializeComponent(); _cInfo = DBAbstract.FindCustomerByID(cid); this.DataContext = _cInfo; }
public CustomerNotes(CustomerInformation cInfo) { InitializeComponent(); _cInfo = cInfo; this.DataContext = _cInfo; }
void LookUpSearch_Click(object sender, RoutedEventArgs e) { DataTable customer; CustomerInformation cinfo = new CustomerInformation(iftFirstName.Text,iftLastName.Text,iftPhoneNumber.Text, iftEMail.Text,iftCompanyName.Text,"",0, dateTimePicker1.SelectedDate); customer = DBAbstract.FindCustomer(cinfo, false,chbLastUpdated.IsChecked); lviewResults.ItemsSource = null; lviewResults.Items.Clear(); lviewResults.ItemsSource = customer.DefaultView; customer.Dispose(); }
public Attachments(CustomerInformation cinfo) { InitializeComponent(); _cInfo = cinfo; if (!Directory.Exists(CTGlobals.Settings.AttachmentsFolder + _cInfo.SQLID.ToString())) Directory.CreateDirectory(CTGlobals.Settings.AttachmentsFolder + _cInfo.SQLID.ToString()); //string root = System.IO.Path.GetDirectoryName(CTGlobals.Settings.AttachmentsFolder + _cInfo.SQLID.ToString()); UpdateList(); }
public CustomerInformation CreateCustomer(CustomerInformation cinfo) { global::CustomerInformation ci = new global::CustomerInformation(); ci.CompanyName = cinfo.CompanyName; ci.EMail = cinfo.EMail; ci.FirstName = cinfo.FirstName; ci.LastModified = Convert.ToDateTime(cinfo.LastModified); ci.LastModifiedSpecified = true; ci.LastName = cinfo.LastName; ci.Notes = cinfo.Notes; ci.PhoneNumber = cinfo.PhoneNumber; //ci.SQLID = cinfo.SQLID; CreateCustomerRequest creq = new CreateCustomerRequest(ci); Task<CreateCustomerResponse> cres = _sqlService.CreateCustomerAsync(creq); ci = cres.Result.CreateCustomerResult; return new CustomerInformation(ci.FirstName,ci.LastName,ci.PhoneNumber,ci.EMail,ci.CompanyName,ci.Notes,ci.SQLID,cinfo.LastModified); }
public CustomerInformation CreateCustomer(CustomerInformation cinfo) { sqlconn.Open(); SQLiteCommand cmd = new SQLiteCommand(_createCommandText, sqlconn); cmd.Parameters.AddWithValue("@cfirstname", cinfo.FirstName); cmd.Parameters.AddWithValue("@clastname", cinfo.LastName); cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); cmd.Parameters.AddWithValue("@cemail", cinfo.EMail); cmd.Parameters.AddWithValue("@cconame", cinfo.CompanyName); cmd.Parameters.AddWithValue("@cnotes", cinfo.Notes); cmd.Parameters.AddWithValue("@clastmodified", cinfo.LastModified.ToString()); try { cmd.ExecuteNonQuery(); sqlconn.Close(); return FindCustomerC(cinfo, true); } catch (Exception ex) { MessageBox.Show(ex.Message); sqlconn.Close(); return null; } }
public DataTable FindCustomer(CustomerInformation cinfo, bool strict, bool? bytime) { global::CustomerInformation ci = new global::CustomerInformation(); ci.CompanyName = cinfo.CompanyName; ci.EMail = cinfo.EMail; ci.FirstName = cinfo.FirstName; if ((bool)bytime) { ci.LastModified = (Convert.ToDateTime(cinfo.LastModified)); ci.LastModifiedSpecified = true; } else { ci.LastModifiedSpecified = false; } ci.LastName = cinfo.LastName; ci.Notes = cinfo.Notes; ci.PhoneNumber = cinfo.PhoneNumber; ci.SQLID = cinfo.SQLID; ci.SQLIDSpecified = true; FindCustomerRequest fcreq = new FindCustomerRequest(ci,strict,bytime); Task<FindCustomerResponse> fcres = _sqlService.FindCustomerAsync(fcreq); return fcres.Result.FindCustomerResult; }
public CustomerInformation FindCustomerByID(int cID) { DataTable dt = new DataTable(); CustomerInformation ci = new CustomerInformation(); String commandText = "SELECT * FROM customer "; String swhere = "WHERE"; sqlconn.Open(); SQLiteCommand cmd = new SQLiteCommand(sqlconn); cmd.Parameters.AddWithValue("@cid", cID); swhere += " cID = @cid;"; commandText += swhere; cmd.CommandText = commandText; SQLiteDataReader reader = cmd.ExecuteReader(); dt.Load(reader); reader.Close(); sqlconn.Close(); foreach (DataRow r in dt.Rows) { ci.FirstName = r["cFirstName"].ToString(); ci.LastName = r["cLastName"].ToString(); ci.CompanyName = r["cCoName"].ToString(); ci.EMail = r["cEMail"].ToString(); ci.LastModified = DateTime.Parse(r["cLastModified"].ToString()); ci.Notes = r["cNotes"].ToString(); ci.PhoneNumber = r["cPhoneNumber"].ToString(); ci.SQLID = Convert.ToInt32(r["cID"].ToString()); } return ci; }
void Importold_Click(object sender, RoutedEventArgs e) { var olddbfilename = (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\\DistNote\\distnotedb.s3db"; importProgress.Value = 0; if (!File.Exists(olddbfilename)) { CTGlobals.Settings.ImportedOldDB = true; return; } string olddbconnectionstring = string.Format("Data Source= {0}", (olddbfilename)); String commandText = "SELECT * FROM Customer"; CustomerInformation ci = new CustomerInformation(); CustomerInformation cr = new CustomerInformation(); SQLiteConnection oconn = new SQLiteConnection(olddbconnectionstring); oconn.Open(); SQLiteCommand cmd = new SQLiteCommand(commandText, oconn); DataTable dt = new DataTable(); SQLiteDataReader reader = cmd.ExecuteReader(); dt.Load(reader); reader.Close(); oconn.Close(); string[] fnln = { }; String name = ""; String[] atts; String oldatt = ""; String newatt = ""; var rtb1 = new RichTextBox(); importProgress.Maximum = dt.Rows.Count; foreach (DataRow r in dt.Rows) { name = r["cName"].ToString(); fnln = name.Split(' '); ci.FirstName = fnln[0]; if (fnln.Length > 1) ci.LastName = fnln[1]; ci.CompanyName = string.Empty; ci.EMail = r["cEmail"].ToString(); ci.LastModified = DateTime.Parse(r["cTouchTime"].ToString()); Paragraph textParagraph = new Paragraph(); rtb1.Document.Blocks.Clear(); textParagraph.Inlines.Clear(); rtb1.CaretPosition = rtb1.Document.ContentStart; textParagraph.Inlines.Add(r["cNotes"].ToString()); rtb1.Document.Blocks.Add(textParagraph); TextRange textRange = new TextRange(rtb1.Document.ContentStart, rtb1.Document.ContentEnd); ci.Notes = textRange.Text; ci.PhoneNumber = r["cPhoneNumber"].ToString(); ci.SQLID = 0; cr = DBAbstract.CreateCustomer(ci); if (cr != null) { oldatt = (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DistNote\\" + r["cPK"].ToString() + "\\"); newatt = (CTGlobals.Settings.AttachmentsFolder + cr.SQLID.ToString() + "\\"); if (Directory.Exists(oldatt)) { if (!Directory.Exists(newatt)) { Directory.CreateDirectory(newatt); atts = Directory.GetFiles(oldatt); foreach (String s in atts) { File.Copy(s, newatt + Path.GetFileName(s)); } } } } importProgress.Value++; } CTGlobals.Settings.ImportedOldDB = true; importold.IsEnabled = false; }
public static bool UpdateCustomer(CustomerInformation cinfo) { return (CTGlobals.Settings.isServer == true) ? _dbServer.UpdateCustomer(cinfo) : _sqlitedb.UpdateCustomer(cinfo); }
public static DataTable FindCustomer(CustomerInformation cinfo, bool strict, bool? bytime) { return (CTGlobals.Settings.isServer == true) ? _dbServer.FindCustomer(cinfo, strict, bytime) : _sqlitedb.FindCustomer(cinfo, strict, bytime); }
public Reminders(CustomerInformation cInfo) { InitializeComponent(); _cInfo = cInfo; remDT.Value = DateTime.Now; }
public CustomerInformation FindCustomerByID(int cID) { global::CustomerInformation ci = new global::CustomerInformation(); global::FindCustomerByIDResponse fcbid = new FindCustomerByIDResponse(); FindCustomerByIDRequest fcbidq = new FindCustomerByIDRequest(cID); fcbid = _sqlService.FindCustomerByID(fcbidq); ci = fcbid.FindCustomerByIDResult; CustomerInformation co = new CustomerInformation(ci.FirstName, ci.LastName, ci.PhoneNumber, ci.EMail, ci.CompanyName, ci.Notes, ci.SQLID, Convert.ToDateTime(ci.LastModified)); return co; }
public bool UpdateCustomer(CustomerInformation cinfo) { sqlconn.Open(); SQLiteCommand cmd = new SQLiteCommand(_updateCommandText, sqlconn); cmd.Parameters.AddWithValue("@cfirstname", cinfo.FirstName); cmd.Parameters.AddWithValue("@clastname", cinfo.LastName); cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); cmd.Parameters.AddWithValue("@cemail", cinfo.EMail); cmd.Parameters.AddWithValue("@cnotes", cinfo.Notes); cmd.Parameters.AddWithValue("@cconame", cinfo.CompanyName); cmd.Parameters.AddWithValue("@clastmodified", cinfo.LastModified.ToString()); cmd.Parameters.AddWithValue("@cid", cinfo.SQLID); try { cmd.ExecuteNonQuery(); sqlconn.Close(); return true; } catch (Exception fail) { MessageBox.Show(fail.Message); sqlconn.Close(); return false; } }
private CustomerInformation FindCustomerC(CustomerInformation cinfo, bool strict) { DataTable dt = new DataTable(); CustomerInformation ci = new CustomerInformation(); String commandText = "SELECT * FROM customer "; String swhere = "WHERE"; sqlconn.ConnectionString = CTGlobals.Settings.SQLiteConnectionString; sqlconn.Open(); SQLiteCommand cmd = new SQLiteCommand(sqlconn); if (strict) { if (!string.IsNullOrEmpty(cinfo.FirstName)) { cmd.Parameters.AddWithValue("@cfirstname", cinfo.FirstName); swhere += " cFirstName = @cfirstname and"; } if (!string.IsNullOrEmpty(cinfo.LastName)) { cmd.Parameters.AddWithValue("@clastname", cinfo.LastName); swhere += " cLastName = @clastname and"; } if (!string.IsNullOrEmpty(cinfo.CompanyName)) { cmd.Parameters.AddWithValue("@cconame", cinfo.CompanyName); swhere += " cCoName = @cconame and"; } if (!string.IsNullOrEmpty(cinfo.PhoneNumber)) { cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); swhere += " cPhoneNumber = @cphonenumber and"; } if (!string.IsNullOrEmpty(cinfo.EMail)) { cmd.Parameters.AddWithValue("@cemail", cinfo.EMail); swhere += " cEMail = @cemail and"; } if (!string.IsNullOrEmpty(cinfo.Notes)) { cmd.Parameters.AddWithValue("@cnotes", cinfo.Notes); swhere += " cNotes = @cnotes and"; } } else { if (!string.IsNullOrEmpty(cinfo.FirstName)) { cmd.Parameters.AddWithValue("@cfirstname", "%" + cinfo.FirstName + "%"); swhere += " cFirstName like @cfirstname and"; } if (!string.IsNullOrEmpty(cinfo.LastName)) { cmd.Parameters.AddWithValue("@clastname", cinfo.LastName); swhere += " cLastName = @clastname and"; } if (!string.IsNullOrEmpty(cinfo.CompanyName)) { cmd.Parameters.AddWithValue("@cconame", "%" + cinfo.CompanyName + "%"); swhere += " cCoName like @cconame and"; } if (!string.IsNullOrEmpty(cinfo.PhoneNumber)) { cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); swhere += " cPhoneNumber = @cphonenumber and"; } if (!string.IsNullOrEmpty(cinfo.EMail)) { cmd.Parameters.AddWithValue("@cemail", "%" + cinfo.EMail + "%"); swhere += " cEmail like @cemail and"; } if (!string.IsNullOrEmpty(cinfo.Notes)) { cmd.Parameters.AddWithValue("@cnotes", "%" + cinfo.Notes + "%"); swhere += " cNotes like @cnotes and"; } } swhere = swhere.Remove((swhere.Length - 4), 4); commandText += swhere; cmd.CommandText = commandText; SQLiteDataReader reader = cmd.ExecuteReader(); dt.Load(reader); reader.Close(); sqlconn.Close(); foreach (DataRow r in dt.Rows) { ci.FirstName = r["cFirstName"].ToString(); ci.LastName = r["cLastName"].ToString(); ci.CompanyName = r["cCoName"].ToString(); ci.EMail = r["cEMail"].ToString(); ci.LastModified = DateTime.Parse(r["cLastModified"].ToString()); ci.Notes = r["cNotes"].ToString(); ci.PhoneNumber = r["cPhoneNumber"].ToString(); ci.SQLID = Convert.ToInt32(r["cID"].ToString()); } return ci; }
private void ClearItUp() { LoopVisualTree(this); //rtbNotes.Clear(); RichTextControl.Text = string.Empty; RichTextControl.Clear(); RichTextControl.Document.Blocks.Clear(); _hasLoaded = false; _isDirty = false; _cInfo = new CustomerInformation(); this.DataContext = _cInfo; }
public DataTable FindCustomer(CustomerInformation cinfo, bool strict, bool? bytime) { DataTable dt = new DataTable(); String commandText = "SELECT * FROM customer "; String swhere = "WHERE"; sqlconn.Open(); SQLiteCommand cmd = new SQLiteCommand(sqlconn); if (strict) { if (!string.IsNullOrEmpty(cinfo.FirstName)) { cmd.Parameters.AddWithValue("@cfirstname", cinfo.FirstName); swhere += " cFirstName = @cfirstname and"; } if (!string.IsNullOrEmpty(cinfo.LastName)) { cmd.Parameters.AddWithValue("@clastname", cinfo.LastName); swhere += " cLastName = @clastname and"; } if (!string.IsNullOrEmpty(cinfo.CompanyName)) { cmd.Parameters.AddWithValue("@cconame", cinfo.CompanyName); swhere += " cCoName = @cconame and"; } if (!string.IsNullOrEmpty(cinfo.PhoneNumber)) { cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); swhere += " cPhoneNumber = @cphonenumber and"; } if (!string.IsNullOrEmpty(cinfo.EMail)) { cmd.Parameters.AddWithValue("@cemail", cinfo.EMail); swhere += " cEMail = @cemail and"; } if (!string.IsNullOrEmpty(cinfo.Notes)) { cmd.Parameters.AddWithValue("@cnotes", cinfo.Notes); swhere += " cNotes = @cnotes and"; } } else { if (!string.IsNullOrEmpty(cinfo.FirstName)) { cmd.Parameters.AddWithValue("@cfirstname", "%" + cinfo.FirstName + "%"); swhere += " cFirstName like @cfirstname and"; } if (!string.IsNullOrEmpty(cinfo.LastName)) { cmd.Parameters.AddWithValue("@clastname", "%" + cinfo.LastName + "%"); swhere += " cLastName like @clastname and"; } if (!string.IsNullOrEmpty(cinfo.CompanyName)) { cmd.Parameters.AddWithValue("@cconame", "%" + cinfo.CompanyName + "%"); swhere += " cCoName like @cconame and"; } if (!string.IsNullOrEmpty(cinfo.PhoneNumber)) { cmd.Parameters.AddWithValue("@cphonenumber", cinfo.PhoneNumber); swhere += " cPhoneNumber = @cphonenumber and"; } if (!string.IsNullOrEmpty(cinfo.EMail)) { cmd.Parameters.AddWithValue("@cemail", "%" + cinfo.EMail + "%"); swhere += " cEmail like @cemail and"; } if (!string.IsNullOrEmpty(cinfo.Notes)) { cmd.Parameters.AddWithValue("@cnotes", "%" + cinfo.Notes + "%"); swhere += " cNotes like @cnotes and"; } if ((bool)bytime) { if (!string.IsNullOrEmpty(cinfo.LastModified.ToString())){ String [] clm = cinfo.LastModified.ToString().Split(' '); cmd.Parameters.AddWithValue("@clastmodified", "%" + clm[0] + "%"); swhere += " cLastModified like @clastmodified and"; } } } swhere = swhere.Remove((swhere.Length - 4), 4); commandText += swhere; cmd.CommandText = commandText; SQLiteDataReader reader = cmd.ExecuteReader(); dt.Load(reader); reader.Close(); sqlconn.Close(); return dt; }
public bool UpdateCustomer(CustomerInformation cinfo) { global::CustomerInformation ci = new global::CustomerInformation(); ci.CompanyName = cinfo.CompanyName; ci.EMail = cinfo.EMail; ci.FirstName = cinfo.FirstName; ci.LastModified = Convert.ToDateTime(cinfo.LastModified); ci.LastModifiedSpecified = true; ci.LastName = cinfo.LastName; ci.Notes = cinfo.Notes; ci.PhoneNumber = cinfo.PhoneNumber; ci.SQLID = cinfo.SQLID; ci.SQLIDSpecified = true; UpdateCustomerRequest ucreq = new UpdateCustomerRequest(ci); Task<UpdateCustomerResponse> ucres = _sqlService.UpdateCustomerAsync(ucreq); return ucres.Result.UpdateCustomerResult; }