大家好 我正在學習關於windows mobile上的編程。然後我用功能創建一個關於「管理聯繫人」的迷你程序:添加,編輯,刪除,搜索和按組排序。但我不知道如何完成功能:搜索和備份/恢復聯繫人!你可以幫我嗎?在Windows Mobile上幫助我C#代碼備份/恢復和搜索聯繫人?
說明有關搜索功能:我創建了一個文本框和列表框,當我按在文本框的任何字,聯繫人的名稱包含詞將顯示列表框! 你能幫我嗎?
這是我的演示,我轉換和示例移動窗戶的維修5.0
這是主要的形式,和圖像有關的主要形式,在這裏: http://3.bp.blogspot.com/-lMmKCF6-REQ/TcqwNk9kgdI/AAAAAAAAAB4/-Eis3miMHy0/s320/Main.JPG
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Telephony;
namespace ManagerContacts
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class ContactSelector : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private OutlookSession outlookSession;
private System.Windows.Forms.TextBox smsText;
//private System.Windows.Forms.Button btnCallWork;
private System.Windows.Forms.Button btnEdit;
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnSendSms;
private Button bntDel;
private TextBox textBox1;
private PictureBox pictureBox1;
private Button button2;
private Button bntBackUp;
private PictureBox pictureBox;
private Contact contactToSelect;
//
// Constructor
//
public ContactSelector()
{
this.outlookSession = new OutlookSession();
this.InitializeComponent();
this.InitializeListBox();
}
/// <summary>
/// This function displays a dialog that lets the user pick a contact from a List or
/// create a new contact.
/// </summary>
/// <returns>The function returns the Contact chosen or a new Contact object if the user pressed "New" on the dialog.</returns>
public Contact Select()
{
this.ShowDialog();
return this.contactToSelect;
}
// Clean up any resources being used.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ContactSelector));
this.btnEdit = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.btnNew = new System.Windows.Forms.Button();
this.btnSendSms = new System.Windows.Forms.Button();
this.smsText = new System.Windows.Forms.TextBox();
this.bntDel = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button2 = new System.Windows.Forms.Button();
this.bntBackUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// btnEdit
//
this.btnEdit.Location = new System.Drawing.Point(152, 70);
this.btnEdit.Name = "btnEdit";
this.btnEdit.Size = new System.Drawing.Size(79, 24);
this.btnEdit.TabIndex = 7;
this.btnEdit.Text = "Edit Contact";
this.btnEdit.Click += new System.EventHandler(this.EditButton_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(10, 32);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(136, 198);
this.listBox1.TabIndex = 6;
//
// btnNew
//
this.btnNew.Location = new System.Drawing.Point(152, 40);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(79, 24);
this.btnNew.TabIndex = 5;
this.btnNew.Text = "Add Contact";
this.btnNew.Click += new System.EventHandler(this.NewButton_Click);
//
// btnSendSms
//
this.btnSendSms.Location = new System.Drawing.Point(201, 240);
this.btnSendSms.Name = "btnSendSms";
this.btnSendSms.Size = new System.Drawing.Size(36, 24);
this.btnSendSms.TabIndex = 4;
this.btnSendSms.Text = "SMS";
this.btnSendSms.Click += new System.EventHandler(this.SendSmsButton_Click);
//
// smsText
//
this.smsText.Location = new System.Drawing.Point(10, 240);
this.smsText.Name = "smsText";
this.smsText.Size = new System.Drawing.Size(188, 21);
this.smsText.TabIndex = 3;
this.smsText.Text = "Write SMS Text here.";
//
// bntDel
//
this.bntDel.Location = new System.Drawing.Point(152, 100);
this.bntDel.Name = "bntDel";
this.bntDel.Size = new System.Drawing.Size(79, 24);
this.bntDel.TabIndex = 8;
this.bntDel.Text = "Del Contact";
this.bntDel.Click += new System.EventHandler(this.bntDel_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(43, 5);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(188, 21);
this.textBox1.TabIndex = 9;
this.textBox1.Text = "Search";
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(10, 5);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(24, 24);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
//
// button2
//
this.button2.Location = new System.Drawing.Point(158, 267);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(79, 24);
this.button2.TabIndex = 13;
this.button2.Text = "Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// bntBackUp
//
this.bntBackUp.Location = new System.Drawing.Point(10, 266);
this.bntBackUp.Name = "bntBackUp";
this.bntBackUp.Size = new System.Drawing.Size(142, 27);
this.bntBackUp.TabIndex = 15;
this.bntBackUp.Text = "BackUp And Recovery";
this.bntBackUp.Click += new System.EventHandler(this.bntBackUp_Click);
//
// pictureBox
//
this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));
this.pictureBox.Location = new System.Drawing.Point(152, 130);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(85, 83);
this.pictureBox.Click += new System.EventHandler(this.pictureBox_Click);
//
// ContactSelector
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.ClientSize = new System.Drawing.Size(240, 296);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.bntBackUp);
this.Controls.Add(this.button2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.bntDel);
this.Controls.Add(this.smsText);
this.Controls.Add(this.btnSendSms);
this.Controls.Add(this.btnNew);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.btnEdit);
this.KeyPreview = true;
this.Name = "ContactSelector";
this.Text = "Contact Selector";
this.ResumeLayout(false);
}
private void InitializeListBox()
{
this.listBox1.DataSource = null;
this.listBox1.DataSource = this.outlookSession.Contacts.Items;
this.listBox1.DisplayMember = "FileAs";
this.listBox1.ValueMember = "ItemId";
}
#endregion
static void Main()
{
Application.Run(new ContactSelector());
}
private void NewButton_Click(object sender, System.EventArgs e)
{
// Add contact to the contacts folder.
// Just do an update once the information has been entered.
contactToSelect = new Contact();
this.outlookSession.Contacts.Items.Add(contactToSelect);
// Edit the newly created contact.
ContactEditor contactDialog = new ContactEditor();
contactDialog.Edit(ref contactToSelect);
this.InitializeListBox();
}
private void EditButton_Click(object sender, System.EventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
}
ContactEditor contactDialog = new ContactEditor();
contactDialog.Edit(ref contactToSelect);
}
private void SendSmsButton_Click(object sender, System.EventArgs e)
{
try
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
if (outlookSession.SmsAccount == null)
throw new ArgumentException("The account is not initialized");
MessageBox.Show("Transport:"+outlookSession.SmsAccount.Name);
SmsMessage s = new SmsMessage(contactToSelect.MobileTelephoneNumber, this.smsText.Text);
s.Body = this.smsText.Text; //Create some input.
s.Send();
}
catch (NullReferenceException except)
{
MessageBox.Show(except.ToString());
}
}
private void bntDel_Click(object sender, EventArgs e)
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
contactToSelect.Delete();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void bntBackUp_Click(object sender, EventArgs e)
{
MainForm BR = new MainForm();
BR.Show();
}
private void pictureBox_Click(object sender, EventArgs e)
{
/*
* contactToSelect = (Contact)this.listBox1.SelectedItem;
Phone p = new Phone();
p.Talk(contactToSelect.MobileTelephoneNumber);
*/
}
}
}
非常感謝您!
你應該粘貼代碼的相關部分。如果你從上面的位置刪除文件,這個問題變得毫無意義。把你的問題集中在你的問題的一個方面......說,*「如何將記錄添加到Windows Mobile數據庫?」*提供解釋你一直在嘗試的代碼片段。我個人不會下載和解壓縮一個.rar文件。我會看看你粘貼到你的問題的代碼。 – IAbstract 2011-05-10 20:26:18