根据配置文件生成select语句及标题数组

本文介绍了一种根据配置文件自动生成标题数据和SQL查询语句的方法,通过解析配置文件内容,动态创建适用于数据展示的标题数组及用于数据库查询的SQL语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    public class ZhCommon
    {
        /// <summary>
        /// 根据导入配置文件生成标题数据(含objectid)
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static string[] GetTitle(string tableName = "HCYSJ", string configPath = "")
        {
            if (string.IsNullOrEmpty(configPath))
                configPath = AppDomain.CurrentDomain.BaseDirectory;
            CpmVars myVar = new CpmVars(tableName, configPath);
            List<string> ls = new List<string>();
            //ls.Add("OID");
            for (int i = 0; i < myVar.Cols.Count; i++)
            {
                ls.Add(myVar.Cols[i].Prompt);
            }
            return ls.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="configPath"></param>
        /// <returns></returns>
        public static string GenSelect(string tableName, string configPath = "")
        {
            if (string.IsNullOrEmpty(configPath))
                configPath = AppDomain.CurrentDomain.BaseDirectory;
            CpmVars myVar = new CpmVars(tableName, configPath);
            List<string> ls = new List<string>(); //ls.Add("OID");
            for (int i = 0; i < myVar.Cols.Count; i++)
                ls.Add(myVar.Cols[i].FieldName);
            return string.Format("select {0} from {1} ", string.Join(",", ls.ToArray()), tableName);
        }

        private void exsample()
        {
            MyCommon.WriteLog(ZhCommon.GenSelect("ZDMX"));

            string[] title = ZhCommon.GetTitle("ZDMX");
            List<string> ls = new List<string>();
            foreach (var item in title)
            {
                ls.Add(string.Format("\"{0}\"", item));
            }
            MyCommon.WriteLog(string.Join(",", ls.ToArray()));

        }
    }
private void Test(){
          Excel.Application excelApp = new Excel.Application();
            excelApp.Visible = true;
            Excel.Workbook wb = excelApp.Workbooks.Add();
            Excel.Worksheet sht = wb.Worksheets.Add();
            string shtName = "xxx";
            sht.Name = shtName;
            MyCommon.FillDtToWorksheet(sht, dt);

            string[] title = { "序号", "日期"};
            EUtil.FillArrayToWorksheet(sht, EUtil.StringArrayToMatrix(title), "A1");

            sht.Cells.Select();
            sht.Cells.EntireColumn.AutoFit();
            //Excel.Range rng = sht.Columns["G:G"];
            //rng.ColumnWidth = 38;
            //excelApp.ActiveWindow.ScrollColumn = 1;
            //rng = sht.Cells[1, 1];
            //rng.Select();
            //string fileName = string.Format("FILES/{0}_{1}.xlsx",wddm,yf);
            wb.SaveAs(Filename: fileName);
            wb.Close();
            excelApp.Quit();
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值