//public void Xml_Carrier(string Name,string City,string Tel,string QQ) //{ // XmlElement Root = null, temp = null; // Root=Doc.CreateElement("Name"); // Root.InnerText=Name; // temp=Doc.CreateElement("City"); // temp.InnerText=City; // Root.AppendChild(temp); // temp=Doc.CreateElement("Tel"); // temp.InnerText=Tel; // Root.AppendChild(temp); // temp=Doc.CreateElement("QQ"); // temp.InnerText=QQ; // Root.AppendChild(temp); // Doc.AppendChild(Root); //} #region 搜索数据 private void Click_Search(object sender, RoutedEventArgs e) { string temp = this.Search_Name.Text; if (Doc != null) { if (this.Insert_Name.Text.Equals(string.Empty)) { System.Windows.MessageBox.Show("Empty Name Inserted!"); } else { XmlElement Search_Result = Doc.SelectSingleNode(NodeTree + "/" + temp) as XmlElement; if (Search_Result == null) { System.Windows.MessageBox.Show(temp + "未找到"); } else { Searched_Detail Search_Info = new Searched_Detail(Search_Result, this.Doc); Doc.Save(XmlPath); this.Contact_Book_View.ItemsSource = Doc.SelectSingleNode(NodeTree).ChildNodes; Contact_Book_View.UpdateLayout(); Search_Name.Text = "输入姓名"; } } } else { System.Windows.MessageBox.Show("No Contact Book Loaded!"); } }
private void Click_Search(object sender, RoutedEventArgs e) { //System.Windows.MessageBox.Show("Searching "+this.Search_Name.Text); if (this.Search_Name.Text.Trim().Equals(string.Empty)) { System.Windows.MessageBox.Show("Empty Name Inserted!"); } else { using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DataBaseConnectionString)) { try { SqlCommand cmd = new SqlCommand("SELECT Name,City,Tel,QQ,Belong FROM Contactors WHERE Belong='" + Sign_in.Get_Confidential_User_ID().Trim() + "'", con); SqlDataAdapter AutoSda = new SqlDataAdapter(); AutoSda.SelectCommand = cmd; SqlCommandBuilder ComBuild = new SqlCommandBuilder(AutoSda); con.Open(); DataTable dt = new DataTable(); AutoSda.Fill(dt); DataRow[] Rows_Selected = dt.Select("Name='" + this.Search_Name.Text.Trim() + "'"); if (Rows_Selected.Count() == 0) { System.Windows.MessageBox.Show(this.Search_Name.Text.Trim() + " not Found"); } else { Searched_Detail temp = new Searched_Detail(Rows_Selected[0]); dt.AcceptChanges(); AutoSda.Update(dt); Contact_Book_View.ItemsSource = dt.DefaultView; } Search_Name.Text = "输入名字"; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } finally { con.Close(); } } } }