private bool user_checkOut(string loginID, string password) { bool login = false; SqlConnection sqlconnection = new SqlConnection(conStr); string comStr = string.Format("select Student_REGISTRED,Student_PASSWORD, Student_NAME from dboStudent where Student_IID = \'{0}\'", loginID); dataSet = new DataSet(); dataSet.Clear(); dataSet = SqlCommondClass.GetDataSet(comStr, "dboStudent", sqlconnection); if (dataSet.Tables[0].Rows.Count == 0) { login = false; return(login); } if (dataSet.Tables[0].Rows[0][0].ToString().Trim().Equals("True")) { if (dataSet.Tables[0].Rows[0][1].ToString().Trim().Equals(password.Trim())) { this.loginName = dataSet.Tables[0].Rows[0][2].ToString().Trim(); login = true; return(login); } } else { MessageBox.Show("您还没有注册登账户!"); } return(login); }
private void textBoxId_TextChanged(object sender, EventArgs e) { string registerId = this.textBoxId.Text.Trim(); string registerName = this.textBoxName.Text.Trim(); string comStr = string.Format("select Student_SEX, Student_BIRTHDAY, Student_DEPT, Student_MAJOR from dboStudent where Student_IID = \'{0}\' and Student_NAME = \'{1}\'", registerId, registerName); SqlConnection sqlconnection = new SqlConnection(conStr); try { sqlconnection.Open(); DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "dboStudent", sqlconnection); if (dataSet.Tables[0].Rows.Count >= 1) { this.textBoxSex.Text = dataSet.Tables[0].Rows[0]["Student_SEX"].ToString().Trim(); this.textBoxBirth.Text = dataSet.Tables[0].Rows[0]["Student_BIRTHDAY"].ToString().Substring(0, dataSet.Tables[0].Rows[0]["Student_BIRTHDAY"].ToString().IndexOf(" ")); this.textBoxDepart.Text = dataSet.Tables[0].Rows[0]["Student_DEPT"].ToString().Trim(); this.textBoxMajor.Text = dataSet.Tables[0].Rows[0]["Student_MAJOR"].ToString().Trim(); } } catch (Exception) { } finally { sqlconnection.Close(); } }
private bool admin_checkOut(string loginID, string password) { bool login = false; SqlConnection sqlconnection = new SqlConnection(conStr); string comStr = string.Format("select Sys_NAME, Sys_PASSWORD from dboSys where Sys_IID = \'{0}\'", loginID); dataSet = new DataSet(); dataSet.Clear(); dataSet = SqlCommondClass.GetDataSet(comStr, "dboSys", sqlconnection); if (dataSet.Tables[0].Rows.Count == 0) { login = false; return(login); } if (dataSet.Tables[0].Rows[0][1].ToString().Trim().Equals(password.Trim())) { this.sysLogin = true; this.loginName = dataSet.Tables[0].Rows[0][0].ToString().Trim(); login = true; return(login); } return(login); }
private void btnSearch_Click(object sender, EventArgs e) { string textStr = this.textBox1.Text.Trim(); string searchStr = "'"; if (textStr.Equals("")) { return; } for (int Strlen = 0; Strlen < textStr.Length; Strlen++) { searchStr += "%" + textStr.ElementAt(Strlen); } searchStr += "%'"; SqlConnection sqlconnection = new SqlConnection(conStr); string comStr; comStr = "select Book_NAME 图书名,Book_MAINAUTHOR 主编,Book_SEARCHID 检索号,Book_CLASS 图书类别,Book_PUBLISHER 出版社,Book_INTRODUCTION 图书简介,Book_REMAIN 剩余量" + " from dboBook where Book_MAINAUTHOR Like " + searchStr + " OR Book_AUTHOR1 Like " + searchStr + " OR Book_AUTHOR2 Like " + searchStr + " OR Book_AUTHOR3 Like " + searchStr + " OR Book_SEARCHID Like " + searchStr + " OR Book_CLASS Like " + searchStr + " OR Book_PUBLISHER Like " + searchStr + " OR Book_INTRODUCTION Like " + searchStr; DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "dboBook", sqlconnection); this.dataGridView1.DataSource = dataSet.Tables[0]; }
private void textBoxISBN_TextChanged(object sender, EventArgs e) { string ISBN = this.textBoxISBN.Text.Trim(); string comStr = string.Format("select Book_NAME, Book_MAINAUTHOR, Book_AUTHOR1,Book_AUTHOR2,Book_AUTHOR2,Book_SEARCHID, Book_CLASS," + "Book_PRICE,Book_PUBLISHER,Book_TOTAL,Book_REMAIN,Book_INTRODUCTION from dboBook " + "where Book_ISBN = \'{0}\'", ISBN); SqlConnection sqlconnection = new SqlConnection(conStr); try { sqlconnection.Open(); DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "result", sqlconnection); if (dataSet.Tables[0].Rows.Count >= 1) { existBook = true; this.textBoxBookName.Text = dataSet.Tables[0].Rows[0]["Book_NAME"].ToString(); this.textBoxMainAuthor.Text = dataSet.Tables[0].Rows[0]["Book_MAINAUTHOR"].ToString(); this.textBoxOtherAuthor.Text = dataSet.Tables[0].Rows[0]["Book_AUTHOR1"].ToString() + " " + dataSet.Tables[0].Rows[0]["Book_AUTHOR2"].ToString() + " " + dataSet.Tables[0].Rows[0]["Book_AUTHOR2"].ToString(); this.textBoxSearchId.Text = dataSet.Tables[0].Rows[0]["Book_SEARCHID"].ToString(); this.textBoxBookClass.Text = dataSet.Tables[0].Rows[0]["Book_CLASS"].ToString(); this.textBoxPrice.Text = dataSet.Tables[0].Rows[0]["Book_PRICE"].ToString(); this.textBoxPublisher.Text = dataSet.Tables[0].Rows[0]["Book_PUBLISHER"].ToString(); this.textBoxTotal.Text = dataSet.Tables[0].Rows[0]["Book_TOTAL"].ToString(); this.textBoxRemain.Text = dataSet.Tables[0].Rows[0]["Book_REMAIN"].ToString(); this.textBoxBriefInfo.Text = dataSet.Tables[0].Rows[0]["Book_INTRODUCTION"].ToString(); } else { existBook = false; this.textBoxBookName.Text = ""; this.textBoxMainAuthor.Text = ""; this.textBoxOtherAuthor.Text = ""; this.textBoxSearchId.Text = ""; this.textBoxBookClass.Text = ""; this.textBoxPrice.Text = ""; this.textBoxPublisher.Text = ""; this.textBoxTotal.Text = ""; this.textBoxRemain.Text = ""; this.textBoxBriefInfo.Text = ""; } } catch (Exception) { MessageBox.Show("数据库操作失败!", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconnection.Close(); } }
private void SuperbtnSearch_Click(object sender, EventArgs e) { string comStr = "select Book_NAME 图书名,Book_MAINAUTHOR 主编,Book_SEARCHID 检索号,Book_CLASS 图书类别,Book_PUBLISHER 出版社,Book_INTRODUCTION 图书简介,Book_REMAIN 剩余量" + " from dboBook where "; string bookName = this.textBookName.Text.Trim(); string authorName = this.textAuthorName.Text.Trim(); string subjectName = this.textSubjectName.Text.Trim(); string publishName = this.textPublishName.Text.Trim(); string isbnName = this.textISBNName.Text.Trim(); if (bookName.Length > 1) { comStr += " Book_NAME = '" + bookName + "'"; } if (authorName.Length > 1) { comStr += "and Book_MAINAUTHOR = '" + authorName + "'"; } if (subjectName.Length > 1) { comStr += "and Book_CLASS = '" + subjectName + "'"; } if (publishName.Length > 1) { comStr += "and Book_PUBLISHER = '" + publishName + "'"; } if (isbnName.Length > 1) { comStr += "and Book_ISBN = '" + isbnName + "'"; } SqlConnection sqlconnection = new SqlConnection(conStr); dataSet.Clear(); dataSet = SqlCommondClass.GetDataSet(comStr, "dboBook", sqlconnection); if (dataSet.Tables[0].Rows.Count < 20) { for (int i = dataSet.Tables[0].Rows.Count; i < 20; i++) { dataSet.Tables[0].Rows.Add(); } } this.dataGridView1.DataSource = dataSet.Tables[0]; }
public void getSystemInfo(string loginID) { if (loginID.Equals("")) { return; } SqlConnection sqlconnection = new SqlConnection(conStr); string comStr; comStr = "select Sys_NAME, Sys_SEX, Sys_BIRTHDAY from dboSys where Sys_IID = " + loginID; DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "dboStudent", sqlconnection); name = dataSet.Tables[0].Rows[0]["Sys_NAME"].ToString().Trim(); sex = dataSet.Tables[0].Rows[0]["Sys_SEX"].ToString().Trim(); ID = loginID; birthday = dataSet.Tables[0].Rows[0]["Sys_BIRTHDAY"].ToString().Trim(); birthday = birthday.Substring(0, 8); userClassification = "管理员"; depart = ""; major = ""; }
public void getUserInfo(string loginID) { if (loginID.Equals("")) { return; } SqlConnection sqlconnection = new SqlConnection(conStr); string comStr; comStr = "select Student_NAME, Student_SEX, Student_BIRTHDAY, Student_TYPE,Student_DEPT, Student_MAJOR from dboStudent where Student_IID = " + loginID; DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "dboStudent", sqlconnection); name = dataSet.Tables[0].Rows[0][0].ToString().Trim(); sex = dataSet.Tables[0].Rows[0][1].ToString().Trim(); ID = loginID; birthday = dataSet.Tables[0].Rows[0][2].ToString().Trim(); birthday = birthday.Substring(0, 10); userClassification = dataSet.Tables[0].Rows[0][3].ToString().Trim(); depart = dataSet.Tables[0].Rows[0][4].ToString().Trim(); major = dataSet.Tables[0].Rows[0][5].ToString().Trim(); }
private void search(searchType searchtype) { SqlConnection sqlconnection = new SqlConnection(conStr); switch (searchtype) { case searchType.searchHistory: { try { sqlconnection.Open(); string comStr = string.Format("select Book_ISBN 图书ISBN,Book_NAME 图书名,Book_MAINAUTHOR 主编, Book_SEARCHID 检索号,Book_CLASS 图书类别,Book_PUBLISHER 出版社,Book_INTRODUCTION 图书简介,Book_REMAIN 剩余量" + " from dboBook,dboSearchRecord" + " where dboBook.Book_ISBN=dboSearchRecord.SearchRecord_Book_ISBN and dboSearchRecord.SearchRecord_user_IID = \'{0}\'" + " order by (dboSearchRecord.SearchRecord_COUNT)", loginID); DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "result", sqlconnection); MostSearchFm.dataGridView1.DataSource = dataSet.Tables[0]; } catch (System.Exception) { } finally { sqlconnection.Close(); } break; } case searchType.borrowHistory: { try { sqlconnection.Open(); string comStr = string.Format("select Book_NAME 图书名,Borrow_BORROW_TIME 借书日期,Borrow_RETURN_TIME 还书日期, Book_MAINAUTHOR 主编, Book_SEARCHID 检索号,Book_CLASS 图书类别,Book_PUBLISHER 出版社,Book_INTRODUCTION 图书简介,Book_REMAIN 剩余量" + " from dboBook,dboBorrow" + " where dboBook.Book_ISBN = dboBorrow.Borrow_Book_ISBN and dboBorrow.Borrow_user_IID = \'{0}\' and dboBorrow.Borrow_BORROW_STATE = 1" + " order by (dboBorrow.Borrow_BORROW_TIME)", loginID); DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "result", sqlconnection); HistotySearchFm.dataGridView1.DataSource = dataSet.Tables[0]; } catch (System.Exception) { } finally { sqlconnection.Close(); } break; } case searchType.borrowNow: { try { string nowTime = DateTime.Now.Date.ToString().Substring(0, 10); sqlconnection.Open(); string comStr = string.Format("select Book_NAME 图书名, DateDiff(day, Borrow_BORROW_TIME, '" + nowTime + "') AS 距还书日期_天, Book_MAINAUTHOR 主编,Book_SEARCHID 检索号,Book_CLASS 图书类别,Book_PUBLISHER 出版社,Book_INTRODUCTION 图书简介" + " from dboBook,dboBorrow" + " where dboBook.Book_ISBN=dboBorrow.Borrow_Book_ISBN and dboBorrow.Borrow_user_IID = \'{0}\' and dboBorrow.Borrow_BORROW_STATE=0" + " order by DateDiff(day, Borrow_BORROW_TIME, Borrow_RETURN_TIME) asc", loginID); DataSet dataSet = SqlCommondClass.GetDataSet(comStr, "result", sqlconnection); BorrowingSearchFm.dataGridView1.DataSource = dataSet.Tables[0]; } catch (System.Exception) { MessageBox.Show("error"); } finally { sqlconnection.Close(); } break; } } }
private void btnRegist_Click(object sender, EventArgs e) { bool finished = true; string adminID = this.textBoxID.Text.Trim(); string adminName = this.textBoxName.Text.Trim(); string adminSex = this.textBoxSex.Text.Trim(); string adminBirth = this.textBoxBirth.Text.Substring(0, 10).Trim(); if (adminID == "" || adminName == "" || adminSex == "" || adminBirth == "") { MessageBox.Show("请输入完整信息", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.textBoxPassword1.Text.Trim() != this.textBoxPassword2.Text.Trim()) { MessageBox.Show("两次输入密码不一致", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); this.textBoxPassword1.Text = ""; this.textBoxPassword2.Text = ""; return; } string adminPassword = this.textBoxPassword1.Text.Trim(); string comStr = string.Format("select * from dboSys where Sys_IID = \'{0}\'", adminID); SqlConnection sqlconnection = new SqlConnection(conStr); DataSet dataSet = new DataSet(); try { dataSet = SqlCommondClass.GetDataSet(comStr, "result", sqlconnection); } catch (System.Exception) { finished = false; MessageBox.Show("打开数据库失败", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { sqlconnection.Close(); } if (dataSet.Tables[0].Rows.Count >= 1) { MessageBox.Show("该管理员编号已经存在,可以直接登录", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { comStr = string.Format("insert into dboSys(Sys_IID,Sys_NAME,Sys_SEX,Sys_BIRTHDAY,Sys_PASSWORD) values(\'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\')", adminID, adminName, adminSex, adminBirth, coding(adminPassword)); MessageBox.Show(comStr); try { sqlconnection.Open(); SqlCommand command = new SqlCommand(comStr, sqlconnection); MessageBox.Show(command.ToString()); command.ExecuteNonQuery(); } catch (System.Exception) { finished = false; MessageBox.Show("创建管理员失败", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { sqlconnection.Close(); } if (finished) { MessageBox.Show("创建管理员成功"); } } }