public void Init(staffListItem item) { this.ID = item.ID; this.manaID = item.manaID; this.Name = item.Name; this.Phone = item.Phone; this.Addr = item.Addr; this.WorkDate = item.WorkDate; }
public staffListItem(staffListItem item) { Init(item); }
private void BtnClickQue(object sender, RoutedEventArgs e) { data.Clear(); data.Add(colHead); string sqlStr = "select * from staff;"; MySqlCommand cmd = new MySqlCommand(sqlStr, con); MySqlDataReader reader = null; try { //MySqlDataReader reader = cmd.ExecuteReader(); staffListItem item = new staffListItem(); reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader.IsDBNull(0)) { item.ID = "NULL"; } else { item.ID = reader.GetString("staffID"); } if (reader.IsDBNull(1)) { item.manaID = "NULL"; } else { item.manaID = reader.GetString("dep_staffID"); } if (reader.IsDBNull(2)) { item.Name = "NULL"; } else { item.Name = reader.GetString("staffName"); } if (reader.IsDBNull(3)) { item.Phone = "NULL"; } else { item.Phone = reader.GetString("staffPhone"); } if (reader.IsDBNull(4)) { item.Addr = "NULL"; } else { item.Addr = reader.GetString("staffAddr"); } if (reader.IsDBNull(5)) { item.WorkDate = "NULL"; } else { item.WorkDate = reader.GetDateTime("startWorkDate").ToLongDateString(); } data.Add(new staffListItem(item)); } TxtAlert.Text = "query success!"; } catch (Exception ex) { TxtAlert.Text = "Fail to execute sql command\nError message: "; TxtAlert.Text += ex.Message; } finally { if (reader != null) { reader.Close(); } } }