//InsertUser private void button11_Click(object sender, EventArgs e) { textBox1.Text = "User"; User user = new User(); user.Id = 2; user.UserId = "usertest"+System.DateTime.Now.ToString(); user.UserName = "******"; user.UserInfo = "��г����"; user.UserLevel = "һ���û�"; user.Remark = "ûʲô��д��"; MessageBox.Show(dba.InsertUser(user)); }
//У���Ƿ���ͬUserid���û� true-ͨ�����ԣ�û�����Ƶ�,false-û��ͨ�����ԣ������Ƶ� public bool CheckUser(User user) { command.CommandText = "SELECT * FROM User where UserId = '" + user.UserId + "'"; SQLiteDataAdapter da = new SQLiteDataAdapter(command); DataTable dt = new DataTable("User"); da.Fill(dt); if (dt.Rows.Count > 0) { return false; } else { return true; } }
//SelectUser private void button10_Click(object sender, EventArgs e) { textBox1.Text = "User"; User user = new User(); user.Id = 2; user.UserId = "usertest" + System.DateTime.Now.ToString(); user.UserName = "******"; user.UserInfo = "��г����"; user.UserLevel = "һ���û�"; user.Remark = "ûʲô��д��"; //MessageBox.Show(user.ToString()); MessageBox.Show(dba.SelectUser(user).Rows[0][0].ToString()); MessageBox.Show(dba.SelectUserToClass(user).ToString()); List<User> listuser = new List<User>(); listuser = dba.SelectUserAllToList(); for (int i = 0; i < listuser.Count; i++) { MessageBox.Show(listuser[i].ToString()); } }
//���û� public string UpdateUser(User user) { DataTable dt = new DataTable(); dt = SelectUser(user); if (dt.Rows.Count == 1) { dt.Rows[0][0] = user.Id; dt.Rows[0][1] = user.UserId; dt.Rows[0][2] = user.UserName; dt.Rows[0][3] = user.UserLevel; dt.Rows[0][4] = user.UserInfo; dt.Rows[0][5] = user.Remark; dt.Rows[0][6] = user.Password; } return UpdateTable(dt, "User"); }
//��ѯ��ij���û���Ϣ public User SelectUserToClass(User user) { command.CommandText = "SELECT * FROM User where Id = " + user.Id; SQLiteDataAdapter da = new SQLiteDataAdapter(command); DataTable dt = new DataTable("User"); da.Fill(dt); User returnvalue = new User(); if(dt.Rows.Count > 0) { returnvalue.Id = Convert.ToInt16(dt.Rows[0][0].ToString()); returnvalue.UserId = dt.Rows[0][1].ToString(); returnvalue.UserName = dt.Rows[0][2].ToString(); returnvalue.UserLevel = dt.Rows[0][3].ToString(); returnvalue.UserInfo = dt.Rows[0][4].ToString(); returnvalue.Remark = dt.Rows[0][5].ToString(); returnvalue.Password = dt.Rows[0][6].ToString(); } return returnvalue; }
//��ѯ�������û� public List<User> SelectUserAllToList() { List<User> listuser = new List<User>(); DataTable dt = new DataTable(); dt = ReadTableOrderByXXId("User", "UserName"); for (int i = 0; i < dt.Rows.Count; i++) { User user = new User(); user.Id = Convert.ToInt16(dt.Rows[i][0].ToString()); user.UserId = dt.Rows[i][1].ToString(); user.UserName = dt.Rows[i][2].ToString(); user.UserLevel = dt.Rows[i][3].ToString(); user.UserInfo = dt.Rows[i][4].ToString(); user.Remark = dt.Rows[i][5].ToString(); user.Password = dt.Rows[i][6].ToString(); listuser.Add(user); } return listuser; }
//��ѯ��ij���û���Ϣ public DataTable SelectUser(User user) { command.CommandText = "SELECT * FROM User where Id=" + user.Id; SQLiteDataAdapter da = new SQLiteDataAdapter(command); DataTable dt = new DataTable("User"); da.Fill(dt); return dt; }
//�����û� public string InsertUser(User user) { DataTable dt = new DataTable(); dt = CreateDataTable("User"); DataRow datarow; datarow = dt.NewRow(); datarow[0] = user.Id; datarow[1] = user.UserId.ToLower(); datarow[2] = user.UserName; datarow[3] = user.UserLevel; datarow[4] = user.UserInfo; datarow[5] = user.Remark; datarow[6] = user.Password; dt.Rows.Add(datarow); return UpdateTable(dt, "User"); }