private void pgPara_SelectionChanged(object sender, DataRowSelectionChangedArgs e) { try { if (e.Row == null) { return; } var group = ((ConfigParaKeyValue)e.Row).Group; if (group == null) { ((ConfigParaKeyValue)e.Row).Group = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comboBoxParaGroup); } else { DropdownBoxHelper.SetGenericToComboBox(comboBoxParaGroup, group); } } catch (Exception ex) { MessageBox.Show(ex.Message); Loger.Error(ex); } }
private void btnTableInfo_Click(object sender, EventArgs e) { try { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); var tableInfoList = dbAccess.Database.GetTableInfoList(ckGetFieldInfo.Checked); StringBuilder sb = new StringBuilder(); sb.AppendLine("----------------------------------------------------------------------------"); sb.AppendLine($"[{config.ConName}] [{tableInfoList.Count}]"); sb.AppendLine("----------------------------------------------------------------------------"); foreach (var tableInfo in tableInfoList) { sb.AppendLine($"[TableName:{tableInfo.Name}]"); sb.AppendLine($"[Comments:{tableInfo.Comments}]"); sb.AppendLine($"[PriKeyField:{string.Join(";", tableInfo.PriKeyFieldInfos.Select(t => { return t.FieldName; })) }]"); sb.AppendLine($"[Field:{string.Join(";", tableInfo.DbFieldInfos.Select(t => { return t.FieldName; })) }]"); string tmp = tableInfo.Indexs == null ? string.Empty : string.Join("; ", tableInfo.Indexs.Select(t => { return($"{t.IndexName}:{t.FieldName}"); })); sb.AppendLine($"[Index:{tmp }]"); sb.AppendLine("----------------------------------------------------------------------------"); } Loger.Info(sb.ToString()); } catch (Exception ex) { Loger.Error(ex); } }
private void btnTest_Click(object sender, EventArgs e) { try { //string pluginAssemblyPath = @"D:\qwe\abc.dll"; //DBAccessManager.LoadDBPlugin(pluginAssemblyPath); //pluginAssemblyPath = @"qwe\abc.dll"; //DBAccessManager.LoadDBPlugin(pluginAssemblyPath); var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); //IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); //string sql = @"SELECT A.* FROM user_indexes A WHERE TABLE_NAME='STU'"; //DataTable dt = dbAccess.QueryDataToDataTable(sql); //DataColumn[] colArr = new DataColumn[dt.Columns.Count]; //dt.Columns.CopyTo(colArr, 0); //string[] colNameArr = colArr.Select(t => { return t.ColumnName; }).ToArray(); //string str = string.Join(",A.", colNameArr); //Loger.Info(str); //IDBInteraction interaction = DBFactoryManager.GetDBFactory(config).GetDBInteraction(); //string conStr = interaction.GenerateDBConStr(config, DBVisitType.R); //Port=5432;Host=localhost;Username=postgres;Password=qwe123;Database=postgres //using (var con = new Npgsql.NpgsqlConnection(conStr)) //{ // con.Open(); // var cmd = con.CreateCommand(); // cmd.CommandText = "select CURRENT_TIMESTAMP"; // object obj = cmd.ExecuteScalar(); //} bool ret; try { //var config = DatabaseConfigManager.GetConfig(Config.Instance.DBID); UtilZ.Dotnet.DBIBase.Factory.IDBFactory dbFactory = UtilZ.Dotnet.DBIBase.Factory.DBFactoryManager.GetDBFactory(config); UtilZ.Dotnet.DBIBase.Interaction.IDBInteraction dbInteraction = dbFactory.GetDBInteraction(); using (var con = dbInteraction.GetProviderFactory().CreateConnection()) { string confStr = dbInteraction.GenerateDBConStr(config, DBVisitType.R); con.ConnectionString = confStr; con.Open(); ret = con.State == ConnectionState.Open; } } catch (Exception exi) { ret = false; Loger.Error(exi); } } catch (Exception ex) { Loger.Error(ex); } }
private void btnPagingQuery_Click(object sender, EventArgs e) { try { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); this._dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); this.QueryPageInfo(this._dbAccess); } catch (Exception ex) { Loger.Error(ex); } }
private void btnDataBaseName_Click(object sender, EventArgs e) { try { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); string databaseName = dbAccess.Database.GetDatabaseName(); Loger.Info($"[{config.ConName}] [DatabaseName:{databaseName}]"); } catch (Exception ex) { Loger.Error(ex); } }
private void btnQuery_Click(object sender, EventArgs e) { try { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); string sql = @"SELECT ID,SensNo,SensLocation,SensType,AddTime FROM Sensors"; DataTable dt = dbAccess.QueryDataToDataTable(sql); dgv.ShowData(dt); } catch (Exception ex) { Loger.Error(ex); } }
private void btnLoad_Click(object sender, EventArgs e) { try { var dbConfig = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); var para = new PartAsynWaitPara <DatabaseConfig, object>(); para.Caption = "查询数据库结构"; para.IsShowCancel = false; para.Para = dbConfig; para.Function = (p) => { p.AsynWait.Hint = $"正在查询数据库[{dbConfig.ConName}]结构,请稍候..."; IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(p.Para.DBID); this._tableList = dbAccess.Database.GetTableInfoList(true).OrderBy(t => { return(t.Name); }).Select(t => { return(new DBTableInfoEx(t)); }).ToList(); if (p.AsynWait.InvokeRequired) { p.AsynWait.Invoke(new Action(() => { this._tableBindingList.Clear(); this._tableBindingList.AddRange(this._tableList); })); } else { this._tableBindingList.Clear(); this._tableBindingList.AddRange(this._tableList); } return(null); }; para.Completed = (ret) => { if (ret.Status == PartAsynExcuteStatus.Exception) { Loger.Error(ret.Exception); } }; PartAsynWaitHelper.Wait(para, this); } catch (Exception ex) { Loger.Error(ex); MessageBox.Show(ex.Message); } }
/// <summary> /// 刷新数据 /// </summary> public override void RefreshData() { try { List <ConfigParaGroup> groups = this._configLogic.GetAllConfigParaGroup(); groups.Insert(0, this._allGroup); ConfigParaGroup selectedItem = null; if (comGroup.Items.Count > 0) { var oldSelectedItem = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comGroup); if (oldSelectedItem != null) { var ret = (from tmpItem in groups where oldSelectedItem.ID == tmpItem.ID select tmpItem).ToList(); if (ret.Count > 0) { selectedItem = ret[0]; } } } if (selectedItem == null && groups.Count > 0) { selectedItem = groups[0]; } this.comGroup.SelectedIndexChanged -= this.comGroup_SelectedIndexChanged; try { DropdownBoxHelper.BindingIEnumerableGenericToComboBox <ConfigParaGroup>(comGroup, groups, nameof(ConfigParaGroup.Name), null); } finally { this.comGroup.SelectedIndex = -1; this.comGroup.SelectedIndexChanged += this.comGroup_SelectedIndexChanged; DropdownBoxHelper.SetGenericToComboBox(comGroup, selectedItem); } } catch (Exception ex) { Loger.Error(ex); } }
private void btnExistTable_Click(object sender, EventArgs e) { try { string tblName = txtTblName.Text; if (checkBoxIgnoreCase.Checked) { tblName = tblName.ToUpper(); } var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); IDBAccess dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); var isExist = dbAccess.Database.ExistTable(tblName); Loger.Info($"[{config.ConName}] [{txtTblName.Text}] [{isExist}]"); } catch (Exception ex) { Loger.Error(ex); } }
private void btnOK_Click(object sender, EventArgs e) { try { var selectedItem = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comGroup); if (selectedItem == null) { MessageBox.Show("参数所属组不能为空"); return; } List <int> validDomainIds = (from tmpItem in this._serviceList where tmpItem.IsSelected select tmpItem.ID).ToList(); if (validDomainIds.Count == 0) { MessageBox.Show("参数作用域范围至少需要有一个服务"); return; } var configParaKeyValue = new ConfigParaKeyValue(); configParaKeyValue.ID = this._configParaKeyValue.ID; configParaKeyValue.Key = this._configParaKeyValue.Key; configParaKeyValue.Value = rtxtValue.Text; configParaKeyValue.GID = selectedItem.ID; configParaKeyValue.Des = rtxtDes.Text; //修改 this._configLogic.ModifyConfigParaKeyValue(configParaKeyValue, validDomainIds); //更新数据源 this._configParaKeyValue.Value = configParaKeyValue.Value; this._configParaKeyValue.Des = configParaKeyValue.Des; this._configParaKeyValue.Group = selectedItem; this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); Loger.Error(ex); } }
private void comboBoxParaGroup_SelectedIndexChanged(object sender, EventArgs e) { try { if (pgPara.SelectedRows.Length == 0) { return; } var group = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comboBoxParaGroup); foreach (var selectedRow in this.pgPara.SelectedRows) { ((ConfigParaKeyValue)((DataGridViewRow)selectedRow).DataBoundItem).Group = group; } } catch (Exception ex) { MessageBox.Show(ex.Message); Loger.Error(ex); } }
private void comGroup_SelectedIndexChanged(object sender, EventArgs e) { try { var selectedItem = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comGroup); if (selectedItem == null) { return; } if (this._allGroup == selectedItem) { selectedItem = null; } List <ConfigParaKeyValue> paras = this._configLogic.GetGroupConfigParaKeyValue(selectedItem); pgConfigParaKeyValue.ShowData(paras, "ConfigParaKeyValue"); } catch (Exception ex) { Loger.Error(ex); } }
private void btnEF_Click(object sender, EventArgs e) { try { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); using (var ef = new DotnetWinFormApp.DB.EFModelContext(config.DBID)) { var actionArr = ef.Action.ToArray(); var roleArr = ef.Role.ToArray(); //Action var roles = ef.Query <DotnetWinFormApp.DB.Role>(r => r.ID == 2).ToArray(); var newRole = new DotnetWinFormApp.DB.Role(); newRole.Name = "员工"; newRole.Des = "打酱油的员工"; if (newRole.Action == null) { newRole.Action = new List <DotnetWinFormApp.DB.Action>(); } foreach (var action in actionArr) { newRole.Action.Add(action); } ef.Insert(newRole); var actionArr2 = ef.Action.ToArray(); var roleArr2 = ef.Role.ToArray(); } } catch (Exception ex) { Loger.Error(ex); } }
private void btnDBQueryExpression_Click(object sender, EventArgs e) { try { // select treea.ID,treea.Name,treea.Age,treeb.City,treeb.Level From treea INNER JOIN treeb on treea.ID = treeb.AID //where treea.Age > 23 AND treeb.Level < 5 //select A.ID,A.Name,A.Age,B.City,B.Level From treea A INNER JOIN treeb B on A.ID = B.AID //where A.Age > 23 AND B.Level < 5 //string tblA = "TreeA"; //string tblB = "TreeB"; string tblA = "treea"; string tblB = "treeb"; var queryExpression = new DBQueryExpression(); queryExpression.QueryFields.Add(new DBQueryField(tblA, "ID")); queryExpression.QueryFields.Add(new DBQueryField(tblA, "Name")); queryExpression.QueryFields.Add(new DBQueryField(tblA, "Age")); queryExpression.QueryFields.Add(new DBQueryField(tblB, "City")); queryExpression.QueryFields.Add(new DBQueryField(tblB, "Level")); queryExpression.ConditionExpressionNodes.LogicOperaters = LogicOperaters.AND; queryExpression.ConditionExpressionNodes.Add(new ExpressionNode(CompareOperater.GreaterThan, tblA, "Age", 23)); queryExpression.ConditionExpressionNodes.Add(new ExpressionNode(CompareOperater.LessThan, tblB, "Level", 5)); var tableAliaNameDic = new Dictionary <string, string>(); tableAliaNameDic.Add("treea", "A"); tableAliaNameDic.Add("treeb", "B"); string fieldSql = queryExpression.QueryFields.ToQueryFieldSql(tableAliaNameDic); Loger.Info(fieldSql); var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); var dbAccess = DBAccessManager.GetDBAccessInstance(config.DBID); List <DBTableInfo> dbTableInfos = dbAccess.Database.GetTableInfoList(true); var dbTableInfoDic = dbTableInfos.ToDictionary(k => { return(k.Name); }, v => { return(v.DbFieldInfos.ToDictionary(t => { return t.FieldName; })); }); var filedValueConverterCollection = new DBFiledValueConverterCollection(); Dictionary <string, object> parameterNameValueDic; int parameterIndex = 1; string where = queryExpression.ConditionExpressionNodes.ToWhere(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, dbAccess.ParaSign, ref parameterIndex, out parameterNameValueDic); Loger.Info(where); ISqlFieldValueFormator fieldValueFormator = DBAccessManager.GetFieldValueFormator(config); string whereNoPara = queryExpression.ConditionExpressionNodes.ToWhereNoParameter(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, fieldValueFormator); Loger.Info(whereNoPara); //------------------------------------------------------------------------------------------------------------------------------------- //A.Age > 23 AND (B.Level < 4 OR B.Level > 6) var expressionNodeCollection = new ExpressionNodeCollection(); expressionNodeCollection.LogicOperaters = LogicOperaters.AND; expressionNodeCollection.Add(new ExpressionNode(CompareOperater.GreaterThan, tblA, "Age", 23)); var orCondition = new ExpressionNode(); orCondition.Children.LogicOperaters = LogicOperaters.OR; orCondition.Children.Add(new ExpressionNode(CompareOperater.LessThan, tblB, "Level", 4)); orCondition.Children.Add(new ExpressionNode(CompareOperater.GreaterThan, tblB, "Level", 6)); expressionNodeCollection.Add(orCondition); parameterNameValueDic = null; parameterIndex = 1; string where2 = expressionNodeCollection.ToWhere(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, dbAccess.ParaSign, ref parameterIndex, out parameterNameValueDic); Loger.Info(where2); string whereNoPara2 = expressionNodeCollection.ToWhereNoParameter(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, fieldValueFormator); Loger.Info(whereNoPara2); tableAliaNameDic.Clear(); parameterNameValueDic = null; parameterIndex = 1; string where3 = expressionNodeCollection.ToWhere(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, dbAccess.ParaSign, ref parameterIndex, out parameterNameValueDic); Loger.Info(where3); string whereNoPara3 = expressionNodeCollection.ToWhereNoParameter(dbTableInfoDic, tableAliaNameDic, filedValueConverterCollection, fieldValueFormator); Loger.Info(whereNoPara3); } catch (Exception ex) { Loger.Error(ex); } }
private void btnTestEF_Click(object sender, EventArgs e) { var config = DropdownBoxHelper.GetGenericFromComboBox <DatabaseConfig>(comboBoxDB); Task.Factory.StartNew(TestEF, config); }
private void btnGetGenericFromComboBox_Click(object sender, EventArgs e) { btnGetGenericFromComboBox.Text = DropdownBoxHelper.GetGenericFromComboBox <CobITemInfo>(comboBox1).Name; }