public static Boolean OneDocument() { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if ((myStream = openFileDialog1.OpenFile()) != null) { using (myStream) { Storage sensor_info = new Storage(); String[] file = File.ReadAllLines(openFileDialog1.FileName); SensorAskingPopup popup = new SensorAskingPopup(sensor_info); popup.ShowDialog(); InsertInDataBase.rapport(DataBaseConnect.getInstance(), file, sensor_info); } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); return(false); } } return(true); }
/// <summary> /// Авторизация /// </summary> /// <returns>Возвращает кортеж - первый элемент булево значение, второй - список элементов</returns> public Tuple <bool, List <string> > LogIn() { List <string> userData = new List <string>(); string HLogin, HPassword; try { HLogin = EncryptionData.EncryptLogin(Login, Password); HPassword = EncryptionData.EncryptPassword(Login, Password); DataBaseConnect DBC = new DataBaseConnect(GetConnectionString.getStringConnectionData()); userData = new List <string>(DBC.getUserInfoFromDataBase(HLogin, HPassword)); getEmergencyAuthData(); if (userData != null) { return(Tuple.Create(true, userData)); } else { return(Tuple.Create(false, userData)); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Пользователь не найден", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(Tuple.Create(false, userData)); } }
static internal System.Data.DataTable SelectVall(string tableName, System.Collections.Generic.List <string> selectedCOll, System.Collections.Generic.Dictionary <string, string> WhereCouple) { var(collumn, where) = DataBaseHelper. SelectFormateHelper(selectedCOll, WhereCouple); var dt = new System.Data.DataTable(); using (var connection = DataBaseConnect.Connect()) { try { connection.Open(); var command = new SqlCommand( string.Format(DataBaseConstants.SelectQuery, collumn, tableName, where), connection); SqlDataAdapter da = new SqlDataAdapter(command); da.Fill(dt); } catch (System.Exception e) { connection.Close(); throw e; } } return(dt); }
/// <summary> /// instancie une commande afin de la serialiser par la suite pour les services de traitement. /// </summary> /// <param name="shipping"></param> /// <param name="facturation"></param> /// <param name="creditcard"></param> /// <param name="books"></param> public Order(ContactDetails shipping, ContactDetails invoicing, string creditcard, Book[] books) { this.shipping = shipping; this.invoicing = invoicing; this.creditcard = creditcard; this.books = books; this.ordernumber = Guid.NewGuid().ToString(); database = new DataBaseConnect(); }
public UserServiceUpdater() { funcList = new Dictionary <string, UpdateFunction>(); db = new DataBaseConnect(SaveLog); redis = new RedisConnect(SaveLog); hashTransfer = new RedisHashTransfer(); }
public RideServiceChecker() { funcList = new Dictionary <string, CheckFunction>(); db = new DataBaseConnect(SaveLog); redis = new RedisConnect(SaveLog); hashTransfer = new RedisHashTransfer(); }
/// <summary> /// Тест соединения с БД при запуске. /// </summary> private void TCDB() { DataBaseConnect DBC = new DataBaseConnect(_connection); if (!DBC.TestConnection()) { MessageBox.Show("Соединение с базой данных невозможно. Вход только по дежерному паролю", "Сервер баз данных не отвечает", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static MySqlDataAdapter ByDate(DateTime startDate, DateTime endDate, String id_sensor) { String strStartDate = MapToDataBase.MapDate(startDate); String strEndDate = MapToDataBase.MapDate(endDate); String sql_query = "SELECT * FROM dataline WHERE dataline.dateTime >= '" + strStartDate + "' AND dataline.dateTime <= '" + strEndDate + "'" + " AND dataline.idSensor = '" + id_sensor + "'"; MySqlCommand dataFromBase = SelectInDataBase.WithParameter(sql_query, DataBaseConnect.getInstance()); return(DataBaseToWinForm.Transform(dataFromBase)); }
/// <summary> /// Выполняет проверку соеднения с сервером баз данных /// </summary> /// <param name="field">List textbox'ов</param> /// <returns>Если соединение установлено, возвращает true, иначе false</returns> private bool TestConnectToDb(List <TextBox> field) { //TODO: codereview + error Connect; DataBaseConnect DBC = new DataBaseConnect(GetConnectionString.getStringConnectionData(field[0].Text, field[1].Text, field[2].Text, field[3].Text)); if (DBC.TestConnection()) { return(true); } return(false); }
/// <summary> /// 获取数据库列表 /// </summary> public static List <string> GetDataBaseList(DataBaseConnect model) { List <string> list = new List <string>(); var sql = "SELECT name FROM SYSDATABASES "; DataSet ds = ExecuteSQLDataSet(GetDbConnect(model), sql); if (ds == null || ds.Tables.Count == 0) { return(null); } foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(dr["name"].ToString()); } return(list); }
/// <summary> /// 获取数据库所有表名称 /// </summary> public static List <string> GetTableList(DataBaseConnect model) { List <string> list = new List <string>(); var sql = @"SELECT name FROM sysobjects WHERE xtype = 'U' ORDER BY crdate DESC"; DataSet ds = ExecuteSQLDataSet(GetDbConnect(model), sql); if (ds == null || ds.Tables.Count == 0) { return(null); } foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(dr["name"].ToString()); } return(list); }
static internal void InsertInTable(string tableName, System.Collections.Generic.Dictionary <string, string> InsertCoup) { var(Coll, vall) = DataBaseHelper.InsertFormateHelper(InsertCoup); using (SqlConnection connection = DataBaseConnect.Connect()) { try { connection.Open(); SqlCommand command = new SqlCommand( string.Format(DataBaseConstants.InsertQuery, tableName, Coll, vall), connection); command.ExecuteNonQuery(); } catch (System.Exception e) { connection.Close(); throw e; } } }
static internal void DeleteInTable(string tableName, System.Collections.Generic.Dictionary <string, string> WhereCouple) { string WhereCond = DataBaseHelper.WhereFormateHelper(WhereCouple); using (SqlConnection connection = DataBaseConnect.Connect()) { try { connection.Open(); SqlCommand command = new SqlCommand( string.Format(DataBaseConstants.DellQuery, tableName, WhereCond), connection); command.ExecuteNonQuery(); } catch (System.Exception e) { connection.Close(); throw e; } } }
public MainWindow() { InitializeComponent(); using (var connection = DataBaseConnect.Connect()) { try { connection.Open(); var command = new SqlCommand( DataBaseConstants.SelectTableAndColumnName, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { DataBaseConstants.hint = new System.Collections.ObjectModel.ObservableCollection <CoupleTwoValues>(); while (reader.Read()) { string buf_coll_name = (string)reader.GetValue(1); if (buf_coll_name != "is_zip") { DataBaseConstants.hint. Add(new CoupleTwoValues { First = (string)reader.GetValue(0), Second = buf_coll_name }); } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Error"); } } SelectGrid.IsReadOnly = true; }
static internal System.Data.DataTable RunAdvancedQuery(string Query) { var dt = new System.Data.DataTable(); using (var connection = DataBaseConnect.Connect()) { try { connection.Open(); var command = new SqlCommand( Query, connection); SqlDataAdapter da = new SqlDataAdapter(command); da.Fill(dt); } catch (System.Exception e) { connection.Close(); throw e; } } return(dt); }
public bool Initialize() { bool bReturn = false; try { log = new Logger(fm1); log.SaveLog($"Controller Version: {version}"); wsServer = new Server(this); dbConnect = new DataBaseConnect(log); if (dbConnect.Initialize()) { if (dbConnect.Connect()) { if (wsServer.Initialize()) { bReturn = true; } } } if (!bReturn) { log.SaveLog("[Error] Controller::Initialize, Initialize Fail"); } } catch (Exception ex) { log.SaveLog($"[Error] Controller::Initialize, Catch Error, Msg:{ex.Message}"); } return(bReturn); }
static internal void UpdateInTable(string tableName, System.Collections.Generic.Dictionary <string, string> Value, System.Collections.Generic.Dictionary <string, string> where) { string Values = DataBaseHelper.UpdateFormateHelper(Value); string StringWhere = DataBaseHelper.WhereFormateHelper(where); using (SqlConnection connection = DataBaseConnect.Connect()) { try { connection.Open(); SqlCommand command = new SqlCommand( string.Format(DataBaseConstants.UpdQuery, tableName, Values, StringWhere), connection); command.ExecuteNonQuery(); } catch (System.Exception e) { connection.Close(); throw e; } } }
public static MySqlDataAdapter all() { MySqlCommand dataFromBase = SelectAll.Data(DataBaseConnect.getInstance()); return(DataBaseToWinForm.Transform(dataFromBase)); }
/// <summary> /// Получает описание устройства по инвентарному номеру /// </summary> /// <param name="InventoryId">String, инвентарный номер устройства</param> /// <returns></returns> public static string GetDeviceDescription(string InventoryId) { DataBaseConnect DBC = new DataBaseConnect(GetConnectionString.getStringConnectionData()); return(DBC.getGetDeviceData("description", InventoryId)); }
/// <summary> /// Получает имя производителя устройства по инвентарному номеру /// </summary> /// <param name="invent"></param> /// <returns></returns> public static string GetDeviceManufacturer(string InventoryId) { DataBaseConnect DBC = new DataBaseConnect(GetConnectionString.getStringConnectionData()); return(DBC.getGetDeviceData("manufacturer", InventoryId)); }
/** * 使用者加入 */ private void OnJoinService(JoinService packet) { JoinServiceResult rData = new JoinServiceResult(); rData.Result = 0; DataBaseConnect dbConnect = sev.GetController().GetDataBase(); try { List <UserAccount> accountList = dbConnect.GetSql().Queryable <UserAccount>().Where(it => it.Email == packet.Email && it.Password == packet.Password).ToList(); // 有找到帳號 if (accountList.Count() == 1) { if (accountList[0].Password == packet.Password) { List <UserInfo> infoList = dbConnect.GetSql().Queryable <UserInfo>().Where(it => it.MemberID == accountList[0].MemberID).ToList(); // 有找到會員 if (infoList.Count() == 1) { if (sev.AddMember(teamID, memberID, this)) { rData.Result = 1; SaveLog($"[Info] ClientHandler::onUserJoin, Add Member:{memberID} Success"); } else { SaveLog($"[Warning] ClientHandler::onUserJoin, Add Member:{memberID} Fail"); } } else { SaveLog("[Warning] ClientHandler::onUserJoin, Can't Find User Info"); rData.Result = 0; } } else { rData.Result = 3; SaveLog("[Info] ClientHandler::onUserJoin, Can't Password Error"); } } else { rData.Result = 2; } } catch (Exception ex) { SaveLog($"[Error] ClientHandler::onUserJoin, Catch Error, Msg:{ex.Message}"); } JObject jsMain = new JObject(); jsMain.Add("CmdID", (int)S2C_CmdID.emJoinServiceResult); jsMain.Add("Data", JsonConvert.DeserializeObject <JObject>(JsonConvert.SerializeObject(rData))); Send(jsMain.ToString()); // 加入失敗 if (rData.Result != 1) { //SaveLog($"[Warning] ClientHandler::onUserJoin, Can Not Find Member"); // 強制斷線 } }
/// <summary> /// Constructeur par defaut necessaire pour la serialisation du service web et celle pour le soap /// </summary> public Order() { database = new DataBaseConnect(); }
/// <summary> /// Constructeur par defaut necessaire pour la serialisation du service web /// </summary> public Library() { dataBase = new DataBaseConnect(); }
public static string GetDbConnect(DataBaseConnect model) { string sql = "data source={0};initial catalog={1};persist security info=True;user id={2};password={3};pooling=true;min pool size=1;max pool size=1000"; return(string.Format(sql, model.DataSource, model.DataBase, model.UserName, model.Password)); }