Exemplo n.º 1
0
        private void btnSaveContact_Click(object sender, EventArgs e)
        {
            XmlDocument doc = XMLOperation.GetDocument();
            //string tempQqNumber = this.txtQqNumber.Text.Trim();
            // string searchString = "/contacts/contact[@contactQqNumber='" + tempQqNumber + "']";
            XmlNode     node     = doc.SelectSingleNode("/contacts/contact[contactQqNumber=" + QqNumber + "]");
            XmlNodeList nodeList = node.ChildNodes;

            nodeList[2].InnerText  = this.txtAcademyName.Text;
            nodeList[4].InnerText  = this.txtClass.Text;
            nodeList[0].InnerText  = this.txtContactName.Text;
            nodeList[8].InnerText  = this.txtEmail.Text;
            nodeList[3].InnerText  = this.txtGrade.Text;
            nodeList[9].InnerText  = this.txtHomeAddress.Text;
            nodeList[5].InnerText  = this.txtMobilePhoneNumber.Text;
            nodeList[7].InnerText  = this.txtQqNumber.Text;
            nodeList[1].InnerText  = this.txtSchoolName.Text;
            nodeList[6].InnerText  = this.txtTelephoneNumber.Text;
            nodeList[10].InnerText = this.richTxtBlessingWords.Text;
            // if (strPicturePath!= null)
            {
                //   FileStream stream = new FileStream(strPicturePath, FileMode.Open, FileAccess.Read);

                /*  long picLength = stream.Length;
                 * byte[] buffer = new byte[(int)picLength];
                 * stream.Read(buffer, 0, (int)picLength);
                 * nodeList[11].InnerText = Convert.ToBase64String(buffer);*/
            }
            XMLOperation.SaveDocument(doc);
            MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK);
            this.Close();
        }
Exemplo n.º 2
0
        private void ViewContactForm_Load(object sender, EventArgs e)
        {
            XmlDocument doc      = XMLOperation.GetDocument();
            XmlNode     node     = doc.SelectSingleNode("/contacts/contact[contactQqNumber=" + QqNumber + "]");
            XmlNodeList nodeList = node.ChildNodes;

            this.txtAcademyName.Text       = nodeList[2].InnerText;
            this.txtClass.Text             = nodeList[4].InnerText;
            this.txtContactName.Text       = nodeList[0].InnerText;
            this.txtEmail.Text             = nodeList[8].InnerText;
            this.txtGrade.Text             = nodeList[3].InnerText;
            this.txtHomeAddress.Text       = nodeList[9].InnerText;
            this.txtMobilePhoneNumber.Text = nodeList[5].InnerText;
            this.txtQqNumber.Text          = nodeList[7].InnerText;
            this.txtSchoolName.Text        = nodeList[1].InnerText;
            this.txtTelephoneNumber.Text   = nodeList[6].InnerText;
            this.richTxtBlessingWords.Text = nodeList[10].InnerText;
        }
Exemplo n.º 3
0
 private void mItemDeleteContactToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("是否要删除联系人", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         XmlDocument doc          = XMLOperation.GetDocument();
         string      tempQqNumber = this.listViewAllContactsInfo.SelectedItems[0].SubItems[4].Text;
         string      searchString = "/contacts/contact[contactQqNumber='" + tempQqNumber + "']";
         XmlNode     node         = doc.SelectSingleNode(searchString);
         node.ParentNode.RemoveChild(node);
         XMLOperation.SaveDocument(doc);
         this.listViewAllContactsInfo.Clear();
         this.Refresh();
     }
     else
     {
         this.listViewAllContactsInfo.Focus();
     }
 }
Exemplo n.º 4
0
        public override void Refresh()
        {
            this.listViewAllContactsInfo.Columns.Add("Name", "名字", 60);
            this.listViewAllContactsInfo.Columns.Add("Class", "班级", 62);
            this.listViewAllContactsInfo.Columns.Add("TeleNumber", "电话号码", 115);
            this.listViewAllContactsInfo.Columns.Add("MobileNumber", "手机号码", 111);
            this.listViewAllContactsInfo.Columns.Add("QqNumber", "QQ号码", 85);
            this.listViewAllContactsInfo.Columns.Add("Email", "Email", 142);
            this.listViewAllContactsInfo.Columns.Add("Address", "联系地址", 229);
            XmlDocument doc      = XMLOperation.GetDocument();
            XmlNodeList nodeList = doc.SelectNodes("/contacts/contact");

            foreach (XmlNode node in nodeList)
            {
                XmlNodeList  childNodeList = node.ChildNodes;
                ListViewItem lvItem        = new ListViewItem(new string[]
                                                              { childNodeList[0].InnerText, childNodeList[4].InnerText,
                                                         childNodeList[6].InnerText, childNodeList[5].InnerText,
                                                         childNodeList[7].InnerText, childNodeList[8].InnerText,
                                                         childNodeList[9].InnerText });
                this.listViewAllContactsInfo.Items.Add(lvItem);
            }
            base.Refresh();
        }
