private void button2_Click(object sender, EventArgs e) { try { User = textBox1.Text.Trim(); Pass = textBox2.Text.Trim(); string str = "SELECT Quyen from tblDangnhap where Taikhoan = '" + User + "' and Matkhau = '" + Pass + "'"; clsDatabase cls = new clsDatabase(); string kq = cls.Execute_Reader(str); if (kq == "") { MessageBox.Show("Tên đăng nhập hoặc tài khoản không đúng!"); } else { Main mainform = new Main(); mainform.Show(); clsThongTinChung._UserAccount = User; clsThongTinChung._Quyen = kq; this.Hide(); } } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại!\n" + ex.Message); } }
public void Update(clsDatabase db, string userID) { using (clsQueryResults results = new clsQueryResults()) { string sql1 = "SELECT * FROM TimeLogEntries WHERE EntryID = " + db.ToSql(mEntryID); results.Open(db, sql1); DateTime lastMaint = (DateTime)results.GetColValue("DateTimeLastMaint"); if (lastMaint != DateTimeLastMaint) { throw new Exception("Entry has been modified since retrieval from the database."); } } DateTimeLastMaint = DateTime.Now; string sql2 = "UPDATE TimeLogEntries SET " + "EmployeeID = " + db.ToSql(EmployeeID) + ", DateWorked = " + db.ToSql(DateWorked) + ", HoursWorked = " + db.ToSql(HoursWorked) + ", Billable = " + db.ToSql(Billable) + ", Description = " + db.ToSql(Description) + ", DateTimeLastMaint = " + db.ToSql(DateTimeLastMaint) + " WHERE EntryID = " + db.ToSql(mEntryID); db.ExecuteSQL(sql2); addTimeLogHistory(sql2, userID, db); }
public string GetDataThang(ref DataTable tbl, string SPname) { try { clsDatabase cls = new clsDatabase(); cls.OpenConnect(); string[] Values = new string[] { Convert.ToString(thang), Convert.ToString(nam) }; if (ParasThang.Length != Values.Length) { return("Tham bien va tham tri khong tuong thich"); } else { cls.getValue(ref tbl, SPname, ParasThang, Values); } cls.CloseConnect(); } catch (Exception ex) { error = ex.ToString(); MessageBox.Show("Co loi " + ex.Message); } return(error); }
private void BtnConnect_Click(object sender, EventArgs e) { clsDatabase objDatabase = new clsDatabase(); // is a connection //server, username, database, password of the database (that you used to get into phpmyadmin //try code, if condition is met, output code try { objDatabase.UpdateName(); lblConnection.Text = "Yes!"; lblConnection.ForeColor = Color.Green; } catch (Exception ex) { lblConnection.Text = "No!\n" + ex; lblConnection.ForeColor = Color.Red; } objDatabase.UpdateName(); }
public void Add(clsDatabase db, string userID) { DateTimeLastMaint = DateTime.Now; string sql = "INSERT INTO TimeLogEntries (" + "EmployeeID, " + "DateWorked, " + "HoursWorked, " + "Billable, " + "Description, " + "DateTimeLastMaint" + ") VALUES (" + db.ToSql(EmployeeID) + ", " + db.ToSql(DateWorked) + ", " + db.ToSql(HoursWorked) + ", " + db.ToSql(Billable) + ", " + db.ToSql(Description) + ", " + db.ToSql(DateTimeLastMaint) + ")"; db.ExecuteSQL(sql); addTimeLogHistory(sql, userID, db); mEntryID = getEntryID(db); }
public void Delete(clsDatabase db, string userID) { string sql = "DELETE FROM TimeLogEntries WHERE EntryID = " + db.ToSql(mEntryID); db.ExecuteSQL(sql); addTimeLogHistory(sql, userID, db); }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = int.Parse(e.CommandArgument.ToString()); if (e.CommandName == "Select")//Load dữ liệu lên các control { var ac = new clsDatabase(); SqlDataReader reader = ac.ExecuteReader1(@"SELECT cateID, title, DESCRIPTION, [content],picture,createdate,active from News Where newsid=" + int.Parse(GridView1.Rows[index].Cells[2].Text) + ""); while (reader.Read()) { txtTieuDe.Text = reader[1].ToString(); txtTomTat.Text = reader[2].ToString(); fckNoiDung.Value = reader[3].ToString(); txtDuongDan.Text = reader[4].ToString(); lblcreatedate.Text = reader[5].ToString(); Label2.Text = reader[6].ToString(); } reader.Close(); ViewState["newsid"] = int.Parse(GridView1.Rows[index].Cells[2].Text); LoadDROP(); } else if (e.CommandName == "xoa") { baiviet bv = new baiviet(); bv.Newsid = int.Parse(GridView1.Rows[index].Cells[2].Text); bv.xoabv(bv); //hien thi ra hop thoai da xoa thanh cong. LoadGridView(); } }
private string Execute(ref string records, string StoreProcedureName) { try { clsDatabase cls = new clsDatabase(); cls.OpenConnect(); string[] Values = new string[] { Taikhoan, Matkhau, Quyen }; if (Paras.Length != Values.Length) { return("Tham bien va tham tri khong tuong thich"); } else { cls.ExecuteSP(StoreProcedureName, Paras, Values, ref records); } cls.CloseConnect(); } catch (Exception ex) { error = ex.ToString(); MessageBox.Show("Co loi " + ex.Message); } return(error); }
private string XemMaBacSi(string tenbacsi) { string str = "SELECT Top(1) PK_Bacsi from tblBacsi where Tenbacsi = N'" + tenbacsi + "'"; clsDatabase cls = new clsDatabase(); string kq = cls.Execute_Reader(str); return(kq); }
private string XemTenBacSi(int MaBS) { string str = "SELECT Top(1) Tenbacsi from tblBacsi where PK_Bacsi = " + MaBS; clsDatabase cls = new clsDatabase(); string kq = cls.Execute_Reader(str); return(kq); }
private void LoadThongTinBenhNhan() { if (clsThongTinChung.MaBenhNhan != "") { string str = "SELECT Top(1) Hoten from tblBenhNhan where PK_MaBN = " + clsThongTinChung.MaBenhNhan; clsDatabase cls = new clsDatabase(); textBox1.Text = cls.Execute_Reader(str); } }
private void LoadDataGrid() { clsDatabase cls = new clsDatabase(); clsDatabase cls2 = new clsDatabase(); LoadDataGridViewThang(dataGridView1, "SPThongKeDoanhThuTheoNgay"); LoadDataGridView(dataGridView2, "SPThongKeDoanhThuTheoThang"); cls2.loaddatagridview(dataGridView3, "SPThongKeDoanhThuTheoNam"); }
private void BangGiaKhamBenh_Load(object sender, EventArgs e) { Banggiactrl bg = new Banggiactrl(); bg.LoadDataGridView(dataGridView1, "", "", "", "", ""); LoadDataGridViewFormat(); TrangThaiBanDau(); clsDatabase cls = new clsDatabase(); cls.loadcombobox(comboBox1, "SELECT Distinct(Danghoatdong) FROM tblLoaihinhdichvu", 0); }
private void Bacsi_Load(object sender, EventArgs e) { Bacsictrl bs = new Bacsictrl(); bs.LoadDatagridview(dataGridView1, "", "", "", "", ""); LoadDataGridViewFormat(); TrangThaiBanDau(); clsDatabase cls = new clsDatabase(); cls.loadcombobox(comboBox1, "SELECT * FROM tblLoaihinhdichvu", 2); }
protected void grvDanhSachCanDuyet_RowCommand(object sender, GridViewCommandEventArgs e) { int index = int.Parse(e.CommandArgument.ToString()); var ac = new clsDatabase(); SqlDataReader reader = ac.ExecuteReader1(@"SELECT newsid,[content] from News Where newsid=" + int.Parse(grvDanhSachCanDuyet.Rows[index].Cells[1].Text) + ""); while (reader.Read()) { Editor1.Content = reader[1].ToString(); } reader.Close(); ViewState["newsid"] = int.Parse(grvDanhSachCanDuyet.Rows[index].Cells[1].Text); }
public void addTimeLogHistory(string sqlCommand, string userID, clsDatabase db) { string sql = "INSERT INTO TimeLogHistory (" + "HistoryDateTime, " + "UserID, " + "SqlCommand " + ") VALUES (" + db.ToSql(DateTime.Now.Date) + ", " + db.ToSql(userID) + ", " + db.ToSql(sqlCommand) + ")"; db.ExecuteSQL(sql); }
private void BtnInsert_Click(object sender, EventArgs e) { clsDatabase objDatabase = new clsDatabase(); string sName = txtNewUser.Text; try { objDatabase.InsertUser(sName); lblConnection.Text = "Done!"; lblConnection.ForeColor = Color.Green; } catch (Exception ex) { lblConnection.Text = "Failed!\n" + ex; lblConnection.ForeColor = Color.Red; } }
private int getEntryID(clsDatabase db) { using (clsQueryResults results = new clsQueryResults()) { string sqlGetEntryID = "SELECT MAX(EntryID) AS entryID FROM TimeLogEntries WHERE " + "EmployeeID=" + db.ToSql(EmployeeID) + " AND " + "DateWorked=" + db.ToSql(DateWorked) + " AND " + "HoursWorked=" + db.ToSql(HoursWorked) + " AND " + "Billable=" + db.ToSql(Billable) + " AND " + "Description=" + db.ToSql(Description) + " AND " + "DateTimeLastMaint=" + db.ToSql(DateTimeLastMaint) + ";"; results.Open(db, sqlGetEntryID); int entryID = (int)results.GetColValue("entryID"); return(entryID); } }
/// <summary> /// bấm nút select trên gridview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { //GridView1.Rows[index].Cells[1].Text lấy ra tên user tại cột 1 trong gridview int index = int.Parse(e.CommandArgument.ToString()); var ac = new clsDatabase(); //lấy dữ liệu từ gridview xuống các điều khiển của chương trình tương ứng với username ở cột 1 SqlDataReader reader = ac.ExecuteReader1(@"SELECT Acount.username, Acount.fullname, Acount.email, Acount.ADDRESS FROM Acount where username='******'"); while (reader.Read()) { txtTendangnhap.Text = reader[0].ToString(); txtHoten.Text = reader[1].ToString(); txtEmail.Text = reader[2].ToString(); txtDiaChi.Text = reader[3].ToString(); } reader.Close(); }
public List <clsTimeLogEntry> GetAllEntries(TimeLogDate beginDate, TimeLogDate endDate) { List <clsTimeLogEntry> listBetweenDates = new List <clsTimeLogEntry>(); string sql; using (clsDatabase db = new clsDatabase(mConnectionString)) using (clsQueryResults results = new clsQueryResults()) { db.Open(); sql = "SELECT COUNT(*) AS NumRecords FROM TimeLogEntries WHERE DateWorked >= " + db.ToSql(beginDate) + " AND DateWorked <= " + db.ToSql(endDate); results.Open(db, sql); int count = (int)results.GetColValue("NumRecords"); if (count > 500) { throw new clsTooManyRecordsException("More than 500 matching records found."); } results.Close(); sql = "SELECT * FROM TimeLogEntries WHERE DateWorked >= " + db.ToSql(beginDate) + " AND DateWorked <=" + db.ToSql(endDate) + " ORDER BY DateWorked DESC, EmployeeID, HoursWorked"; results.Open(db, sql); while (results.EOF == false) { clsTimeLogEntry entry = new clsTimeLogEntry(); entry.RestoreStateFromQuery(results); listBetweenDates.Add(entry); results.MoveNext(); } } return(listBetweenDates); }
public void Add(clsTimeLogEntry entry) { using (clsDatabase db = new clsDatabase(mConnectionString)) { try { db.Open(); db.BeginTransaction(); entry.Add(db, UserID); db.CommitTransaction(); } catch { if (db != null) { db.RollbackTransaction(); } throw; } } }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "GioHang") { DataTable dt; clsDatabase cls = new clsDatabase(); if (Session["GioHang"] == null) { dt = cls.GetDataTable(); } else { dt = (DataTable)Session["GioHang"]; } string strProductID, strProductName; int strPrice; int strNumber, strTotal; LinkButton lbt = new LinkButton(); Label lb = new Label(); //Tên sản phẩm lb = (Label)e.Item.FindControl("lbtProductName"); strProductName = lb.Text; //Mã sản phẩm strProductID = cls.LoadDuLieu("select ProductID from tbProduct where ProductName='" + strProductName + "'", 0); //Giá lb = (Label)e.Item.FindControl("lbPrice"); strPrice = int.Parse(lb.Text); //Số lượng strNumber = 1; //Tổng tiền strTotal = strNumber * strPrice; cls.DienVaoBang(dt, strProductID, strProductName, strPrice, strNumber, strTotal); Session["GioHang"] = dt; Response.Redirect("Cart.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { clsDatabase dbconn = new clsDatabase(); }
// Performs a query and sets the current record/row pointer to the first one. public void Open(clsDatabase db, string sqlQuery) { mDataReader = db.ExecuteQuery(sqlQuery); MoveNext(); }
private string ReadINFLOConfigurationFiles() { //Configuration files variables string RoadwayLinkConfigFile = string.Empty; string DetectorStationConfigFile = string.Empty; string DetectionZoneConfigFile = string.Empty; string MileMarkerConfigFile = string.Empty; string retValue = string.Empty; //txtINFLOConfigFile.Text = clsGlobalVars.INFLOConfigFile; //txtINFLOConfigFile.Refresh(); #region "Read the INFLO configuration file" INFLOConfigurationFile = Application.StartupPath + "\\Config\\INFLOConfig.xml"; //txtINFLOConfigFile.Text = Application.StartupPath + "\\Config\\INFLOConfig.xml"; txtINFLOConfigFile.Text = INFLOConfigurationFile; txtINFLOConfigFile.Refresh(); LogTxtMsg(txtLog, "\r\nReading the contents of the INFLO configuration file: " + clsGlobalVars.INFLOConfigFile); if (clsGlobalVars.INFLOConfigFile.Length > 0) { //retValue = clsMiscFunctions.ReadINFLOConfigFile(clsGlobalVars.INFLOConfigFile, ref Roadway); retValue = clsMiscFunctions.ReadINFLOConfigFile(INFLOConfigurationFile, ref Roadway); if (retValue.Length > 0) { return(retValue); } RoadwayLinkConfigFile = clsGlobalVars.RoadwayLinkConfigFile; txtRoadwayLinkConfigFile.Text = RoadwayLinkConfigFile; txtRoadwayLinkConfigFile.Refresh(); DetectorStationConfigFile = clsGlobalVars.DetectorStationConfigFile; txtDetectionStationConfigFile.Text = DetectorStationConfigFile; txtDetectionStationConfigFile.Refresh(); DetectionZoneConfigFile = clsGlobalVars.DetectionZoneConfigFile; txtDetectionZoneConfigFile.Text = DetectionZoneConfigFile; txtDetectionZoneConfigFile.Refresh(); MileMarkerConfigFile = clsGlobalVars.MileMarkerConfigFile; } else { retValue = "\tThe INFLO configuration file name was not specified in the Global variables class."; return(retValue); } #endregion #region "Establish connection to INFLO database" LogTxtMsg(txtLog, "\r\n\tEstablish connection to the INFLO database: " + "\r\n\t\tDBInterfaceType: " + clsGlobalVars.DBInterfaceType + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.AccessDBFileName + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.DSNName + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.SqlServer + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.SqlServerDatabase + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.SqlServerUserId + "\r\n\t\tAccessDBFileName: " + clsGlobalVars.SqlStrConnection); if (clsGlobalVars.DBInterfaceType.Length > 0) { DB = new clsDatabase(clsGlobalVars.DBInterfaceType); if (DB.ConnectionStr.Length > 0) { LogTxtMsg(txtLog, "\r\n\tDatabase Connection string: " + DB.ConnectionStr); retValue = DB.OpenDBConnection(); if (retValue.Length > 0) { return(retValue); } } else { retValue = "\r\n\tError in generating connection string to INFLO database."; return(retValue); } } else { retValue = "\tThe INFLO Application can not connect to the INFLO database. " + "\r\n\tThe DBInterfaceType= " + clsGlobalVars.DBInterfaceType + " is not specified."; return(retValue); } #endregion #region "Read the Roadway Link configuration file" LogTxtMsg(txtLog, "\r\n\tRead the contents of the Roadway Link configuration file."); if (RoadwayLinkConfigFile.Length > 0) { retValue = clsMiscFunctions.ReadRoadwayLinkConfigFile(clsGlobalVars.RoadwayLinkConfigFile, ref RLList); if (retValue.Length > 0) { return(retValue); } } else { retValue = "\tThe INFLO Roadway Link configuration file name was not specified in the INFLO configuration file."; return(retValue); } #endregion #region "Read Detector Station configuration file" LogTxtMsg(txtLog, "\r\n\tRead the contents of the Detector Station configuration file."); if (clsGlobalVars.DetectorStationConfigFile.Length > 0) { retValue = clsMiscFunctions.ReadDetectorStationConfigFile(clsGlobalVars.DetectorStationConfigFile, ref DSList); if (retValue.Length > 0) { return(retValue); } } else { retValue = "\tThe INFLO Detector Station configuration file name was not specified in the INFLO configuration file."; return(retValue); } #endregion #region "Read Detection Zones configuration file" LogTxtMsg(txtLog, "\r\n\tRead the contents of the Detection Zones configuration file."); if (DetectionZoneConfigFile.Length > 0) { retValue = clsMiscFunctions.ReadDetectionZonesConfigFile(clsGlobalVars.DetectionZoneConfigFile, ref DZList); if (retValue.Length > 0) { return(retValue); } } else { retValue = "\tThe INFLO Detection Zones configuration file name was not specified in the INFLO configuration file."; return(retValue); } #endregion #region "Read MileMarker configuration file" LogTxtMsg(txtLog, "\r\n\tRead the contents of the Mile Marker configuration file."); if (MileMarkerConfigFile.Length > 0) { retValue = clsMiscFunctions.ReadMileMarkerConfigFile(clsGlobalVars.MileMarkerConfigFile, ref MMList); if (retValue.Length > 0) { return(retValue); } } else { retValue = "\tThe INFLO MileMarker configuration file name was not specified in the INFLO configuration file."; return(retValue); } #endregion LogTxtMsg(txtLog, "\r\nFinished processing the INFLO Application configuration files"); #region "Load Roadway info into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the Roadway info into the INFLO database."); retValue = clsMiscFunctions.LoadRoadwayInfoIntoINFLODatabase(Roadway, ref DB); if (retValue.Length > 0) { return(retValue); } #endregion #region "Load Roadway Sub Link info into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the Roadway Sub Link info into the INFLO database."); retValue = clsMiscFunctions.LoadRoadwaySubLinkInfoIntoINFLODatabase(Roadway, ref DB); if (retValue.Length > 0) { return(retValue); } #endregion #region "Load Roadway Link info into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the Roadway Link info into the INFLO database."); retValue = clsMiscFunctions.LoadRoadwayLinkInfoIntoINFLODatabase(RLList, ref DB); if (retValue.Length > 0) { return(retValue); } #endregion #region "Load Detector Station info into INFLO database" /*LogTxtMsg(txtLog, "\r\n\tLoad the Detector Station info into the INFLO database."); * retValue = clsMiscFunctions.LoadDetectorStationInfoIntoINFLODatabase(DSList, ref DB); * if (retValue.Length > 0) * { * return retValue; * }*/ #endregion #region "Load Detection Zone info into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the Detection Zone info into the INFLO database."); retValue = clsMiscFunctions.LoadDetectionZoneInfoIntoINFLODatabase(DZList, ref DB); if (retValue.Length > 0) { return(retValue); } #endregion #region "Load MileMarker info into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the Mile Marker info into the INFLO database."); retValue = clsMiscFunctions.LoadMileMarkerInfoIntoINFLODatabase(MMList, ref DB); if (retValue.Length > 0) { return(retValue); } #endregion #region "Load INFLO Thresholds into INFLO database" LogTxtMsg(txtLog, "\r\n\tLoad the INFLO thresholds and parameters into the INFLO database."); retValue = clsMiscFunctions.LoadThresholdsIntoINFLODatabase(ref DB); if (retValue.Length > 0) { return(retValue); } #endregion LogTxtMsg(txtLog, "\r\nFinished loading the INFLO configuration parameters into the INFLO database"); return(retValue); }
private void LoadBacSi() { clsDatabase cls = new clsDatabase(); cls.loadcombobox(comboBox1, "SELECT * FROM tblBacsi", 1); }