База даних "Телефонний довідник"
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
}
}
string ConvertToPersianDate(string stringDate)
{
try
{
DateTime dateTime = DateTime.Parse(stringDate);
PersianCalendar persianCalendar = new PersianCalendar();
var str = persianCalendar.GetYear(dateTime).ToString() + " / " +
persianCalendar.GetMonth(dateTime).ToString() + " / " +
persianCalendar.GetDayOfMonth(dateTime).ToString() + " " +
persianCalendar.GetHour(dateTime).ToString() + ":" +
persianCalendar.GetMinute(dateTime).ToString() + ":" +
persianCalendar.GetSecond(dateTime).ToString();
return str;
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
return "";
}
}
#region listview
void textBoxSearch_TextChanged(object sender, EventArgs e)
{
try
{
if (textBoxSearch.Text.Trim() == "")
{
LoadPhoneBookItems();
return;
}
listView1.Items.Clear();
var query = from q in Variables.xDocument.Descendants("Item")
where q.Attribute("UserID").Value == Variables.CurrentUserID &&
(q.Attribute("Name").Value.ToLower().Contains(textBoxSearch.Text.Trim().ToLower())
q.Attribute("Phone").Value.ToLower().Contains(textBoxSearch.Text.Trim().ToLower())
q.Attribute("Mobile").Value.ToLower().Contains(textBoxSearch.Text.Trim().ToLower())
q.Attribute("Email").Value.ToLower().Contains(textBoxSearch.Text.Trim().ToLower())
q.Attribute("Address").Value.ToLower().Contains(textBoxSearch.Text.Trim().ToLower()))
select q;
if (query.Count() < 1) return;
foreach (var item in query)
{
ListViewItem listViewItems = new ListViewItem(new string[]
{ item.Attribute("Name").Value,
item.Attribute("Phone").Value,
item.Attribute("Mobile").Value,
item.Attribute("Email").Value,
item.Attribute("Address").Value,
item.Attribute("RegDate").Value});
listViewItems.Name = "Item" + item.Attribute("ID").Value;
listView1.Items.Add(listViewItems);
}
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
//var item = listView1.GetItemAt(e.X, e.Y);
buttonEdit_Click(null, null);
}
#endregion
}
}
Форма введення запису про абонентів:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Phonebook.Classes;
using System.Xml.Linq;
using System.IO;
using System.Drawing.Imaging;
namespace Phonebook
{
public partial class ItemForm: Form
{
public string ItemID = "";
bool NewItem = false;
bool EditItem = false;
public ItemForm(bool newItem, bool editItem)
{
InitializeComponent();
this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);
//////////////////////
this.NewItem = newItem;
this.EditItem = editItem;
if (NewItem)
this.Text = "Додати новий запис";
else if (EditItem)
this.Text = "Редагувати запис";
}
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
try
{
if (e.Row % 2 == 0)
{
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(new SolidBrush(Color.FromArgb(225, 225, 225)), r);
}
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
private void buttonSubmit_Click(object sender, EventArgs e)
{
try
{
errorProvider1.Clear();
#region add new item
if (NewItem)
{
if (textBoxName.Text.Trim() == "")
{
errorProvider1.SetError(textBoxName, "Будь-ласка, введіть імя");
return;
}
int maxID = 0;
try
{
maxID = (from q in Variables.xDocument.Descendants("Item")
where q.Attribute("UserID").Value == Variables.CurrentUserID
select (int)q.Attribute("ID")).Max();
}
catch { }
maxID++;
XElement newItem = new XElement("Item", new XAttribute("ID", maxID),
new XAttribute("UserID", Variables.CurrentUserID),
new XAttribute("Name", textBoxName.Text.Trim()),
new XAttribute("Mobile", textBoxMobile.Text.Trim()),
new XAttribute("Phone", textBoxPhone.Text.Trim()),
new XAttribute("Email", textBoxEMail.Text.Trim()),
new XAttribute("Address", textBoxAddress.Text.Trim()),
new XAttribute("RegDate", DateTime.Now.ToString()));
var ItemsElement = (from q in Variables.xDocument.Descendants("Items")
select q).First();
ItemsElement.Add(newItem);
}
#endregion
#region edit item
else if (EditItem)
{
if (textBoxName.Text.Trim() == "")
{
errorProvider1.SetError(textBoxName, "Будь-ласка, введіть імя");
return;
}
var theItem = (from q in Variables.xDocument.Descendants("Item")
where q.Attribute("ID").Value == this.ItemID
select q).First();
theItem.Attribute("Name").Value = textBoxName.Text.Trim();
theItem.Attribute("Mobile").Value = textBoxMobile.Text.Trim();
theItem.Attribute("Phone").Value = textBoxPhone.Text.Trim();
theItem.Attribute("Email").Value = textBoxEMail.Text.Trim();
theItem.Attribute("Address").Value = textBoxAddress.Text.Trim();
}
#endregion
TripleDES.EncryptToFile(Variables.xDocument.ToString(SaveOptions.DisableFormatting), Variables.DBFile, TripleDES.ByteKey, TripleDES.IV);
//Variables.xDocument.Save("debug.xml");
this.Close();
}
catch (Exception ex)
{
StackFrame file_info = new StackFrame(true);
Messages.error(ref file_info, ex.Message, this);
}
}
#region
Image ResizeImage(Image FullsizeImage, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
// Prevent using images internal thumbnail
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
if (OnlyResizeIfWider)
{
if (FullsizeImage.Width <= NewWidth)
{
NewWidth = FullsizeImage.Width;
}
}
int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
NewHeight = MaxHeight;
}
System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
// Clear handle to original file so that we can overwrite it if necessary
FullsizeImage.Dispose();
// Save resized picture
return NewImage;
}
string ImageToBase64String(Image image, ImageFormat format)
{
MemoryStream memory = new MemoryStream();
image.Save(memory, format);
string base64 = Convert.ToBase64String(memory.ToArray());
memory.Close();
return base64;
}
Image ImageFromBase64String(string base64)
{
MemoryStream memory = new MemoryStream(Convert.FromBase64String(base64));
Image result = Image.FromStream(memory);
memory.Close();
return result;
}
#endregion
}
}
Форма користувача:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Linq;
using Phonebook.Classes;
using System.Diagnostics;
using System.Net.Mail;
using System.Net;
namespace Phonebook
{
public partial class UserForm: Form
{
bool NewUser = false;
bool ChangeUser = false;
bool ChangeInfo = false;
pu