Exemplo n.º 5
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string      searchMobile = "/contacts/contact[contains(contactMobileNumber,'" + this.txtSearchInfo.Text.Trim() + "')]";
            string      searchName   = "/contacts/contact[contains(contactName,'" + this.txtSearchInfo.Text.Trim() + "')]";
            string      searchQQ     = "/contacts/contact[contains(contactQqNumber,'" + this.txtSearchInfo.Text.Trim() + "')]";
            XmlDocument doc          = XMLOperation.GetDocument();

            if (this.radioButtonMobilephoneNumber.Checked == true)
            {
                if (this.txtSearchInfo.Text.IndexOf(' ', 0) == -1)
                {
                    XmlNode      node   = doc.SelectSingleNode(searchMobile);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
                else
                {
                    string tempCommonMatchName = this.txtSearchInfo.Text
                                                 .Replace(" ", "").Trim();
                    searchMobile = "/contacts/contact[contains(contactMobileNumber,'" + tempCommonMatchName + "')]";
                    XmlNode      node   = doc.SelectSingleNode(searchMobile);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
            }
            else if (this.radioButtonName.Checked == true)
            {
                if (this.txtSearchInfo.Text.IndexOf(' ', 0) == -1)
                {
                    XmlNode      node   = doc.SelectSingleNode(searchName);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
                else
                {
                    string tempCommonMatchName = this.txtSearchInfo.Text
                                                 .Replace(" ", "").Trim();
                    searchName = "/contacts/contact[contains(contactName,'" + tempCommonMatchName + "')]";
                    XmlNode      node   = doc.SelectSingleNode(searchName);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
            }
            else if (this.radioButtonQqNumber.Checked == true)
            {
                if (this.txtSearchInfo.Text.IndexOf(' ', 0) == -1)
                {
                    XmlNode      node   = doc.SelectSingleNode(searchQQ);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
                else
                {
                    string tempCommonMatchName = this.txtSearchInfo.Text.Replace(" ", "").Trim();
                    searchQQ = "/contacts/contact[contains(contactQqNumber,'" + tempCommonMatchName + "')]";
                    XmlNode      node   = doc.SelectSingleNode(searchQQ);
                    ResultsFound result = new ResultsFound(node);
                    result.Show();
                }
            }
            else
            {
                MessageBox.Show("请选择一个搜索匹配条件再进行查找", "提示");
            }
        }
Exemplo n.º 6
0
        public static int SaveContact(ContactForm contactForm)
        {
            XmlDocument    doc       = XMLOperation.GetDocument();
            XPathNavigator navigator = doc.CreateNavigator();
            XmlNode        root      = doc.SelectSingleNode("contacts");
            XmlElement     contactElement;
            XmlElement     childElement;
            string         searchExpression = "/contacts/contact[contactName='"
                                              + contactForm.txtContactName.Text + "']";

            try
            {
                if (navigator.SelectSingleNode(searchExpression) == null)
                {
                    contactElement         = doc.CreateElement("contact");
                    childElement           = doc.CreateElement("contactName");
                    childElement.InnerText = contactForm.txtContactName.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactSchoolName");
                    childElement.InnerText = contactForm.txtSchoolName.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactAcademyName");
                    childElement.InnerText = contactForm.txtAcademyName.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactGrade");
                    childElement.InnerText = contactForm.txtGrade.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactClass");
                    childElement.InnerText = contactForm.txtClass.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactMobileNumber");
                    childElement.InnerText = contactForm.txtMobilePhoneNumber.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactTelephoneNumber");
                    childElement.InnerText = contactForm.txtTelephoneNumber.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactQqNumber");
                    childElement.InnerText = contactForm.txtQqNumber.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactEmail");
                    childElement.InnerText = contactForm.txtEmail.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactAddress");
                    childElement.InnerText = contactForm.txtHomeAddress.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    childElement           = doc.CreateElement("contactBlessingWords");
                    childElement.InnerText = contactForm.richTxtBlessingWords.Text;
                    contactElement.AppendChild((XmlNode)childElement);
                    //  if (contactForm.strPicturePath != null)
                    {
                        // FileStream stream = new FileStream(contactForm.strPicturePath,
                        //     FileMode.Open, FileAccess.Read);

                        /* long picLength = stream.Length;
                         * byte[] buffer = new byte[(int)picLength];
                         * stream.Read(buffer, 0, (int)picLength);
                         * childElement = doc.CreateElement("contactImage");
                         * childElement.InnerText = Convert.ToBase64String(buffer);
                         * contactElement.AppendChild((XmlNode)childElement);*/
                    }
                    root.AppendChild((XmlNode)contactElement);
                    XMLOperation.SaveDocument(doc);
                    return(1);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (System.Exception e)
            {
                MessageBox.Show("联系人已存在!" + e.ToString());
                return(0);
            }
        }