/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_SaveData(object sender, RoutedEventArgs e) { var item = Bussiness.SelectedItem as Data_Business; if (item == null) { CodeBox.Show("请求选择业务", this); } else { item.UpdateDay = (UpdateDay.SelectedItem as BindModel).value; item.UpdateCount = (UpdateCount.SelectedItem as BindModel).value; item.UpdateTime = (UpdateTime.SelectedItem as BindModel).value; item.SaveDataMonth = (DataMonth.SelectedItem as BindModel).value; item.Policy = (IsDel.SelectedItem as BindModel).value.ToStr(); var isSuccess = FastWrite.Update <Data_Business>(item, a => a.Id == item.Id, a => new { a.UpdateCount, a.UpdateTime, a.UpdateDay, a.SaveDataMonth, a.Policy }).IsSuccess; if (isSuccess) { Bussiness.ItemsSource = AppCache.GetAllBusiness; Common.UpdateWindow(); CodeBox.Show("保存成功", this); } else { CodeBox.Show("保存失败", this); } } }
/// <summary> /// 删除字典明细 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_DicLeaf_Click(object sender, RoutedEventArgs e) { var count = 0; foreach (var item in Dic.Items) { var box = Common.GetTemplateColumn <CheckBox>(Dic, 0, "dicBox", item); if (box != null && box.IsChecked == true) { var temp = item as Data_Dic_Details; if (temp != null && !string.IsNullOrEmpty(temp.Id)) { FastWrite.Delete <Data_Dic_Details>(a => a.Id == temp.Id); } count++; } } if (count == 0) { CodeBox.Show("请选择字典明细", this); } else { InitDic(); CodeBox.Show("删除成功", this); } }
/// <summary> /// 显示 /// </summary> /// <param name="msg">消息</param> /// <returns></returns> public static void Show(string msg, Window owner) { var msgBox = new CodeBox(); msgBox.Message = msg; Common.OpenWin(msgBox, owner); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, RoutedEventArgs e) { dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName); if (!BaseLink.CheckLink(dbType, dbConn)) { CodeBox.Show("连接数据库失败!", this); } else { var buildLink = BaseLink.ControlsToData(dbType, txtHostName, txtUserName, txtPwd, txtPort, txtServerName, labServerName, true, txtLinkName); buildLink.LinkName = buildLink.LinkName == "" ? BaseLink.GetLinkName(buildLink) : buildLink.LinkName; buildLink.Id = Guid.NewGuid().ToString(); AppCache.SetLink(buildLink); if (FastRead.Query <Data_Source>(a => a.LinkName == buildLink.LinkName).ToCount() == 1) { FastWrite.Update <Data_Source>(buildLink, a => a.LinkName == buildLink.LinkName, a => new { a.Host, a.PassWord, a.Port, a.ServerName, a.Type, a.UserName }); } else { FastWrite.Add(buildLink); } CodeBox.Show("连接数据库成功!", this); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, RoutedEventArgs e) { using (var db = new DataContext()) { var success = false; var main = Dic.SelectedItem as Data_Dic; if (string.IsNullOrEmpty(main.Id)) { main.Id = Guid.NewGuid().ToString(); success = FastWrite.Add(main).IsSuccess; } else { success = FastWrite.Update(main, a => a.Id == main.Id, a => new { a.Name }).IsSuccess; } foreach (var item in DicLeaf.Items) { var temp = item as Data_Dic_Details; if (temp == null) { continue; } temp.DicId = main.Id; if (temp != null) { if (string.IsNullOrEmpty(temp.Value)) { CodeBox.Show("字典值不能为空", this); continue; } if (string.IsNullOrEmpty(temp.ContrastValue)) { CodeBox.Show("字典对照值不能为空", this); continue; } if (string.IsNullOrEmpty(temp.Id)) { temp.Id = Guid.NewGuid().ToString(); if (success) { success = db.Add(temp).writeReturn.IsSuccess; } } else { success = db.Update(temp, a => a.Id == temp.Id, a => new { a.Name, a.Value, a.ContrastValue }).writeReturn.IsSuccess; } } } } CodeBox.Show("保存成功", this); }
/// <summary> /// 测试数据库连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Conn_Click(object sender, RoutedEventArgs e) { dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName); if (BaseLink.CheckLink(dbType, dbConn)) { CodeBox.Show("连接成功!", this); } else { CodeBox.Show("连接失败!", this); } }
/// <summary> /// 删除字典类型 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_Dic_Click(object sender, RoutedEventArgs e) { var success = false; var item = Dic.SelectedItem as Data_Dic; if (!string.IsNullOrEmpty(item.Id)) { success = FastWrite.Delete <Data_Dic>(a => a.Id == item.Id).IsSuccess; } if (success) { InitDic(); CodeBox.Show("删除成功", this); } else { CodeBox.Show("删除失败", this); } }
/// <summary> /// 删除业务配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_DelData(object sender, RoutedEventArgs e) { var main = Bussiness.SelectedItem as Data_Business; if (main == null || string.IsNullOrEmpty(main.Name)) { CodeBox.Show("请选择业务", this); return; } using (var db = new DataContext()) { var isSuccess = true; db.BeginTrans(); isSuccess = db.Delete <Data_Business>(a => a.Id == main.Id).writeReturn.IsSuccess; if (isSuccess) { isSuccess = db.Delete <Data_Business_Details>(a => a.Id == main.Id).writeReturn.IsSuccess; } if (isSuccess) { isSuccess = db.ExecuteSql(string.Format("drop table {0}", main.TableName), null, false).writeReturn.IsSuccess; } if (isSuccess) { db.SubmitTrans(); Bussiness.ItemsSource = AppCache.GetAllBusiness; Common.UpdateWindow(); CodeBox.Show("删除业务成功", this); } else { db.RollbackTrans(); CodeBox.Show("删除业务失败", this); } } }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_Click(object sender, RoutedEventArgs e) { var item = dbTypeLink.SelectedItem as Data_Source; if (item != null) { if (FastRead.Query <Data_Business_Details>(a => a.DataSourceId == item.Id).ToCount() == 0) { FastWrite.Delete <Data_Source>(a => a.LinkName == item.LinkName); AppCache.RemoveLink(); dbTypeLink.ItemsSource = AppCache.GetAllLink; InitLinkInfo(); CodeBox.Show("删除成功", this); } else { InitLinkInfo(); CodeBox.Show("删除失败数据源在使用中", this); } } }
/// <summary> /// 保存业务配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_SaveData(object sender, RoutedEventArgs e) { using (var db = new DataContext()) { var isUpdateTable = false; var isSuccess = true; db.BeginTrans(); var main = Bussiness.SelectedItem as Data_Business; if (main == null || string.IsNullOrEmpty(main.Name)) { CodeBox.Show("业务名称不能为空", this); return; } if (string.IsNullOrEmpty(main.TableName)) { CodeBox.Show("业务表名不能为空", this); return; } #region 业务 if (string.IsNullOrEmpty(main.Id)) { //默认每天更新 main.UpdateDay = 1; //默认晚上2点更新 main.UpdateTime = 2; //默认更新条数1万 main.UpdateCount = 1; //默认上次更新时间 main.LastUpdateTime = DateTime.Now; //关联主键策略(1=重复删除,0=重复保留,2=重复更新) main.Policy = "1"; //增加业务 main.Id = Guid.NewGuid().ToString(); isSuccess = db.Add(main).writeReturn.IsSuccess; //创建表 if (isSuccess) { isSuccess = DataSchema.CreateTable(db, main); } //表备注 if (isSuccess) { isSuccess = DataSchema.UpdateTableComment(db, main); } } else { //修改业务 if (isSuccess) { var oldTableName = FastRead.Query <Data_Business>(a => a.Id == main.Id, a => new { a.Name }).ToDic(db).GetValue("name").ToString(); isSuccess = db.Update <Data_Business>(main, a => a.Id == main.Id, a => new { a.Name }).writeReturn.IsSuccess; if (oldTableName != main.TableName) { if (DataSchema.IsExistsTable(db, oldTableName)) { isUpdateTable = true; //修改表名 if (isSuccess) { isSuccess = DataSchema.UpdateTableName(db, main, oldTableName); } //修改表备注 if (isSuccess) { isSuccess = DataSchema.UpdateTableComment(db, main); } } else { DataSchema.CreateTable(db, main); } } } } #endregion #region 业务明细 foreach (var temp in BussinessDetails.Items) { var leaf = temp as Data_Business_Details; if (leaf == null) { continue; } if (string.IsNullOrEmpty(leaf.FieldName)) { continue; } //数据源id if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 1, "DataSourceBox", temp).SelectedItem == null) { continue; } var dataSource = (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 1, "DataSourceBox", temp).SelectedItem as Data_Source); leaf.DataSourceId = dataSource.Id; //表名 if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 2, "TabelBox", temp).SelectedItem != null) { leaf.TableName = (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 2, "TabelBox", temp).SelectedItem as Cache_Table).Name; } //源列名 var columnInfo = new Cache_Column(); if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 3, "ColumnBox", temp).SelectedItem != null) { columnInfo = Common.GetTemplateColumn <ComboBox>(BussinessDetails, 3, "ColumnBox", temp).SelectedItem as Cache_Column; leaf.ColumnName = columnInfo.Name; } //主键 if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 4, "KeyBox", temp).SelectedItem != null) { columnInfo = Common.GetTemplateColumn <ComboBox>(BussinessDetails, 4, "KeyBox", temp).SelectedItem as Cache_Column; leaf.Key = columnInfo.Name; } //排序 if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 5, "OrderByBox", temp).SelectedItem != null) { columnInfo = Common.GetTemplateColumn <ComboBox>(BussinessDetails, 5, "OrderByBox", temp).SelectedItem as Cache_Column; leaf.OrderBy = columnInfo.Name; } //字典 if (Common.GetTemplateColumn <ComboBox>(BussinessDetails, 6, "DicBox", temp).SelectedItem != null) { var dic = Common.GetTemplateColumn <ComboBox>(BussinessDetails, 6, "DicBox", temp).SelectedItem as Data_Dic; if (dic != null && !string.IsNullOrEmpty(dic.Id)) { leaf.Dic = dic.Id; } } //sql leaf.Sql = (temp as Data_Business_Details).Sql; if (string.IsNullOrEmpty(leaf.FieldId)) { leaf.FieldId = Guid.NewGuid().ToString(); leaf.Id = main.Id; //增加业务明细 if (isSuccess) { isSuccess = db.Add(leaf).writeReturn.IsSuccess; } //增加列 columnInfo = Common.GetTemplateColumn <ComboBox>(BussinessDetails, 3, "ColumnBox", temp).SelectedItem as Cache_Column; if (isSuccess) { isSuccess = DataSchema.AddColumn(db, main, leaf, columnInfo, dataSource); } //修改备注 if (isSuccess) { isSuccess = DataSchema.UpdateColumnComment(db, main, leaf, columnInfo, dataSource); } } else { //修改业务明细 if (isSuccess) { isSuccess = db.Update <Data_Business_Details>(leaf, a => a.FieldId == leaf.FieldId, a => new { a.FieldName, a.DataSourceId, a.ColumnName, a.Key, a.OrderBy, a.TableName, a.Dic, a.Sql }).writeReturn.IsSuccess; } //列增加修改 if (isSuccess) { if (DataSchema.IsExistsColumn(db, main.Name, leaf.FieldName)) { isSuccess = DataSchema.UpdateColumn(db, main, leaf, columnInfo, dataSource); } else { isSuccess = DataSchema.AddColumn(db, main, leaf, columnInfo, dataSource); } } } } #endregion if (isSuccess) { if (isUpdateTable) { Bussiness.ItemsSource = AppCache.GetAllBusiness; Common.UpdateWindow(); } db.SubmitTrans(); CodeBox.Show("保存业务成功", this); } else { db.RollbackTrans(); CodeBox.Show("保存业务失败", this); } } }
/// <summary> /// 更新数据源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateData_Click(object sender, RoutedEventArgs e) { DataSchema.InitTable(AppCache.GetLink, false); CodeBox.Show("更新数据源成功!", this); }
/// <summary> /// 加载数据源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadData_Click(object sender, RoutedEventArgs e) { DataSchema.InitTable(AppCache.GetLink, true); CodeBox.Show("加载数据源成功!", this); }