public static VoterInfo RetrieveVoterInfoObject(int VoterID) // should retrieve a Candidate Object based on the input of a CandidateID, Candidate has an override for .ToString() { SqlDataReader DR; VoterInfo VIData = new VoterInfo(); string sql = "SELECT * From VoterInfo where VoterID = " + VoterID.ToString(); OpenDB(); SqlCommand cmd = new SqlCommand(sql, con); DR = cmd.ExecuteReader(); if (DR.Read()) { VIData.VoterID = (int)DR["VoterID"]; VIData.Salt = (byte[])DR["Salt"]; VIData.Hash = (byte[])DR["Hash"]; DR.Close(); CloseDB(); return(VIData); } else { CloseDB(); throw new Exception($"VoterID {VoterID} Not Found"); } }
//public static void VerifyVoter(VoterInfo VUser, VoterInfo VData) // method to verify voter information //{ // // VUser is the Voter Object retrieved from the Users input from the program // // VData is the Voter Object retrieved from the Database // string VUserString = VUser.ToString(); // string VDataString = VData.ToString(); // if (VUserString == VDataString) // { // // strings match and the voter is correct // } // else // { // // strings don't match, verification failed // } // //} public static Voter RetrieveVoterObject(int VoterID) // should retrieve a Voter Object based on the input of a VoterID, Voter has an override for .ToString() { SqlDataReader DR; Voter VData = new Voter(); string sql = "SELECT * From Voters where VoterID = " + VoterID.ToString(); OpenDB(); SqlCommand cmd = new SqlCommand(sql, con); DR = cmd.ExecuteReader(); if (DR.Read()) { VData.VoterID = (int)DR["VoterID"]; VData.Fname = (string)DR["Fname"]; VData.Lname = (string)DR["Lname"]; VData.HasVoted = (bool)DR["HasVoted"]; // watch this one, might need to specify a 0 or 1 instead of true or false DR.Close(); CloseDB(); return(VData); } else { CloseDB(); throw new Exception($"VoterID {VoterID} Not Found"); } }
public static Candidate RetrieveCandidateObject(int CandidateID) // should retrieve a Candidate Object based on the input of a CandidateID, Candidate has an override for .ToString() { SqlDataReader DR; Candidate CData = new Candidate(); string sql = "SELECT * From Candidates where VoterID = " + CandidateID.ToString(); OpenDB(); SqlCommand cmd = new SqlCommand(sql, con); DR = cmd.ExecuteReader(); if (DR.Read()) { CData.CandidateID = (int)DR["CandidateID"]; CData.FName = (string)DR["Fname"]; CData.LName = (string)DR["Lname"]; CData.PartyName = (string)DR["PartyName"]; CData.Seat = (string)DR["Seat"]; CData.VoteCount = (int)DR["VoteCount"]; DR.Close(); CloseDB(); return(CData); } else { CloseDB(); throw new Exception($"VoterID {CandidateID} Not Found"); } }
public List <string> GetAvailableColors() { List <string> availableColors = new List <string>(); SqlConnection CapstoneColors = new SqlConnection(); CapstoneColors.ConnectionString = @"Persist Security Info=False;Integrated Security=True;Database=CentreHigh3DPrintingServicesDB;Server=DATABAIST;"; CapstoneColors.Open(); SqlCommand Command = new SqlCommand { Connection = CapstoneColors, CommandType = CommandType.StoredProcedure, CommandText = "GetAvailableColors" }; SqlDataReader DR; DR = Command.ExecuteReader(); if (DR.HasRows) { while (DR.Read()) { for (int i = 0; i < DR.FieldCount; i++) { availableColors.Add(DR[i].ToString()); } } } DR.Close(); CapstoneColors.Close(); return(availableColors); }
public List <ProductBrandInfoDTO> GetProductBrand() { List <ProductBrandInfoDTO> productBrandiList = new List <ProductBrandInfoDTO>(); SqlDataReader DR; SqlConnection objMyCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objCmd = new SqlCommand(); objCmd.Connection = objMyCon; objCmd.CommandText = "SELECT PB_PK, PB_Code, PB_Name FROM ProductBrandInfo ORDER BY PB_Code DESC"; try { objMyCon.Open(); DR = objCmd.ExecuteReader(); } catch (Exception Exp) { throw Exp; } while (DR.Read()) { ProductBrandInfoDTO pbDto = new ProductBrandInfoDTO();//(Guid)DR[0],(string)DR[1],(string)DR[1]); pbDto.PrimaryKey = (Guid)DR[0]; pbDto.PB_Code = (string)DR[1]; pbDto.PB_Name = (string)DR[2]; productBrandiList.Add(pbDto); } DR.Close(); objMyCon.Close(); return(productBrandiList); }
private void txt_senha_Leave(object sender, EventArgs e) { DataBase.obterConexao(); string pesq = "SELECT * FROM TB_FUNCIONARIO WHERE SENHA= '" + txt_senha.Text + "'"; SqlCommand cmd = new SqlCommand(pesq, DataBase.obterConexao()); SqlDataReader DR; try { DataBase.obterConexao(); DR = cmd.ExecuteReader(); if (DR.Read()) { lbl_nome_log.Text = DR.GetValue(1).ToString(); lbl_sbre.Text = DR.GetValue(2).ToString(); lbl_rg.Text = DR.GetValue(3).ToString(); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DataBase.fecharConexao(); } }
/// <summary> /// 显示所有 /// </summary> /// <param name="Type">类型(单选/多选/不定项选/判断)</param> /// <param name="PapersID">试卷ID</param> /// <returns></returns> public List <Model.PapersTitleList> GetList(string Type, int PapersID, int StatusID) { string strSql = ""; //strSql = "Select * FROM [PapersTitleList] Where [Type]='" + Type + "' AND [PapersID]='" + PapersID + "' AND Status_id='"+ StatusID + "' order by newid()"; //add by wangke 2016-12-13 题目排序调整 strSql = "Select * FROM [PapersTitleList] Where [Type]='" + Type + "' AND [PapersID]='" + PapersID + "' AND Status_id='" + StatusID + "' order by ID"; List <Model.PapersTitleList> List = new List <Model.PapersTitleList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.PapersTitleList model = new Model.PapersTitleList(); model.Title = DR["Title"].ToString(); model.T_F = DR["T_F"].ToString(); model.ID = int.Parse(DR["ID"].ToString()); model.Score = int.Parse(DR["Score"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
private void btnBuscar_Click(object sender, EventArgs e) { string read = "SELECT (SELECT SUM(Monto) FROM Ingresos WHERE Empleado='" + this.cbxEmpleado.Text + "') - (SELECT SUM(Monto) FROM Deducciones WHERE Empleado='" + this.cbxEmpleado.Text + "')"; SqlCommand cmd = new SqlCommand(read, conexao); SqlDataReader DR; try { conexao.Open(); DR = cmd.ExecuteReader(); if (DR.Read()) { txtSalario.Text = DR.GetValue(0).ToString(); } else { MessageBox.Show("Registro no encontrado."); txtSalario.Clear(); cbxEmpleado.Focus(); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conexao.Close(); } }
/// <summary> /// 详细信息 /// </summary> /// <param name="TitleListID">题目ID</param> /// <returns></returns> public List <Model.OptionsList> Details(int TitleListID) { string strSql = ""; strSql = "Select * FROM [OptionsList] Where [TitleListID]='" + TitleListID + "'"; List <Model.OptionsList> List = new List <Model.OptionsList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.OptionsList model = new Model.OptionsList(); model.Name = DR["Name"].ToString(); model.T_F = DR["T_F"].ToString(); model.ID = int.Parse(DR["ID"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
/// <summary> /// 详细信息 /// </summary> /// <param name="ID">ID</param> /// <returns></returns> public List <Model.TitleList> Details(int ID) { string strSql = ""; strSql = "Select * FROM [TitleList] Where [ID]='" + ID + "'"; List <Model.TitleList> List = new List <Model.TitleList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.TitleList model = new Model.TitleList(); model.Title = DR["Title"].ToString(); model.T_F = DR["T_F"].ToString(); model.Analysis = DR["Analysis"].ToString(); model.ID = int.Parse(DR["ID"].ToString()); model.CourseID = int.Parse(DR["CourseID"].ToString()); model.Status_id = int.Parse(DR["Status_id"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
//Quando formulario é iniciado é selecionado o ultimo protocolo que foi adicionado no banco private void frm_Cadastro_Load(object sender, EventArgs e) { string pesquisa = "SELECT * FROM TB_PROTOCOLO"; SqlCommand cmd = new SqlCommand(pesquisa, DataBase.obterConexao()); SqlDataReader DR; try { DataBase.obterConexao(); DR = cmd.ExecuteReader(); if (DR.Read()) { lbl_prot_ocult.Text = DR.GetValue(0).ToString(); } else { MessageBox.Show("Erro"); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DataBase.fecharConexao(); } }
private void btnPesquisar_Click(object sender, EventArgs e) { //instrução sql responsável por pesquisar o banco de dados (CRUD - Read) string pesquisa = "select * from tbContatos where idContatos = " + txbId.Text; SqlCommand cmd = new SqlCommand(pesquisa, conexao); //objeto responsável pelos comandos(querys) no sql. //criando objeto de nome cmd tendo como modelo a classe OleDbCommand para execultar a instução sql // OleDbCommand cmd = new OleDbCommand(pesquisa, conexao); // Atravé da classe OleDbDataReader que faz parte do SqlCliente, criamos uma //variável chamada DR que será usada na leitura dos dados (instrução select) SqlDataReader DR; //OleDbDataReader DR; //tratamento de exeções: try - catch - finally (em caso de erro de erro capturamos o erro) try { //abrindo conexão com o bando de dados conexao.Open(); cmd.ExecuteNonQuery(); //Executa o cmd e pega todos os dados que buscamos com o nosso comando DataSet ds = new DataSet(); //setar dados SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; //adapta o cmd ao projeto da.Fill(ds); // preenche todas as informações dentro do DataSet //executando a instrução e armazenando o resultado do reader DR DR = cmd.ExecuteReader(); if (DR.Read()) { txbId.Text = DR.GetValue(0).ToString(); txbNome.Text = DR.GetValue(1).ToString(); txbTelefone.Text = DR.GetValue(2).ToString(); txbEmail.Text = DR.GetValue(3).ToString(); } //Exibe as Informações nas caisas de texto(textBox) correspondente (#) //nova pesquisa else { MessageBox.Show("Registro não encontrado"); txbNome.Text = ""; txbTelefone.Text = ""; txbEmail.Text = ""; txbId.Focus(); } //encerrando o uso do Reader DR DR.Close(); //encerra o cmd cmd.Dispose(); } catch (Exception ex) { //exibe o erro MessageBox.Show(ex.Message); } // de qualquer forma sempre fechar a conexão com o banco ("lembrar da porta da //geladeira rsrsrs") finally { conexao.Close(); } }
public static string[] RetrieveUserRole() { List <string> RoleDescList = new List <string>(); Conn = ConnectDB(); strSQL = "SELECT tblRole.* FROM tblRole ORDER BY tblRole.RoleID"; try { Cmd = new OleDbCommand(); if ((Conn.State == ConnectionState.Closed)) { Conn.Open(); } Cmd.Connection = Conn; Cmd.CommandText = strSQL; DR = Cmd.ExecuteReader(); while (DR.Read()) { //MessageBoxAdv.Show(DR["RoleDescription"].ToString()); RoleDescList.Add(DR["RoleDescription"].ToString()); } } catch (Exception ex) { MessageBoxAdv.Show(ex.Message); } DR.Close(); string[] RoleDesc = RoleDescList.ToArray(); return(RoleDesc); }
protected void ddNamaPerusahaan_SelectedIndexChanged(object sender, EventArgs e) { try { //DropDownList ddNamaPerusahaan = (DropDownList)GridResult.Rows[e.NewEditIndex].FindControl("ddNamaPerusahaan"); //DropDownList ddNamaBarang = (DropDownList)GridResult.Rows[e.NewEditIndex].FindControl("ddNamaBarang"); using (SqlConnection con = new SqlConnection(strConString)) { SqlCommand cmd = new SqlCommand("Select * From tblPerusahaan Where [Nama Perusahaan] = '" + ddNamaPerusahaan.SelectedValue + "'", con); con.Open(); cmd.ExecuteNonQuery(); SqlDataReader DR; DR = cmd.ExecuteReader(); while (DR.Read()) { //string IdPerusahaan = (string)DR["IdPerusahaan"].ToString(); lblIdPerusahaan.Text = DR[0].ToString(); } DR.Close(); con.Close(); } } catch (Exception ex) { message = ex.Message; } }
/// <summary> /// 详细信息 /// </summary> /// <param name="ID">ID</param> /// <returns></returns> public List <Model.Papers> Details(int ID) { string strSql = ""; strSql = "Select * FROM [Papers] Where [ID]='" + ID + "'"; List <Model.Papers> List = new List <Model.Papers>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.Papers model = new Model.Papers(); model.ID = int.Parse(DR["ID"].ToString()); model.Name = DR["Name"].ToString(); model.CourseID = int.Parse(DR["CourseID"].ToString()); model.Type = DR["Type"].ToString(); model.Lock = int.Parse(DR["Lock"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
private void frm_alterafunc_Load(object sender, EventArgs e) { string pesq = "SELECT * FROM TB_DADOS_LOG"; SqlCommand cmd = new SqlCommand(pesq, DataBase.obterConexao()); SqlDataReader DR; try { DataBase.obterConexao(); DR = cmd.ExecuteReader(); if (DR.Read()) { txt_pesquisa.Text = DR.GetValue(2).ToString(); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DataBase.fecharConexao(); } }
/// <summary> /// 显示所有 /// </summary> /// <param name="TitleListID">题目ID</param> /// <returns></returns> public List <Model.PapersOptionsList> GetList(int TitleListID, int PapersID) { string strSql = ""; //strSql = "Select * FROM [PapersOptionsList] Where [TitleListID]='" + TitleListID + "' and [PapersID]='" + PapersID + "' order by newid()"; strSql = "Select * FROM [PapersOptionsList] Where [TitleListID]='" + TitleListID + "' and [PapersID]='" + PapersID + "' order by ID"; List <Model.PapersOptionsList> List = new List <Model.PapersOptionsList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.PapersOptionsList model = new Model.PapersOptionsList(); model.Name = DR["Name"].ToString(); model.T_F = DR["T_F"].ToString(); model.PapersID = int.Parse(DR["PapersID"].ToString()); model.TitleListID = int.Parse(DR["TitleListID"].ToString()); model.ID = int.Parse(DR["ID"].ToString()); model.Score = int.Parse(DR["Score"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
//Quando formulario é iniciado é selecionado o ultimo protocolo que foi adicionado no banco //Quando formulário é iniciado seleciona o usuario logado private void frm_Serviços_Load(object sender, EventArgs e) { //PROTOCOLO string pesquisa = "SELECT * FROM TB_PROTOCOLO"; SqlCommand cmd = new SqlCommand(pesquisa, DataBase.obterConexao()); SqlDataReader DR; try { DataBase.obterConexao(); DR = cmd.ExecuteReader(); if (DR.Read()) { lbl_prot_ocult.Text = DR.GetValue(0).ToString(); } else { MessageBox.Show("Erro para pegar o valor do protocolo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DataBase.fecharConexao(); } //USUARIO string pesq = "SELECT * FROM TB_DADOS_LOG"; SqlCommand cmd2 = new SqlCommand(pesq, DataBase.obterConexao()); SqlDataReader DR2; try { DataBase.obterConexao(); DR2 = cmd2.ExecuteReader(); if (DR2.Read()) { txt_rg_func.Text = DR2.GetValue(2).ToString(); lbl_exp_nome_func.Text = DR2.GetValue(0).ToString(); lbl_exp_sbrnome_func.Text = DR2.GetValue(1).ToString(); } DR2.Close(); cmd2.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DataBase.fecharConexao(); } }
/// <summary> /// 显示所有 /// </summary> /// <param name="Type">类型(单选/多选/不定项选/判断)</param> /// <param name="CourseID">课程ID</param> /// <param name="Extent">程度</param> /// <returns></returns> public List <Model.TitleList> GetList(string Type, int CourseID, string Extent) { string strSql = ""; strSql = "Select * FROM [TitleList] Where [Type]='" + Type + "' AND [CourseID]='" + CourseID + "' AND [Extent]='" + Extent + "'"; List <Model.TitleList> List = new List <Model.TitleList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.TitleList model = new Model.TitleList(); model.Title = DR["Title"].ToString(); model.T_F = DR["T_F"].ToString(); model.Analysis = DR["Analysis"].ToString(); model.ID = int.Parse(DR["ID"].ToString()); model.Extent = DR["Extent"].ToString(); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
private void btnPesquisar_Click(object sender, EventArgs e) { if (txtId.Text == "") { MessageBox.Show("Valor Nulo! Digite um Id para pesquisar"); } //instrução sql responsável por pesquisar o banco de dados (CRUD - Read) string pesquisa = "select * from tbcontato where Id = " + txtId.Text; //criando um objeto de nome cmd tendo como modelo a classe OleDbCommand para executar a instrução sql OleDbCommand cmd = new OleDbCommand(pesquisa, conexao); // Atravé da classe OleDbDataReader que faz parte do SqlCliente, criamos uma //variável chamada DR que será usada na leitura dos dados (instrução select) OleDbDataReader DR; //tratamento de exceções: try - catch - finally (em caso de erro capturamos o //tipo do erro) try { // Abrindo a conexão com o banco conexao.Open(); // Executando a instrução e armazenando o resultado no reader DR DR = cmd.ExecuteReader(); // Se houver um registro correspondente ao Id if (DR.Read()) { // Exibe as informações nas caixas de texto (textBox) correspondentes (0) //corresponde ao Id, (1) ao Nome e assim sucessivamente txtId.Text = DR.GetValue(0).ToString(); txtNome.Text = DR.GetValue(1).ToString(); txtFone.Text = DR.GetValue(2).ToString(); txtEmail.Text = DR.GetValue(3).ToString(); } // Senão, exibimos uma mensagem avisando e também limpamos os campos para uma //nova pesquisa else { MessageBox.Show("Registro não encontrado"); txtNome.Clear(); txtFone.Clear(); txtEmail.Clear(); txtId.Focus(); } // Encerrando o uso do reader DR DR.Close(); // Encerrando o uso do cmd cmd.Dispose(); } //caso ocorra algum erro catch (Exception ex) { } // de qualquer forma sempre fechar a conexão com o banco ("lembrar da porta da //geladeira rsrsrs") finally { conexao.Close(); } }
private void pdc_imprimir_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { { int X = 50; int Y = 50; Font minhafonte = new Font("Arial", 14, FontStyle.Bold); e.Graphics.DrawString(this.Text, minhafonte, Brushes.Blue, X, Y); e.Graphics.DrawString(DateTime.Now.ToString(), minhafonte, Brushes.Blue, X + 500, Y); minhafonte = new Font("Arial", 12, FontStyle.Bold); Y = Y + 100; e.Graphics.DrawString("Numero de vendas", minhafonte, Brushes.Black, X, Y); e.Graphics.DrawString("Itens", minhafonte, Brushes.Black, X + 250, Y); e.Graphics.DrawString("Faturamento", minhafonte, Brushes.Black, X + 400, Y); e.Graphics.DrawString("Total", minhafonte, Brushes.Black, X + 650, Y); minhafonte = new Font("Arial", 12, FontStyle.Regular); string consulta = "SELECT * FROM tb_pedidos where status = 'Entregue'"; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = consulta; cmd.CommandType = CommandType.Text; cmd.Connection = Conexao.abreConexao(); MySqlDataReader DR; try { DR = cmd.ExecuteReader(); while (DR.Read()) { Y = Y + 30; // decimal valorTotal = Convert.ToDecimal(DR.GetValue(7)) * Convert.ToDecimal(DR.GetValue(7)); e.Graphics.DrawString(DR.GetValue(3).ToString(), minhafonte, Brushes.Black, X, Y); e.Graphics.DrawString(DR.GetValue(4).ToString(), minhafonte, Brushes.Black, X + 250, Y); e.Graphics.DrawString(DR.GetValue(7).ToString(), minhafonte, Brushes.Black, X + 400, Y); e.Graphics.DrawString(DR.GetValue(8).ToString(), minhafonte, Brushes.Black, X + 650, Y); // e.Graphics.DrawString(valorTotal.ToString(), minhafonte, Brushes.Black, X + 650, Y); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Conexao.fechaConexao(); } } }
private void pdcImprimir_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int X = 50; int Y = 50; Font minhafonte = new Font("Arial", 14, FontStyle.Bold); e.Graphics.DrawString(this.Text, minhafonte, Brushes.Blue, X, Y); e.Graphics.DrawString(DateTime.Now.ToString(), minhafonte, Brushes.Blue, X + 500, Y); minhafonte = new Font("Arial", 12, FontStyle.Bold); Y = Y + 100; e.Graphics.DrawString("Cliente dos Clientes", minhafonte, Brushes.Black, X, Y); e.Graphics.DrawString("Nome dos Clientes", minhafonte, Brushes.Black, X + 250, Y); e.Graphics.DrawString("Sexo dos Clientes", minhafonte, Brushes.Black, X + 500, Y); minhafonte = new Font("Arial", 12, FontStyle.Regular); string consulta = "SELECT * FROM Clientes"; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = consulta; cmd.CommandType = CommandType.Text; cmd.Connection = Conexao.abreConexao(); MySqlDataReader DR; try { DR = cmd.ExecuteReader(); while (DR.Read()) { Y = Y + 30; e.Graphics.DrawString(DR.GetValue(0).ToString(), minhafonte, Brushes.Black, X, Y); e.Graphics.DrawString(DR.GetValue(1).ToString(), minhafonte, Brushes.Black, X + 250, Y); e.Graphics.DrawString(DR.GetValue(2).ToString(), minhafonte, Brushes.Black, X + 500, Y); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Conexao.fechaConexao(); } }
private void btnBuscar_Click(object sender, EventArgs e) { string read = "select * from Ingresos where Nombre='" + this.txtNombre.Text + "'"; SqlCommand cmd = new SqlCommand(read, conexao); SqlDataReader DR; try { conexao.Open(); DR = cmd.ExecuteReader(); if (DR.Read()) { txtID.Text = DR.GetValue(0).ToString(); txtNombre.Text = DR.GetValue(1).ToString(); cbxEmpleado.Text = DR.GetValue(2).ToString(); cbxIngreso.Text = DR.GetValue(3).ToString(); cbxDependeSalario.Text = DR.GetValue(4).ToString(); cbxEstado.Text = DR.GetValue(5).ToString(); txtFecha.Text = DR.GetValue(6).ToString(); txtMonto.Text = DR.GetValue(7).ToString(); } else { MessageBox.Show("Registro no encontrado."); txtNombre.Clear(); cbxEmpleado.SelectedItem = null; cbxIngreso.SelectedItem = null; cbxDependeSalario.SelectedItem = null; cbxEstado.SelectedItem = null; txtMonto.Clear(); txtNombre.Focus(); } DR.Close(); cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conexao.Close(); } }
/// <summary> /// 查询所有 /// </summary> /// <returns></returns> public List <Model.UserSystem> GetList(int PageCount, int PageSize) { string strSql = ""; string RedCountsql = ""; int RowTotal = (PageCount - 1) * PageSize;// RedCountsql = "(select count(TR_ID) from [AP_TRAINEE_USER]) as RowTotal"; strSql = "Select Top " + PageSize + " [TR_ID],[TR_POSITION],[TR_NICKNAME],[TR_NAME],[TR_SEX],[TR_CITY],[TR_PHONE],[TR_EMAIL],[TR_COMPANY_TEL],[TR_QR_CODE]," + RedCountsql + " FROM AP_TRAINEE_USER where [TR_ID] not in (Select Top " + RowTotal + " [TR_ID] from AP_TRAINEE_USER ORDER BY TR_ID DESC) ORDER BY TR_ID DESC"; List <Model.UserSystem> List = new List <Model.UserSystem>(); SqlParameter[] parameters = { }; SqlDataReader DR; if (GetUserSysSetupInfo()) { DR = UserSys.ExecuteReader(strSql.ToString(), parameters); } else { DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); } using (DR) { while (DR.Read()) { Model.UserSystem model = new Model.UserSystem(); model.ID = int.Parse(DR["TR_ID"].ToString()); model.cnName = DR["TR_NAME"].ToString(); model.enName = DR["TR_NICKNAME"].ToString(); model.Sex = DR["TR_SEX"].ToString(); model.ZipCode = DR["TR_QR_CODE"].ToString(); model.Address = DR["TR_CITY"].ToString(); model.Mobile = DR["TR_COMPANY_TEL"].ToString(); model.Phone = DR["TR_PHONE"].ToString(); model.Email = DR["TR_EMAIL"].ToString(); model.RowTotal = int.Parse(DR["RowTotal"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
public static DataTable GetData() { string sConn = @"Server=(local); Database=AdventureWorks;Trusted_Connection=true;User Id=ABSAROKA\frann"; SqlConnection conn = new SqlConnection(sConn); string sSQL = "SELECT * FROM [Production].[Product] ORDER BY ProductLine, Name"; SqlCommand comm; SqlDataReader DR; DataTable DT = new DataTable(); DataTable UoM = new DataTable(); conn.Open(); comm = new SqlCommand(sSQL, conn); DR = comm.ExecuteReader(); DT.Load(DR); DR.Close(); conn.Close(); return(DT); }
/// <summary> /// 显示所有 /// add by wangke 2016-11-23 添加返回datatable类型 /// </summary> /// <param name="Type">类型(单选/多选/不定项选/判断)</param> /// <param name="CourseID">课程ID</param> /// <returns></returns> public DataTable GetList(string Type, int CourseID, int Status_id) { string strSql = ""; if (Status_id != 0) { strSql = "Select * FROM [TitleList] Where [Type]='" + Type + "' AND [CourseID]='" + CourseID + "' AND [Status_id]=" + Status_id; } else { strSql = "Select * FROM [TitleList] Where [Type]='" + Type + "' AND [CourseID]='" + CourseID + "'"; } DataTable dt = new DataTable(); dt.Columns.Add("Title"); dt.Columns.Add("T_F"); dt.Columns.Add("Analysis"); dt.Columns.Add("ID"); dt.Columns.Add("Extent"); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { DataRow dr = dt.NewRow(); dr["Title"] = DR["Title"].ToString(); dr["T_F"] = DR["T_F"].ToString(); dr["Analysis"] = DR["Analysis"].ToString(); dr["ID"] = DR["ID"].ToString(); dr["Extent"] = DR["Extent"].ToString(); dt.Rows.Add(dr); } DR.Close(); DR.Dispose(); } return(dt); }
public MainWindow() { InitializeComponent(); string sConn = @"Server=(local)\AURORA; Database=AdventureWorks2012;Trusted_Connection=true"; SqlConnection conn = new SqlConnection(sConn); string sSQL = "SELECT * FROM [Production].[Product] ORDER BY ProductLine, Name"; SqlCommand comm; SqlDataReader DR; DataTable DT = new DataTable(); conn.Open(); comm = new SqlCommand(sSQL, conn); DR = comm.ExecuteReader(); DT.Load(DR); LayoutGrid.DataContext = DT; DR.Close(); conn.Close(); }
/// <summary> /// 查询所有 /// </summary> /// <param name="CourseLbID">类别ID</param> /// <returns></returns> public List <Model.CourseSystem> GetList(int PageCount, int PageSize, int CourseLbID) { string strSql = ""; string RedCountsql = ""; int RowTotal = (PageCount - 1) * PageSize;// RedCountsql = "(select count(CR_ID) from [AP_COURSE] where [CR_CATEGORY_ID]='" + CourseLbID + "' ) as RowTotal"; strSql = "Select Top " + PageSize + " *," + RedCountsql + " FROM [AP_COURSE] where [CR_ID] not in (Select Top " + RowTotal + " [CR_ID] from [AP_COURSE] Where [CR_CATEGORY_ID]='" + CourseLbID + "' ORDER BY CR_ID DESC ) And [CR_CATEGORY_ID]='" + CourseLbID + "' ORDER BY CR_ID DESC"; List <Model.CourseSystem> List = new List <Model.CourseSystem>(); SqlParameter[] parameters = { }; SqlDataReader DR; if (GetCourseSysSetupInfo()) { DR = CourseSys.ExecuteReader(strSql.ToString(), parameters); } else { DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); } using (DR) { while (DR.Read()) { Model.CourseSystem model = new Model.CourseSystem(); model.ID = int.Parse(DR["CR_ID"].ToString()); model.Title = DR["CR_COURSE_NAME"].ToString(); model.RowTotal = int.Parse(DR["RowTotal"].ToString()); model.Credit = int.Parse(DR["CR_CREDIT"].ToString()); model.Money = int.Parse(DR["CR_MONEY"].ToString()); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
/// <summary> /// 查询所有 /// </summary> /// <param name="UserName">用户名(可中可英)</param> /// <returns></returns> public List <Model.UserSystem> GetList(string UserName) { string strSql = ""; strSql = "Select * FROM [AP_TRAINEE_USER] Where [TR_NAME] like '%" + UserName + "%' or [TR_NICKNAME] like '%" + UserName + "%'"; List <Model.UserSystem> List = new List <Model.UserSystem>(); SqlParameter[] parameters = { }; SqlDataReader DR; if (GetUserSysSetupInfo()) { DR = UserSys.ExecuteReader(strSql.ToString(), parameters); } else { DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); } using (DR) { while (DR.Read()) { Model.UserSystem model = new Model.UserSystem(); model.ID = int.Parse(DR["TR_ID"].ToString()); model.cnName = DR["TR_NAME"].ToString(); model.enName = DR["TR_NICKNAME"].ToString(); model.Sex = DR["TR_SEX"].ToString(); model.ZipCode = DR["TR_QR_CODE"].ToString(); model.Address = DR["TR_CITY"].ToString(); model.Mobile = DR["TR_COMPANY_TEL"].ToString(); model.Phone = DR["TR_PHONE"].ToString(); model.Email = DR["TR_EMAIL"].ToString(); List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }
/// <summary> /// 统计分值 /// </summary> /// <param name="Type">类型(单选/多选/不定项选/判断)</param> /// <param name="PapersID">试卷ID</param> /// <returns></returns> private List <Model.PapersTitleList> nSumScore(string Type, int PapersID) { string strSql = ""; if (Type != "") { strSql = "SELECT SUM([Score]) as sumscore FROM [ExaminationSystem].[Exam].[PapersTitleList] where PapersID='" + PapersID + "' and Type='" + Type + "'"; } else { strSql = "SELECT SUM([Score]) as sumscore FROM [ExaminationSystem].[Exam].[PapersTitleList] where PapersID='" + PapersID + "'"; } List <Model.PapersTitleList> List = new List <Model.PapersTitleList>(); SqlParameter[] parameters = { }; SqlDataReader DR; DR = ExamSys.ExecuteReader(strSql.ToString(), parameters); using (DR) { while (DR.Read()) { Model.PapersTitleList model = new Model.PapersTitleList(); if (DR["sumscore"].ToString() == "") { model.Score = 0; } else { model.Score = int.Parse(DR["sumscore"].ToString()); } List.Add(model); } DR.Close(); DR.Dispose(); } return(List); }