База даних "Телефонний довідник"
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
nt.Descendants("Item").Where(q => q.Attribute("UserID").Value == Variables.CurrentUserID).Count();
this.Text = Variables.Caption + Variables.CurrentUserName + ": " + contactsNumbers.ToString() + " Contacts";
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
void buttonClearSearchTextBox_Click(object sender, EventArgs e)
{
textBoxSearch.Text = "";
LoadPhoneBookItems();
}
void buttonEdit_Click(object sender, EventArgs e)
{
try
{
if (listView1.SelectedItems.Count < 1) return;
string id = listView1.SelectedItems[0].Name.Replace("Item", "");
var item = (from q in Variables.xDocument.Descendants("Item")
where q.Attribute("UserID").Value == Variables.CurrentUserID && q.Attribute("ID").Value == id
select q).First();
if (item == null) return;
ItemForm editForm = new ItemForm(false, true);
editForm.Font = new Font(this.Font.Name, this.FontSize, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
editForm.Text = "Edit Item";
editForm.textBoxAddress.Text = item.Attribute("Address").Value;
editForm.textBoxEMail.Text = item.Attribute("Email").Value;
editForm.textBoxMobile.Text = item.Attribute("Mobile").Value;
editForm.textBoxName.Text = item.Attribute("Name").Value;
editForm.textBoxPhone.Text = item.Attribute("Phone").Value;
editForm.lableRegDate.Text = christianToolStripMenuItem.Checked ? item.Attribute("RegDate").Value: ConvertToPersianDate(item.Attribute("RegDate").Value);
editForm.ItemID = id;
editForm.ShowDialog();
LoadPhoneBookItems();
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
void buttonDelete_Click(object sender, EventArgs e)
{
try
{
if (listView1.SelectedItems.Count < 1) return;
if (MessageBox.Show("Ви впевнені, що хочете видалити запис,його потім не відновиш?", "Попередження", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return;
string id = listView1.SelectedItems[0].Name.Replace("Item", "");
var item = (from q in Variables.xDocument.Descendants("Item")
where q.Attribute("UserID").Value == Variables.CurrentUserID && q.Attribute("ID").Value == id
select q).First();
item.Remove();
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
LoadPhoneBookItems();
q.Attribute("UserID").Value==Variables.CurrentUserID).Count();">int contactsNumbers = Variables.xDocument.Descendants("Item").Where(q => q.Attribute("UserID").Value == Variables.CurrentUserID).Count();
this.Text = Variables.Caption + Variables.CurrentUserName + ": " + contactsNumbers.ToString() + " Contacts";
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
#endregion
#region Menu Strip Events
#region Settings
void rightToLeftToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
rightToLeftToolStripMenuItem.Checked = true;
leftToRightToolStripMenuItem.Checked = false;
textBoxSearch.RightToLeft = RightToLeft.Yes;
listView1.RightToLeft = RightToLeft.Yes;
var query = (from q in Variables.xDocument.Descendants("Setting")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select q).First();
query.Attribute("RightToLeft").Value = "Yes";
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
}
catch { }
}
void leftToRightToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
leftToRightToolStripMenuItem.Checked = true;
rightToLeftToolStripMenuItem.Checked = false;
textBoxSearch.RightToLeft = RightToLeft.No;
listView1.RightToLeft = RightToLeft.No;
var query = (from q in Variables.xDocument.Descendants("Setting")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select q).First();
query.Attribute("RightToLeft").Value = "NO";
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
}
catch { }
}
void toolStripMenuItemFontSize_Click(object sender, EventArgs e)
{
try
{
toolStripMenuItemFontSize8.Checked = toolStripMenuItemFontSize10.Checked = toolStripMenuItemFontSize12.Checked = toolStripMenuItemFontSize14.Checked = toolStripMenuItemFontSize16.Checked = toolStripMenuItemFontSize18.Checked = false;
ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
menuItem.Checked = true;
this.FontSize = float.Parse(menuItem.Text.Trim());
if (this.Font.Size!= this.FontSize)
{
this.Font = new Font(this.Font.Name, this.FontSize, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
var query = (from q in Variables.xDocument.Descendants("Setting")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select q).First();
query.Attribute("FontSize").Value = this.FontSize.ToString();
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
}
}
catch { }
}
void christianToolStripMenuItem_Click(object sender, EventArgs e)
{
christianToolStripMenuItem.Checked = true;
persianToolStripMenuItem.Checked = false;
var query = (from q in Variables.xDocument.Descendants("Setting")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select q).First();
query.Attribute("Dates").Value = "Christian";
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
}
void persianToolStripMenuItem_Click(object sender, EventArgs e)
{
christianToolStripMenuItem.Checked = false;
persianToolStripMenuItem.Checked = true;
var query = (from q in Variables.xDocument.Descendants("Setting")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select q).First();
query.Attribute("Dates").Value = "Persian";
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
}
#endregion
void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
void newUserToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
UserForm newUserForm = new UserForm(true, false, false);
newUserForm.Font = new Font(this.Font.Name, this.FontSize, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
newUserForm.ShowDialog();
ApplySettings();
LoadPhoneBookItems();
if (Variables.CurrentUserName!= "" && Variables.CurrentUserID!= "")
{
q.Attribute("UserID").Value==Variables.CurrentUserID).Count();">int contactsNumbers = Variables.xDocument.Descendants("Item").Where(q => q.Attribute("UserID").Value == Variables.CurrentUserID).Count();
this.Text = Variables.Caption + Variables.CurrentUserName + ": " + contactsNumbers.ToString() + " Contacts";
DisableEnableControls(true);
}
else
DisableEnableControls(false);
}
catch (Exception ex)
{
DisableEnableControls(false);
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
void changeUserToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
UserForm userForm = new UserForm(false, true, false);
userForm.Font = new Font(this.Font.Name, this.FontSize, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
userForm.Show