public object Clone(caddressBook addressbook) { addressbook.id = id; addressbook.name = name; addressbook.contact = contact; addressbook.address = address; addressbook.city = city; addressbook.comment = comment; return(addressbook); }
private void newaddressBook(string str) { caddressBook temp = Deserialize <caddressBook>(str); string strsql; strsql = $"{usesql}{line}UPDATE CONTACTS{line}SET NAME='{temp.name}',CONTACT='{temp.contact}',CADDRESS='{temp.address}',CITY='{temp.city}',COMMENT='{temp.comment}'{line}WHERE ID IN (SELECT CONTACTSID FROM addressBook WHERE ID='{temp.id}');"; write(strsql); reminder = "修改通讯录"; }
//public void add<T>(T obj) //{ // string temp = typeof(T).ToString(); // int i = temp.LastIndexOf('.'); // reminder = temp.Substring(i+1); //} public ObservableCollection <caddressBook> newaddressBook() { const string addressBookname = "vaddressbook"; string sqlAddressBook = $"{usesql}{line}SELECT * FROM {addressBookname};"; ObservableCollection <caddressBook> addressBook = new ObservableCollection <caddressBook>(); const string id = "id"; const string name = "name"; const string contact = "contact"; const string caddress = "caddress"; const string city = "city"; const string comment = "comment"; using (SqlConnection sql = new SqlConnection(connect)) { sql.Open(); using (SqlCommand cmd = new SqlCommand(sqlAddressBook, sql)) { using (SqlDataReader read = cmd.ExecuteReader()) { //判断当前的reader是否读取到了数据 if (!read.HasRows) { return(addressBook); } int idindex = read.GetOrdinal(id); int nameindex = read.GetOrdinal(name); int contactindex = read.GetOrdinal(contact); int caddressindex = read.GetOrdinal(caddress); int cityindex = read.GetOrdinal(city); int commentindex = read.GetOrdinal(comment); while (read.Read()) { caddressBook temp = new caddressBook { id = read.GetInt32(idindex).ToString(), name = read.GetString(nameindex).Trim(), contact = read.GetString(contactindex).Trim(), address = read.GetString(caddressindex).Trim(), city = read.GetString(cityindex).Trim(), comment = read.GetString(commentindex).Trim() }; addressBook.Add(temp); } } } } return(addressBook); }
/// <summary> /// 添加通讯录 /// </summary> public void addaddressBook(caddressBook addressbook) { //添加加上一个在末尾 string strsql; const string addressBook = "addressbook"; const string contacts = "CONTACTS"; string id; if (addressbook == null) { reminder = "添加通讯录,添加的通讯录空"; return; } strsql = $"{usesql}{line}insert into {contacts}(name,contact,caddress,city,comment){line}values('{addressbook.name}','{addressbook.contact}','{addressbook.address}','{addressbook.city}','{addressbook.comment}') SELECT @@IDENTITY AS Id;"; id = write(strsql); strsql = $"insert into {addressBook}(CONTACTSID) values( '{id}');"; write(strsql); }
// override object.Equals public override bool Equals(object obj) { // // See the full list of guidelines at // http://go.microsoft.com/fwlink/?LinkID=85237 // and also the guidance for operator== at // http://go.microsoft.com/fwlink/?LinkId=85238 // if (obj == null || GetType() != obj.GetType()) { return(false); } caddressBook addressbook = obj as caddressBook; if (addressbook.id != id) { return(false); } if (addressbook.name != name) { return(false); } if (addressbook.contact != contact) { return(false); } if (addressbook.address != address) { return(false); } if (addressbook.city != city) { return(false); } if (addressbook.comment != comment) { return(false); } // TODO: write your implementation of Equals() here return(true); }
private List <caddressBook> lajiaddressBook() { List <caddressBook> addressBook = new List <caddressBook>(); List <string> chinacity = new List <string>(); chinacity.AddRange(sql.城市.Split(new char[2] { '\r', '\n' })); for (int i = 0; i < chinacity.Count; i++) { if (string.IsNullOrEmpty(chinacity[i])) { chinacity.RemoveAt(i); i--; } else { chinacity[i] = chinacity[i].Trim(); } } int n = 100; caddressBook temp; for (int i = 0; i < n; i++) { temp = new caddressBook() { id = i.ToString(), name = ranstr(3), contact = ran.Next().ToString(), address = chinacity[ran.Next(chinacity.Count)], city = chinacity[ran.Next(chinacity.Count)], comment = "随机的名,作为测试" }; addressBook.Add(temp); } return(addressBook); }
/// <summary> /// 删除通讯录 /// </summary> /// <param name="id">要删除id</param> public void deleteaddressBook(caddressBook addressbook) { string strsql; //string id; const string addressBook = "addressbook"; //const string contacts = "CONTACTS"; //strsql = $"{usesql}{line}SELECT CONTACTSID{line}FROM {addressBook}{line}WHERE ID='{addressbook.id}';"; //id = write(strsql); //DELETE FROM ADDRESSBOOK //WHERE addressBook.ID = '213'; strsql = $"{usesql}{line}DELETE FROM {addressBook}{line}WHERE {addressBook}.ID = '{addressbook.id}';"; write(strsql); //DELETE FROM CONTACTS //WHERE CONTACTS.ID = '218'; //strsql = $"{usesql}{line}DELETE FROM {contacts}{line}WHERE {contacts}.ID = '{id}';"; //write(strsql); reminder = "删除" + addressbook.id + " " + addressbook.name; }