//获得数据库数据 private void GetUserData() { MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select distinct User_Dept from tb_user"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { UserModel um = new UserModel(); um.Department = dr["User_Dept"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
//获得数据库数据 private void GetUserData() { MySQLConnection DBConn = null; string connectStr = new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString; //System.Windows.Forms.MessageBox.Show(connectStr); DBConn = new MySQLConnection(connectStr); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select User_Id,User_Name,User_Dept,User_Job,User_Mail,User_Cell from tb_user"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { UserModel um = new UserModel(); um.ID = dr["User_Id"].ToString(); um.Name = dr["User_Name"].ToString(); um.Department = dr["User_Dept"].ToString(); um.Email = dr["User_Mail"].ToString(); um.PersonPosition = dr["User_Job"].ToString(); um.Telephone = dr["User_Cell"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
//打开操作 private void Confirm_Click(object sender, RoutedEventArgs e) { //得到新的添加项 selected = listView1.SelectedItem as UserModel; if (selected == null) { return; } this.Visibility = System.Windows.Visibility.Hidden; }