public void GetTables() { MySqlService mySqlService = new MySqlService(); var tables = mySqlService.GetTables(connectionInfo, "sys"); CollectionAssert.Contains(tables, "sys_config"); }
public override string OnResponse(string data) { DefaultReq defaultReq = null; try { defaultReq = JsonConvert.DeserializeObject <DefaultReq>(data); } catch (Exception e) { MySqlService.log.Warn("传入的参数有误:" + e); return(null); } MySqlService.InitCommomData(); string _tag = defaultReq.tag; int _connId = defaultReq.connId; JObject _responseData = new JObject(); _responseData.Add(MyCommon.TAG, _tag); _responseData.Add(MyCommon.CONNID, _connId); _responseData.Add(MyCommon.CODE, (int)Consts.Code.Code_OK); return(_responseData.ToString()); }
/// <summary> /// Adds a service to the list of services. /// </summary> /// <param name="service">Service to add.</param> /// <param name="machine">Machine containing the service.</param> /// <param name="setPage">Flag indicating if the Services tab must be focused.</param> private void AddService(MySqlService service, Machine machine, bool setPage) { if (service == null) { return; } if (service.Host == null) { service.Host = machine; service.SetServiceParameters(true); } ListViewItem newItem = new ListViewItem(service.DisplayName) { Tag = service }; newItem.SubItems.Add(machine.Name); newItem.SubItems.Add(service.Status.ToString()); MonitoredServicesListView.Items.Add(newItem); if (!setPage) { return; } ItemsTabControl.SelectedIndex = 0; newItem.Selected = true; }
public void GetDatabases() { MySqlService mySqlService = new MySqlService(); var databases = mySqlService.GetDatabases(connectionInfo); CollectionAssert.Contains(databases, "sys"); }
public void GetViews() { MySqlService mySqlService = new MySqlService(); var views = mySqlService.GetViews(connectionInfo, "sys"); CollectionAssert.Contains(views, "host_summary"); }
//tag(string):SupplyGold //uid(string) //todayCount(int) //goldNum(int) public static void SendSupplyGold(string uid) { UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid); if (userInfo.Gold < 1500) { var config = NHibernateHelper.commonConfigManager.GetByUid(uid); if (config == null) { config = ModelFactory.CreateConfig(uid); } if (config.free_gold_count > 0) { userInfo.Gold += 2000; config.free_gold_count--; NHibernateHelper.commonConfigManager.Update(config); NHibernateHelper.userInfoManager.Update(userInfo); MySqlService.log.Info($"{uid}发放补助金"); //给logic服务器推送 IntPtr connId; if (MySqlService.serviceDic.TryGetValue(TljServiceType.LogicService, out connId)) { var jObject = new JObject(); jObject.Add(MyCommon.TAG, Consts.Tag_SupplyGold); jObject.Add(MyCommon.UID, uid); int temp = 0; if (config.free_gold_count == 2) { temp = 1; } else if (config.free_gold_count == 1) { temp = 2; } else if (config.free_gold_count == 0) { temp = 3; } jObject.Add("todayCount", temp); jObject.Add("goldNum", 2000); MySqlService.Instance().sendMessage(connId, jObject.ToString()); MySqlService.log.Info($"主动发送给logic:{jObject.ToString()}"); //记录玩家财富变化日志 int afterGold = userInfo.Gold; int changeGold = 2000; StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, "奖励金发放", afterGold - changeGold, changeGold, afterGold); } } } }
public static void Main(string[] args) { PrintGreeting(); if (!MySqlService.IsInstalled()) { Console.WriteLine("MySQL server is not installed in your computer."); MySqlService.InstallMySql(); } BuildWebHost(args).Run(); }
private void btn_Refresh_Click(object sender, EventArgs e) { btn_Refresh.Enabled = false; try { string connectionString = string.Concat("Server=", txb_Server.Text, ";Database=information_schema", ";Uid=", txb_Username.Text, ";Pwd=", txb_Password.Text, ";"); IAdoService adoService = new MySqlService(); cbb_Database.DataSource = adoService.GetAllDatabase(connectionString); } catch (Exception ex) { MessageBox.Show(ex.Message); } btn_Refresh.Enabled = true; }
public static void insertOrder(int chair, int table, int sofa, int totalsum) { MySqlConnection con = MySqlService.getConnection(); con.Open(); MySqlCommand comm = con.CreateCommand(); comm.CommandText = "INSERT INTO uzsakymai(kedes,stalai,sofos,suma) VALUES(@kedes, @stalai, @sofos, @suma)"; comm.Parameters.AddWithValue("@kedes", chair); comm.Parameters.AddWithValue("@stalai", table); comm.Parameters.AddWithValue("@sofos", sofa); comm.Parameters.AddWithValue("@suma", totalsum); comm.ExecuteNonQuery(); con.Close(); }
public static void insertOrder(int chair, int table, int sofa, int totalsum) { using (MySqlConnection con = MySqlService.getConnection()) { try { con.Open(); AddBaldas(chair, table, sofa, totalsum, con); MessageBox.Show("Your order was placed"); } catch (Exception e) { MessageBox.Show("Unable to connect to MySql"); } } }
/// <summary> /// Event delegate method fired when the <see cref="UpdateTrayIconCheckBox"/> checked status changes. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void UpdateTrayIconCheckBox_CheckedChanged(object sender, EventArgs e) { if (_selectedItem == null) { return; } if (_selectedItem is MySqlService) { MySqlService selectedService = _selectedItem as MySqlService; selectedService.UpdateTrayIconOnStatusChange = UpdateTrayIconCheckBox.Checked; _servicesHaveChanges = true; } else if (_selectedItem is MySqlInstance) { MySqlInstance selectedInstance = _selectedItem as MySqlInstance; selectedInstance.UpdateTrayIconOnStatusChange = UpdateTrayIconCheckBox.Checked; _instancesHaveChanges = true; } }
/// <summary> /// Event delegate method fired when the <see cref="NotifyOnStatusChangeCheckBox"/> checked status changes. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void NotifyOnStatusChangeCheckBox_CheckedChanged(object sender, EventArgs e) { if (_selectedItem == null) { return; } if (_selectedItem is MySqlService) { MySqlService selectedService = _selectedItem as MySqlService; selectedService.NotifyOnStatusChange = NotifyOnStatusChangeCheckBox.Checked; _servicesHaveChanges = true; } else if (_selectedItem is MySqlInstance) { MySqlInstance selectedInstance = _selectedItem as MySqlInstance; selectedInstance.MonitorAndNotifyStatus = NotifyOnStatusChangeCheckBox.Checked; _instancesHaveChanges = true; } }
public static List <Baldas> getBaldai() { using (MySqlConnection con = MySqlService.getConnection()) { using (MySqlCommand cmd = new MySqlCommand("select Pavadinimas, Kaina, Laikas from baldai", con)) { try { con.Open(); return(extractBaldai(cmd)); } catch (Exception e) { MessageBox.Show("Unable to connect to MySql"); List <Baldas> baldai = new List <Baldas>(); baldai.Add(new Baldas(Tipas.DESK, 10, 5)); baldai.Add(new Baldas(Tipas.CHAIR, 10, 5)); baldai.Add(new Baldas(Tipas.SOFA, 10, 5)); return(baldai); } } } }
/// <summary> /// Sets the availability of controls related to services or instances based on the selected item. /// </summary> private void SetDialogControlsAvailability() { DeleteButton.Enabled = _selectedItem != null; NotifyOnStatusChangeCheckBox.Enabled = DeleteButton.Enabled; UpdateTrayIconCheckBox.Enabled = DeleteButton.Enabled; if (_selectedItem == null) { NotifyOnStatusChangeCheckBox.Checked = false; UpdateTrayIconCheckBox.Checked = false; InstanceMonitorIntervalNumericUpDown.Value = 0; InstanceMonitorIntervalNumericUpDown.Enabled = false; InstanceMonitorIntervalUOMComboBox.Text = string.Empty; InstanceMonitorIntervalUOMComboBox.Enabled = false; } else if (_selectedItem is MySqlService) { MySqlService service = _selectedItem as MySqlService; NotifyOnStatusChangeCheckBox.Checked = service.NotifyOnStatusChange; UpdateTrayIconCheckBox.Checked = service.UpdateTrayIconOnStatusChange; InstanceMonitorIntervalNumericUpDown.Value = 0; InstanceMonitorIntervalNumericUpDown.Enabled = false; InstanceMonitorIntervalUOMComboBox.Text = string.Empty; InstanceMonitorIntervalUOMComboBox.Enabled = false; } else if (_selectedItem is MySqlInstance) { MySqlInstance instance = _selectedItem as MySqlInstance; NotifyOnStatusChangeCheckBox.Checked = instance.MonitorAndNotifyStatus; UpdateTrayIconCheckBox.Checked = instance.UpdateTrayIconOnStatusChange; InstanceMonitorIntervalNumericUpDown.Enabled = true; InstanceMonitorIntervalNumericUpDown.Value = instance.MonitoringInterval; InstanceMonitorIntervalUOMComboBox.Enabled = true; InstanceMonitorIntervalUOMComboBox.SelectedIndex = (int)instance.MonitoringIntervalUnitOfMeasure; } }
public static DataTable getOrderTable() { using (MySqlConnection con = MySqlService.getConnection()) { try { con.Open(); MySqlDataAdapter MyDA = new MySqlDataAdapter(); string sqlSelectAll = "SELECT * from uzsakymai"; MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, con); DataTable table = new DataTable(); MyDA.Fill(table); return(table); } catch (Exception e) { MessageBox.Show("Unable to connect to MySql"); return(new DataTable()); } } }
static void Main(string[] args) { try { var argList = ReadArgs(args); if (argList == null) { return; } var dbType = GetSwitchInput(argList, "-t", "Database Type:\n1. SQL Server\n2. MySQL\n3. PostgreSQL", new Dictionary <string, string> { { "1", _msSql }, { "2", _mySql }, { "3", _postgreSql } }); var connectionString = GetInput(argList, "-c", "ConnectionString:", optional: true); var skip = !string.IsNullOrWhiteSpace(connectionString); var setting = new DatabaseSettingModel { ConnectionString = connectionString, DbType = dbType, HostString = GetInput(argList, "-s", "Server name or IP address:", skip: skip), DatabaseName = GetInput(argList, "-d", "Database name:", skip: skip && dbType == _msSql), UserName = GetInput(argList, "-u", "Username:"******"-p", "Password:"******"Can't get any table info"); } IExporter exporter = new HtmlExporter(); var stream = exporter.Export(setting, tableInfos); stream.Seek(0, SeekOrigin.Begin); using (var fileStream = new FileStream($"{setting.DatabaseName}.html", FileMode.Create)) { stream.CopyTo(fileStream); } } catch (Exception e) { Console.WriteLine(e.ToString()); System.Threading.Thread.Sleep(5000); } }
private void cbDatabase_DropDownOpened(object sender, EventArgs e) { cbDatabase.ItemsSource = new List <string> { "<Loading databases>" }; var sel = Enum.Parse <ConnectionProvider>(cbProvider.SelectedItem.ToString()); try { switch (sel) { case ConnectionProvider.MsSql: var conInfo = new MsSqlConnectionInfo { Server = txtServer.Text, Port = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text), TrustedConnection = chkIntegratedSecurity.IsChecked.Value, Username = txtUsername.Text, Password = txtPassword.Password }; var mssql = new MsSqlService(); cbDatabase.ItemsSource = mssql.LoadDatabase(conInfo); break; case ConnectionProvider.PostgreSql: var npgInfo = new NpgConnectionInfo { Server = txtServer.Text, Port = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text), TrustedConnection = chkIntegratedSecurity.IsChecked.Value, Username = txtUsername.Text, Password = txtPassword.Password }; var npgsql = new NpgService(); cbDatabase.ItemsSource = npgsql.LoadDatabase(npgInfo); break; case ConnectionProvider.MySql: if (chkIntegratedSecurity.IsChecked == true) { throw new InvalidOperationException("Integrated Security doesnt supported by MySql Server"); } var myInfo = new MySqlConnectionInfo { Server = txtServer.Text, Port = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text), Username = txtUsername.Text, Password = txtPassword.Password }; var mysql = new MySqlService(); cbDatabase.ItemsSource = mysql.LoadDatabase(myInfo); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public List <EJ.DBColumn> GetCurrentColumns(IDatabaseService db, string tablename) { var dbnameMatch = System.Text.RegularExpressions.Regex.Match(db.ConnectionString, @"database=(?<dname>(\w)+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase); var dbname = dbnameMatch.Groups["dname"].Value; MySqlService mySqlService = (MySqlService)db; List <EJ.DBColumn> result = new List <EJ.DBColumn>(); var table = db.SelectTable($"select * from information_schema.COLUMNS where TABLE_SCHEMA='{dbname}' and TABLE_NAME='{tablename}'"); //获取主键 var pkcolumnName = db.ExecSqlString(@"SELECT C.COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c WHERE c.CONSTRAINT_SCHEMA = '" + dbname + @"' AND c.CONSTRAINT_NAME = 'PRIMARY' AND c.TABLE_NAME = '" + tablename + @"' ")?.ToString(); foreach (var row in table.Rows) { EJ.DBColumn column = new EJ.DBColumn(); column.Name = row["COLUMN_NAME"].ToSafeString(); column.CanNull = row["IS_NULLABLE"].ToSafeString() == "YES"; column.dbType = row["DATA_TYPE"].ToSafeString().ToLower(); column.caption = row["COLUMN_COMMENT"]?.ToString(); int typeindex = -1; for (int i = 0; i < Database.MySql.MySqlTableService.ColumnType.Count; i++) { if (string.Equals(Database.MySql.MySqlTableService.ColumnType[i], column.dbType, StringComparison.CurrentCultureIgnoreCase)) { typeindex = i; break; } } if (typeindex >= 0) { column.dbType = EntityDB.Design.ColumnType.SupportTypes[typeindex]; } else if (column.dbType.EndsWith("int")) { column.dbType = "int"; } else if (column.dbType == "enum" || column.dbType == "set") { column.dbType = "varchar"; } else { for (int i = 0; i < Way.EntityDB.Design.ColumnType.SupportTypes.Count; i++) { if (string.Equals(Way.EntityDB.Design.ColumnType.SupportTypes[i], column.dbType, StringComparison.CurrentCultureIgnoreCase)) { typeindex = i; break; } } if (typeindex >= 0) { column.dbType = EntityDB.Design.ColumnType.SupportTypes[typeindex]; } else { column.dbType = "[未识别]" + column.dbType; } } column.defaultValue = row["COLUMN_DEFAULT"].ToSafeString(); column.IsAutoIncrement = row["EXTRA"].ToSafeString().Contains("auto_increment"); if (!string.IsNullOrEmpty(pkcolumnName)) { column.IsPKID = column.Name == pkcolumnName; } if (column.dbType.Contains("char")) { column.length = row["CHARACTER_MAXIMUM_LENGTH"].ToSafeString(); } column.ChangedProperties.Clear(); result.Add(column); } return(result); }