private void btnRegister_Click_1(object sender, EventArgs e) { if (allFieldsAreNotEmpty()) { try { DBuser.createNewUser(txtName.Text, txtUsername.Text, txtUsername.Text, chAdmin.Checked); MessageBox.Show("Usuario agregado exitosamente", "Clase GUI 05", MessageBoxButtons.OK, MessageBoxIcon.Information); fillControls(); } catch (Exception ex) { if (ex.GetType().ToString() == "Npgsql.PostgresException") { MessageBox.Show("Verificar si el usuario a ingresar ya existe en la base", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("Error desconocido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("¡Complete todos los campos!", "Clase GUI 05", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
protected void lostbtn_Click(object sender, EventArgs e) { string stayid = Request.Cookies["stayid"].Value; string type = DropDownList1.SelectedValue; //失物类型 string attri = attributes.Text.Trim(); //失物属性 string quyu = DropDownList2.SelectedValue; //失物区域 string pickinfo = pickertext.Text.Trim(); //拾到者信息 if (attributes.Text == "" || pickertext.Text == "") { MessageBox.Show("请填写完整属性以及拾到者信息!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } string timenow; DateTime t1 = new DateTime(); t1 = DateTime.Now; timenow = t1.Year + "-" + t1.Month + "-" + t1.Day + " " + t1.Hour + ":" + t1.Minute + ":" + t1.Second + "." + t1.Millisecond;//登记时间 string sql1 = "insert into 失物登记表(类型,收入站点,失物属性,捡拾地,登记时间,拾到者登记) values ('" + type + "','" + stayid + "','" + attri + "','" + quyu + "','" + timenow + "','" + pickinfo + "');"; DBuser dh = new DBuser(); int res1 = dh.DBhandle(sql1); if (res1 > 0) { MessageBox.Show("登记成功!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { MessageBox.Show("登记失败!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } dh.closeDb(); }
private void dtvUsers_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewRow row = dtvUsers.Rows[e.RowIndex]; string selectedUser = row.Cells[2].Value.ToString(); if (selectedUser == loggedUser.userName) { MessageBox.Show("No se puede eliminar al usuario actual", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (MessageBox.Show("¿Seguro que desea eliminar al usuario " + selectedUser + "?", "Clase GUI 06", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DBuser.dropUser(selectedUser); MessageBox.Show("¡Usuario eliminado exitosamente!", "Clase GUI 06", MessageBoxButtons.OK, MessageBoxIcon.Information); fillControls(); } } }
private void btnChange_Click(object sender, EventArgs e) { User user = (User)cmbUsers.SelectedItem; if (txtPass.Text.Length != 0 && txtConfirmPass.Text.Length != 0 && txtOldPass.Text.Length != 0) { if (DBuser.getIfPasswordMatch(user.userName, txtOldPass.Text)) { if (txtPass.Text == txtConfirmPass.Text) { DBuser.changeUserPassword(user.userName, txtConfirmPass.Text); MessageBox.Show("Operacion realizada exitosamente", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); originForm.fillCombo(); } else { MessageBox.Show("Las claves no coinciden", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("La clave vieja es incorrecta", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Llenar todos los campos", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void fillCombo() { // Actualizar ComboBox cmbUsers.DataSource = null; cmbUsers.ValueMember = "password"; cmbUsers.DisplayMember = "userName"; cmbUsers.DataSource = DBuser.GetUsers(); }
public void OpenDatabase() { //Status.UpdateStatus(); if (IsInitialized && (IsConnectedCheck || IsConnecting)) { return; } // check for settings from text file // force the configuration file through try { switch (_dbType) { case ClsDAL.DBTypes.MYSQL: if (DBserver.Trim() != "" && DBdatabase.Trim() != "" && DBuser.Trim() != "" && DBpassword.Trim() != "") { string strUSR = Crypto.Decrypt(DBuser); string strPWD = Crypto.Decrypt(DBpassword); strUSR = (strUSR == "") ? DBuser : strUSR; strPWD = (strPWD == "") ? DBpassword : strPWD; DAL.OpenConnection(DBserver, DBdatabase, strUSR, strPWD, DBport); _blnInitialized = true; if (DAL.IsConnectedCheck) { //Debug.Log("MySQL服务器链接成功"); } } else { Debug.Log("缺少数据库链接信息"); //没有数据库链接信息 } break; } } catch { Debug.Log("Unable to Connect to the Database"); //Unable to Connect to the Database."; //_blnClientCanUse = false; } //Status.UpdateStatus(); }
private void fillControls() { List <UserDirections> directions = UserDirectionsDAO.getDirections(loggedUser.idUser.ToString()); if (loggedUser.userType) { List <User> lista = DBuser.GetUsers(); List <Business> businesses = DBbusiness.getBusiness(); List <Product> products = DBproduct.getAll(); cmbProBusi.DataSource = null; cmbProBusi.ValueMember = "idbusiness"; cmbProBusi.DisplayMember = "name"; cmbProBusi.DataSource = businesses; // Tabla (data grid view) dtvUsers.DataSource = null; dtvUsers.DataSource = lista; //Escondiendo la columna de la clave dtvUsers.Columns[3].Visible = false; dtvUsers.Columns[0].Visible = false; dgvBusi.DataSource = null; dgvBusi.DataSource = businesses; dgvPro.DataSource = null; dgvPro.DataSource = products; } else { if (!hasCheckedUserType) { tabControl1.TabPages[0].Parent = null; tabControl1.TabPages[1].Parent = null; hasCheckedUserType = true; } } dgvDirections.DataSource = null; dgvDirections.DataSource = directions; }
protected void returnbtn_Click(object sender, EventArgs e) { int returnID = Convert.ToInt32(bianhaotext.Text); string timenow; DateTime t1 = new DateTime(); t1 = DateTime.Now; timenow = t1.Year + "-" + t1.Month + "-" + t1.Day + " " + t1.Hour + ":" + t1.Minute + ":" + t1.Second + "." + t1.Millisecond;//登记时间 string takerinfo = pickertext.Text.Trim(); string sql1 = "insert into 失物归还表(编号,领取者登记,时间) values('" + returnID + "','" + takerinfo + "','" + timenow + "');"; string sql2 = "update 失物登记表 set 失物状态='N' where 编号= " + returnID + ";"; DBuser dh = new DBuser(); int res1 = dh.DBhandle(sql1); int res2 = dh.DBhandle(sql2); if (res1 > 0 && res2 > 0) { MessageBox.Show("失物领取成功!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } dh.closeDb(); }
//登录按钮的单击事件 protected void Button1_Click(object sender, EventArgs e) { //判断是否非空 if (TextBox1.Text == "" || TextBox2.Text == "") { MessageBox.Show("请填写管理员ID或密码!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { DBuser dh = new DBuser(); string managerid = TextBox1.Text.Trim(); string password = TextBox2.Text.Trim(); string sql = "select 登录密码,管理站点 from 管理员表 where ID='" + managerid + "';"; SqlDataReader reader = dh.queryDb(sql); if (reader.HasRows) { reader.Read(); //判断密码是否正确 if (((string)reader[0]) == password) { Response.Cookies["stayid"].Value = reader[1].ToString(); dh.closeDb(); //转到管理员界面 Response.Redirect("manager.aspx"); } else { dh.closeDb(); MessageBox.Show("密码错误!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } else { dh.closeDb(); MessageBox.Show("管理员ID不存在!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } }
//登录按钮单击事件 protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "" || TextBox2.Text == "")//判断是否非空 { MessageBox.Show("请填写学工号或密码!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { DBuser dh = new DBuser(); string userid = TextBox1.Text.Trim(); string password = TextBox2.Text.Trim(); string sql = "select 密码,借伞状态 from 用户表 where 学工号='" + userid + "';"; SqlDataReader reader = dh.queryDb(sql); if (reader.HasRows) { reader.Read(); //判断密码是否正确 if (((string)reader[0]) == password) { Response.Cookies["userid"].Value = userid; dh.closeDb(); //转到用户界面 Response.Redirect("user.aspx"); } else { dh.closeDb(); MessageBox.Show("密码错误!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } else { dh.closeDb(); MessageBox.Show("学工号不存在!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } }
public void OpenDatabase(bool blnReadSettingsFile = true) { #if USES_STATUSMANAGER Status.UpdateStatus(); #endif if (!IsServer && !ClientsCanUse) { return; } if (IsInitialized && (IsConnectedCheck || IsConnecting)) { return; } // CHECK FOR SETTINGS FROM TEXT FILE bool blnOkayToProcessTextFile = false; bool blnCouldClientLogIn = _blnClientCanUse; string[] strLines = null; // FORCE THE CONFIGURATION FILE THROUGH if (blnReadSettingsFile) { DBsettingsFile = ""; if (DBtextFile != null) { DBsettingsFile = DBtextFile.name + ".txt"; } if (!_blnDBisReadIn && DBsettingsFile != "") { if (!Util.FileExists("", DBsettingsFile)) { #if USES_STATUSMANAGER Status.Status = "Unable to find file \"" + DBsettingsFile + "\"."; #endif _blnClientCanUse = false; } else { strLines = Util.ReadTextFile("", DBsettingsFile).Split('\n'); blnOkayToProcessTextFile = strLines != null && strLines.Length > 0; #if USES_STATUSMANAGER Status.Status = DBsettingsFile + " found. " + strLines.Length.ToString() + " lines Read In."; #endif } if (DBtextFile != null && !blnOkayToProcessTextFile) { strLines = DBtextFile.text.Split('\n'); blnOkayToProcessTextFile = strLines.Length > 0; } if (blnOkayToProcessTextFile) { DBport = 0; if (strLines.Length > 0) { foreach (string st in strLines) { if (!st.StartsWith("//") && st.Trim() != "" && st.Contains("=")) { string[] s = st.Trim().Split('='); if (s.Length > 2) { for (int i = 2; i < s.Length; i++) { s[1] += "=" + s[i]; } } switch (s[0].Trim().ToLower()) { case "server": DBserver = s[1].Trim(); break; case "database": DBdatabase = s[1].Trim(); break; case "username": DBuser = Crypto.Decrypt(s[1].Trim()); if (DBuser == "") { DBuser = s[1].Trim(); } break; case "password": DBpassword = Crypto.Decrypt(s[1].Trim()); if (DBpassword == "") { DBpassword = s[1].Trim(); } break; case "port": try { DBport = int.Parse(s[1].Trim()); } catch { DBport = 0; } break; case "retries": try { MAX_SQL_RETRIES = int.Parse(s[1].Trim()); } catch { MAX_SQL_RETRIES = 0; } break; case "cmdcount": try { MAX_SQL_SAVE_CMDS = int.Parse(s[1].Trim()); } catch { MAX_SQL_SAVE_CMDS = 0; } break; case "charcount": try { MAX_SQL_CHAR_COUNT = int.Parse(s[1].Trim()); } catch { MAX_SQL_CHAR_COUNT = 0; } break; case "savedelay": try { SQL_SAVE_DELAY = float.Parse(s[1].Trim()); } catch { SQL_SAVE_DELAY = 0; } break; case "sqlitedbfile": try { SQLiteDBfileLocation = s[1].Trim(); } catch { SQLiteDBfileLocation = ""; } break; } } } } DBuseWindowsAccount = (DBuser == "" && DBpassword == ""); } _blnDBisReadIn = true; } } try { switch (_dbType) { case ClsDAL.DBtypes.MSSQL: if (DBserver.Trim() != "" && DBdatabase.Trim() != "" && ((DBuser.Trim() != "" && DBpassword.Trim() != "") || DBuseWindowsAccount)) { if (!_blnClientCanUse) { _blnClientCanUse = blnCouldClientLogIn; } if (DBuseWindowsAccount) { DAL.OpenConnection(DBserver, DBdatabase, DBport); } else { string strUSR = Crypto.Decrypt(DBuser); string strPWD = Crypto.Decrypt(DBpassword); strUSR = (strUSR == "") ? DBuser : strUSR; strPWD = (strPWD == "") ? DBpassword : strPWD; DAL.OpenConnection(DBserver, DBdatabase, strUSR, strPWD, DBport); } _blnInitialized = true; if (DAL.IsConnectedCheck) { #if USES_STATUSMANAGER Status.Status = "Unable to Connect to the Database."; Status.UpdateStatus(); #endif _blnClientCanUse = false; } } else { #if IS_DEBUGGING #if USES_APPLICATIONMANAGER App.AddToDebugLog("-- Missing Database Connection Information."); #endif #endif } break; case ClsDAL.DBtypes.MYSQL: if (DBserver.Trim() != "" && DBdatabase.Trim() != "" && DBuser.Trim() != "" && DBpassword.Trim() != "") { if (!_blnClientCanUse) { _blnClientCanUse = blnCouldClientLogIn; } string strUSR = Crypto.Decrypt(DBuser); string strPWD = Crypto.Decrypt(DBpassword); strUSR = (strUSR == "") ? DBuser : strUSR; strPWD = (strPWD == "") ? DBpassword : strPWD; DAL.OpenConnection(DBserver, DBdatabase, strUSR, strPWD, DBport); _blnInitialized = true; if (DAL.IsConnectedCheck) { #if USES_STATUSMANAGER Status.Status = "Unable to Connect to the Database."; Status.UpdateStatus(); #endif _blnClientCanUse = false; } } else { #if IS_DEBUGGING #if USES_APPLICATIONMANAGER App.AddToDebugLog("-- Missing Database Connection Information."); #endif #endif } break; case ClsDAL.DBtypes.SQLITE: if (SQLiteDBfileLocation.Trim() != "") { DAL.OpenConnection(SQLiteDBfileLocation); _blnInitialized = true; if (DAL.IsConnectedCheck) { #if USES_STATUSMANAGER Status.Status = "Unable to Connect to the Database."; Status.UpdateStatus(); #endif _blnClientCanUse = false; } } else { #if IS_DEBUGGING #if USES_APPLICATIONMANAGER App.AddToDebugLog("-- Missing Database Flie Location Information."); #endif #endif } break; } } catch { #if USES_STATUSMANAGER Status.Status = "Unable to Connect to the Database."; Status.UpdateStatus(); #endif _blnClientCanUse = false; } #if USES_STATUSMANAGER Status.UpdateStatus(); #endif }
protected void Button2_Click(object sender, EventArgs e) { int indexselcet = DropDownList1.SelectedIndex + 1; DBuser dh = new DBuser(); //判断是否可以借伞 string userid = (string)Request.Cookies["userid"].Value; // string userid = (string)Session["userid"]; string sqlx = "select 借伞状态 from 用户表 where 学工号='" + userid + "';"; SqlDataReader reader0 = dh.queryDb(sqlx); if (reader0.HasRows) { //reader0.Read(); //Session["userstate"] = (string)reader0[0]; //if ((string)Session["userstate"] != "T") //{ // MessageBox.Show("无借伞记录!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); // return; //} reader0.Read(); string state = (string)reader0[0]; if (state != "T") { dh.closeDb(); MessageBox.Show("无借伞记录!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } } ////////////////// string sql = "select top 1 雨伞ID from 雨伞借出表 where 用户ID=" + userid + "order by ID DESC;"; SqlDataReader reader = dh.queryDb(sql); //List<allumbrella> brow = new List<allumbrella>(); if (reader.HasRows == true) { reader.Read(); int umid = (int)reader[0]; string timenow; DateTime t1 = new DateTime(); t1 = DateTime.Now; timenow = t1.Year + "-" + t1.Month + "-" + t1.Day + " " + t1.Hour + ":" + t1.Minute + ":" + t1.Second + "." + t1.Millisecond; string sql1 = "insert into 雨伞归还表(用户ID,雨伞ID,归还站点,归还时间) values ('" + userid + "'," + umid + "," + indexselcet + ",'" + timenow + "');"; int res1 = dh.DBhandle(sql1); string sql2 = "update 用户表 set 借伞状态='F' where 学工号= " + userid + ";"; int res2 = dh.DBhandle(sql2); string sql3 = "update 站点雨伞情况表 set 雨伞余量=雨伞余量+1 where 站点=" + indexselcet + ";"; int res3 = dh.DBhandle(sql3); string sql4 = "update 雨伞总表 set 归还次数=归还次数+1,可借状态='Y',所在站点=" + indexselcet + "where ID=" + umid + ";"; int res4 = dh.DBhandle(sql4); //MessageBox.Show("所借雨伞ID为" + res1 +timenow+",锁具已开,请取伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res1 > 0 && res2 > 0 && res3 > 0 && res4 > 0) { // Session["userstate"] = 'F';//应注释掉 MessageBox.Show("雨伞已还,锁具已上锁!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); dh.closeDb(); return; } } //else //{ // MessageBox.Show("无可借雨伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); //} }
protected void Button1_Click(object sender, EventArgs e) { int indexselcet = DropDownList1.SelectedIndex + 1; DBuser dh = new DBuser(); //判断是否可以借伞 // string userid = (string)Session["userid"]; string userid = (string)Request.Cookies["userid"].Value; string sqlx = "select 借伞状态 from 用户表 where 学工号='" + userid + "';"; SqlDataReader reader0 = dh.queryDb(sqlx); if (reader0.HasRows) { //reader0.Read(); //Session["userstate"] = (string)reader0[0]; //if ((string)Session["userstate"] != "F") //{ // MessageBox.Show("你有未归还雨伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); // return; //} reader0.Read(); string state = (string)reader0[0]; if (state != "F") { MessageBox.Show("你有未归还雨伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); dh.closeDb(); return; } } ////////////////// string sql = "select top 1 * from 雨伞总表 where 可借状态= 'Y' and 所在站点=" + indexselcet + ";"; SqlDataReader reader = dh.queryDb(sql); //List<allumbrella> brow = new List<allumbrella>(); if (reader.HasRows == true) { allumbrella outp = new allumbrella(); while (reader.Read()) { outp.ID = (int)reader[0]; outp.outnum = (int)reader[2]; outp.backnum = (int)reader[3]; outp.state = (string)reader[5]; outp.stay = (int)reader[4]; } string timenow; DateTime t1 = new DateTime(); t1 = DateTime.Now; timenow = t1.Year + "-" + t1.Month + "-" + t1.Day + " " + t1.Hour + ":" + t1.Minute + ":" + t1.Second + "." + t1.Millisecond; string sql1 = "insert into 雨伞借出表 (用户ID,雨伞ID,借出站点,借出时间) values ('" + userid + "'," + outp.ID + "," + indexselcet + ",'" + timenow + "');"; int res1 = dh.DBhandle(sql1); string sql2 = "update 用户表 set 借伞状态='T' where 学工号= " + userid + ";"; int res2 = dh.DBhandle(sql2); string sql3 = "update 站点雨伞情况表 set 雨伞余量=雨伞余量-1 where 站点=" + outp.stay + ";"; int res3 = dh.DBhandle(sql3); string sql4 = "update 雨伞总表 set 借出次数=借出次数+1,可借状态='N',所在站点=0 where ID=" + outp.ID + ";"; int res4 = dh.DBhandle(sql4); //MessageBox.Show("所借雨伞ID为" + res1 +timenow+",锁具已开,请取伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res1 > 0 && res2 > 0 && res3 > 0 && res4 > 0) { // Session["userstate"] ="T";//应注释掉 MessageBox.Show("所借雨伞ID为" + outp.ID + ",锁具已开,请取伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); dh.closeDb(); return; } } else { dh.closeDb(); MessageBox.Show("无可借雨伞!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } }
//注册按钮的单击事件 protected void Button1_Click(object sender, EventArgs e) { string userid = TextBox1.Text.Trim(); //学号 string pwd = TextBox2.Text.Trim(); //密码 string phonenum = TextBox4.Text.Trim(); //手机号 string address = DropDownList1.Text; //地址 string pn = @"^0?1[3|4|5|8][0-9]\d{8}$"; //手机号的正则表达式 Regex reg = new Regex(pn); string un = @"^\d{8}$"; //学号的正则表达式 Regex reg1 = new Regex(un); //判断非空 if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "") { MessageBox.Show("请填写全部信息!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { if (TextBox3.Text != TextBox2.Text)//判断两次输入密码是否一致 { MessageBox.Show("两次密码不一致!请确认!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } if (!reg.IsMatch(phonenum))//判断手机号格式是否正确 { MessageBox.Show("手机号格式不正确!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } if (!reg1.IsMatch(userid))//判断学号是否是8位 { MessageBox.Show("请输入8位学号!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } userid = TextBox1.Text.Trim(); pwd = TextBox2.Text.Trim(); phonenum = TextBox4.Text.Trim(); address = DropDownList1.Text; DBuser dh = new DBuser(); string sql = "select 学工号 from 用户表 where 学工号='" + userid + "';"; SqlDataReader reader = dh.queryDb(sql); //判断用户是否已经存在 if (reader.HasRows) { reader.Read(); dh.closeDb(); MessageBox.Show("用户已存在!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); return; } string sql1 = "insert into 用户表 (学工号,密码,手机号,住址) values ('" + userid + "','" + pwd + "','" + phonenum + "','" + address + "')"; int res = dh.DBhandle(sql1); //插入注册信息 if (res > 0) { MessageBox.Show("注册成功!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); dh.closeDb(); Response.Redirect("userlogin.aspx"); } else { dh.closeDb(); MessageBox.Show("注册失败!", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } }
//查询按钮的单击事件 protected void lostbtn_Click(object sender, EventArgs e) { ListBox1.Visible = true; ListBox1.Items.Clear();//清空数据 int indexselcet1 = DropDownList1.SelectedIndex; int indexselect2 = DropDownList2.SelectedIndex; string type = DropDownList1.SelectedValue; string area = DropDownList2.SelectedValue; string sqlsearch = ""; string searchtime = losttime.Text.Trim(); //判断查询条件 if (indexselcet1 == 0 && indexselect2 == 0 && searchtime == "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y';"; } if (indexselcet1 != 0 && indexselect2 == 0 && searchtime == "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 类型='" + type + "';"; } if (indexselcet1 == 0 && indexselect2 != 0 && searchtime == "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 捡拾地='" + area + "';"; } if (indexselcet1 == 0 && indexselect2 == 0 && searchtime != "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 登记时间>='" + searchtime + "';"; } if (indexselcet1 == 0 && indexselect2 != 0 && searchtime != "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 捡拾地='" + area + "' and 登记时间>='" + searchtime + "';"; } if (indexselcet1 != 0 && indexselect2 == 0 && searchtime != "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 类型='" + type + "' and 登记时间>='" + searchtime + "';"; } if (indexselcet1 != 0 && indexselect2 != 0 && searchtime == "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 捡拾地='" + area + "' and 类型='" + type + "';"; } if (indexselcet1 != 0 && indexselect2 != 0 && searchtime != "") { sqlsearch = "select 编号,类型,收入站点,失物属性,捡拾地 from 失物登记表 where 失物状态='Y' and 捡拾地='" + area + "' and 类型='" + type + "' and 登记时间>='" + searchtime + "';"; } DBuser dh = new DBuser(); DataTable losttable = dh.DTquery(sqlsearch); dh.closeDb(); ListBox1.Items.Add("编号\t\t类型\t\t所在站点\t\t失物属性\t\t捡拾地"); ListBox1.Items.Add("======================================"); for (int i = 0; i < losttable.Rows.Count; i++) { ListBox1.Items.Add(string.Format("{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}", losttable.Rows[i].ItemArray[0].ToString(), losttable.Rows[i].ItemArray[1].ToString(), losttable.Rows[i].ItemArray[2].ToString(), losttable.Rows[i].ItemArray[3].ToString(), losttable.Rows[i].ItemArray[4].ToString() )); } }