public ArticleHandler(RuleConfig ruleConfig) { this._ruleConfig = ruleConfig; this._fileOperate = new FileOperate(); this._articleBuilder = new ArticleBuilder(); this._sqlOperate = new SqlOperate(); this._currentRule = new JsonArticleRule(ruleConfig.Rules); }
public static string GenerateSingleTableSqlByOperate <T>(this T t, SqlOperate sqlOperate) { var type = t.GetType(); var tableName = type.Name; var properties = type.GetProperties(BindingFlags.GetField | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance); var useableProperties = from p in properties where p.GetValue(t, null) != null let des = p.IsDefined(typeof(IgnoreFieldAttribute)) where !des select p; var sqlText = new StringBuilder(); if (sqlOperate == SqlOperate.Select) { } if (sqlOperate == SqlOperate.Insert) { } if (sqlOperate == SqlOperate.Update) { sqlText.Append("UPDATE ").Append(tableName).Append(" SET "); useableProperties.Each <PropertyInfo>((property) => { sqlText.Append(property.Name).Append("=@").Append(property.Name).Append(","); }); sqlText.Replace(",", "", sqlText.Length - 1, 1);//remove the last character sqlText.Append(" WHERE [ID]=@ID "); } if (sqlOperate == SqlOperate.Delete) { } return(sqlText.ToString()); }
/// <summary> /// 根据配置导出SQL /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGenerateSQL_Click(object sender, EventArgs e) { if (projectInfo != null) { if (string.IsNullOrEmpty(projectInfo.OutputPath)) { MessageDxUtil.ShowError("请在项目菜单中配置导出脚本路径"); return; } if (!DirectoryUtil.IsExistDirectory(projectInfo.OutputPath)) { MessageDxUtil.ShowError(string.Format("配置的路径{0}在系统中不存在,请在项目菜单中配置导出脚本路径", projectInfo.OutputPath)); return; } // 操控进度条 var progressBar = (this.MdiParent as MainForm).progressBar; string fileName = "Dict.Sql"; string sqlfile = projectInfo.OutputPath + "\\" + fileName; StringBuilder sb = new StringBuilder(); switch (projectInfo.DbType) { case "Oracle": break; case "Mysql": break; case "DB2": break; case "SqlServer": { #region 对于SqlServer 脚本的处理 if (FileUtil.IsExistFile(sqlfile)) { FileUtil.DeleteFile(sqlfile); } List <ModRecordInfo> lst = new List <ModRecordInfo>(); lst.Add(new ModRecordInfo() { ModDate = DateTimeHelper.GetServerDateTime2(), ModVersion = new Version("1.0.0.0").ToString(), ModOrderId = "M1234567890", Proposer = "测试递申人", Programmer = "测试修改人", ModContent = "这里是修改内容", ModReason = "修改原因", Remark = "备注信息" }); // 创建文件 FileUtil.CreateFile(sqlfile); // 添加文本信息 //FileUtil.AppendText(sqlfile, SqlServerGenerate.printHeaderInfo(fileName, "V1.3.2.1111", "Jimmy", "2017-09-01 13:22:11", "备注信息", "2017-07-01", lst), Encoding.Default); FileUtil.AppendText(sqlfile, SqlOperate.printHeaderInfo(projectInfo.DbType, fileName, "V1.3.2.1111", "Jimmy", "2017-09-01 13:22:11", "备注信息", "2017-07-01", lst), Encoding.Default); //FileUtil.AppendText(sqlfile, SqlServerGenerate.printInitInfo("T_Basic_DictType"), Encoding.Default); //FileUtil.AppendText(sqlfile, SqlServerGenerate.printInitInfo("T_Basic_DictData"), Encoding.Default); // TODO 这里需要等表结果完成在做 break; #endregion } case "Sqlite": break; case "Access": break; } } }