2023/04/20

C#/.NET/.NET Core/.NET Framework 版本

.Net Framework 4.0, VS2010, C# 4.0 (2010/4)

.Net Framework 4.5, VS2012, C# 5.0 (2012/08)

.Net Framework 4.5.1, VS2013, C#5.0  (2012/08)

.Net Framework 4.6, VS2015, C# 6.0 (2015/07)

.Net Framework 4.7, VS2017, C# 7.0 (2012/08)

.Net Framework 4.7.2, VS2019, C# 8.0 (2019/09)

.Net Framework 4.8, Net Framework不再更新, 除了安全性更新, C# 8.0

.Net Framework 4.8.1 安全新更新, C# 8.0

.Net Core 3.1 (LTS), VS2019, C# 8.0

.NET 5, VS2019, C# 9.0 (2020/09)

.NET 6 (LTS), VS2022, C# 10.0 (2021/11), C# 11.0 (2022/08)

.NET 7, VS2022

.NET 8, 2023/11預計


.NET 每年11月更新

奇數年份發表LTS版本(3   年支援)(.NET 6/8)

偶數年份發表STS版本(1.5 年支援)(.NET 5/7)

Download .NET SDKs for Visual Studio

Wiki:

C# 版本

.Net & .NetCore

ASP.NET_Core

.NET Framework


2023/04/11

SQL 相關

 最後一筆

SELECT * FROM 

(SELECT *,

ROW_NUMBER() OVER (PARTITION BY OrderID ORDER BY CDate DESC) Sort

FROM OrderDetail) R

WHERE R.Sort = 1 

'--取得當天日期
select getdate()   

--取得從系統開始日至今日的時間差(long型態)
select datediff(m,0,getdate())    

--取得當月的第一天
select dateadd(m, datediff(m,0,getdate()),0)

--當月的最後一天 = 下個月的第一天 - 1
select dateadd(day ,-1, dateadd(m, datediff(m,0,getdate())+1,0))  

CrystalReport群組換頁

 群組首>右鍵>群組專家>選項>選項>打勾(1)在之後新增分頁(2)在每一頁重複群組首






LinqToExcel

 1 nuget 安裝 LinqToExcel

2 安裝AccessDatabaseEngine.exe (32位元版本)

3 IIS>應用程式集區>啓用32位元應用程式=True

若無設定32位元, 會出現錯誤: 'Microsoft.ACE.OLEDB.12.0' 提供者並未登錄於本機電腦上的問題


Crystal Report Print Button

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System;

using System.Collections.Generic;

using System.Data;

using System.Web;

using TTCom.Common;


namespace Rpt

{


    public partial class RptSalePrint : PrintBase

    {

        const string strRptCode = "RptSale";

        DateTime qBaseDate;// => Request.QueryString["basedate"].ToDateTime();

        protected void Page_Init(object sender, EventArgs e)

        {

            qBaseDate = new DateTime(2020, 12, 11);

            UF_Preinit(strRptCode);

            //UF_GetQueryString();

            //lblMsg.Text = ReportPath;


            try

            {

                DS_Report = new DataSet();

                DS_Report.ReadXmlSchema(xsdPath);

                if (!IsPostBack)

                {

                    Cache.Clear(DSTableTB);

                    UF_SetMainData();

                    UF_Rpt();

                }

                else

                {

                    DS_Report = GetListI(DSTableTB);

                }


                //預覽報表

                rd.Load(Server.MapPath(ReportPath));

                rd.SetDataSource(DS_Report);

                //CRV1.DisplayGroupTree = false;                

                CRV1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

                CRV1.ReportSource = rd;

            }

            catch (Exception ex)

            {

                Response.Write(ex.ToString());

            }

        }

        private void Page_Unload(object sender, System.EventArgs E)

        {

            rd.Dispose();

            CRV1.Dispose();

        }


        /// <summary>

        /// 將查詢資料存放至HttpContext.Current

        /// </summary>

        /// <param name="ItemName"></param>

        /// <returns></returns>

        public DataSet GetListI(string ItemName)

        {

            DataSet dsData = new DataSet();

            HttpContext context = HttpContext.Current;

            //當查詢的區塊編號的編號cache不存在

            if (context.Cache[ItemName.ToString()] == null)

            {

                //與資料庫相連取資料的程式

                UF_Rpt();

                dsData = (DataSet)context.Cache[ItemName.ToString()];

            }

            else

            {

                //將目前已經查詢過的區塊號碼 Cache 轉為 DataTable

                dsData = (DataSet)context.Cache[ItemName.ToString()];

            }

            return dsData;

        }

        protected void UF_GetQueryString()

        {

 

        }

        private void UF_Rpt()

        {

            //SetCompany();

            //SetPartner(qPartnerSn);

            ReportProvider reportProvider = new ReportProvider();

            //var m = reportProvider.GetRptSal01M(qEnumSysClosingItem, qClosingDate);

            DataRow drM = DS_Report.Tables[DSTableM].NewRow();

            drM["BaseDate"] = qBaseDate.ToString("yyyy/MM/dd");


            DS_Report.Tables[DSTableM].Rows.Add(drM);


            List<DTORptSaleTB> listTB = reportProvider.GetRptSaleTB(qBaseDate);

            foreach (var item in listTB)

            {

                DataRow dr = DS_Report.Tables[DSTableTB].NewRow();


                dr["BaseDate"] = item.BaseDate.ToString("yyyy/MM/dd");

                dr["PartnerNameS"] = EnumHelper.GetEnumString<EnumPartner>(item.PartnerSn);



                dr["CaseNumAll"] = item.CaseNumAll;

                dr["PayAmtAll"] = item.PayAmtAll;

                dr["LoanBalance"] = item.LoanBalance;


                dr["CaseNumD"] = item.CaseNumD;

                dr["PayAmtD"] = item.PayAmtD;


                dr["CaseNumM"] = item.CaseNumM;

                dr["PayAmtM"] = item.PayAmtM;

                dr["RPayAmtM"] = item.RPayAmtM;

                dr["RatePayAmtM"] = item.PayAmtM == 0 ? 0 : item.RPayAmtM /  item.PayAmtM  * 100;


                dr["CaseNumMP"] = item.CaseNumMP;

                dr["PayAmtMP"] = item.PayAmtMP;

                dr["RPayAmtMP"] = item.RPayAmtMP;

                dr["RatePayAmtMP"] = item.PayAmtMP == 0 ? 0 : item.RPayAmtMP / item.PayAmtMP * 100;


                dr["CaseNumY"] = item.CaseNumY;

                dr["PayAmtY"] = item.PayAmtY;

                dr["RPayAmtY"] = item.RPayAmtY;

                dr["RatePayAmtY"] = item.PayAmtY == 0 ? 0 : item.RPayAmtY / item.PayAmtY * 100;


                dr["CaseNumYP"] = item.CaseNumYP;

                dr["PayAmtYP"] = item.PayAmtYP;


                dr["LoanBalance30"] = item.LoanBalance30;

                dr["LoanBalance60"] = item.LoanBalance60;


                dr["LoanBalanceRate30"] = item.DelayRate30 * 100;

                dr["LoanBalanceRate60"] = item.DelayRate60 * 100;


                DS_Report.Tables[DSTableTB].Rows.Add(dr);

            }


            Cache.CreateCache(DSTableTB, DS_Report, 5);

        }


        protected void btnPrint_Click(object sender, EventArgs e)

        {

            ReportDocument cry = new ReportDocument();

            try

            {

                cry.Load(Server.MapPath(ReportPath));

                cry.SetDataSource(DS_Report);

                cry.PrintToPrinter(1, false, 0, 0);

            }

            catch (Exception ex)

            {

                

            }

        }

    }

}

CrystralReport to PDF

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System;

using System.Collections.Generic;

using System.Data;

using System.Web;

using TTCom.Common;


namespace Process

{

    /// <summary>

    /// 輸入: https://localhost:44397/ITTest/TestCR2PDF.aspx?basedate=2020/12/11

    /// 輸出: D:\RptSale20201211.pdf

    /// </summary>    

    public partial class TestCR2PDF : PrintBase

    {

        const string strRptCode = "RptSale";

        DateTime qBaseDate => Request.QueryString["basedate"].ToDateTime();

        private void ToPDF()

        {

            DS_Report = new DataSet();

            DS_Report.ReadXmlSchema(xsdPath);

            UF_SetMainData(0);

            UF_Rpt();


            ReportDocument rptDoc = new ReportDocument();         

            rptDoc.Load(Server.MapPath(@"..\RptCR/RptSale.rpt"), OpenReportMethod.OpenReportByTempCopy);


            rptDoc.SetDataSource(DS_Report);

                

            //產生PDF檔

            ExportOptions crExportOptions = new ExportOptions();

            DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();

            string fname = @"D:\"+ strRptCode + qBaseDate.ToString("yyyyMMdd") + ".pdf";

            crDiskFileDestinationOptions.DiskFileName = fname;

            crExportOptions = rptDoc.ExportOptions;

            {

                crExportOptions.DestinationOptions = crDiskFileDestinationOptions;

                crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

                crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

            }

            rptDoc.Export();

            rptDoc.Close();

            rptDoc.Dispose();



        }

        protected void Page_Init(object sender, EventArgs e)

        {

            if (!Page.IsPostBack)

            {

                UF_Preinit(strRptCode);

                ToPDF();

            }

        }

      

        private void UF_Rpt()

        {

            //SetCompany();

            //SetPartner(qPartnerSn);

            ReportProvider reportProvider = new ReportProvider();

            //var m = reportProvider.GetRptSal01M(qEnumSysClosingItem, qClosingDate);

            DataRow drM = DS_Report.Tables[DSTableM].NewRow();

            drM["BaseDate"] = qBaseDate.ToString("yyyy/MM/dd");


            DS_Report.Tables[DSTableM].Rows.Add(drM);


            List<DTORptSaleTB> listTB = reportProvider.GetRptSaleTB(qBaseDate);

            foreach (var item in listTB)

            {

                DataRow dr = DS_Report.Tables[DSTableTB].NewRow();


                dr["BaseDate"] = item.BaseDate.ToString("yyyy/MM/dd");

                dr["PartnerNameS"] = EnumHelper.GetEnumString<EnumPartner>(item.PartnerSn);



                dr["CaseNumAll"] = item.CaseNumAll;

                dr["PayAmtAll"] = item.PayAmtAll;

                dr["LoanBalance"] = item.LoanBalance;


                dr["CaseNumD"] = item.CaseNumD;

                dr["PayAmtD"] = item.PayAmtD;


                dr["CaseNumM"] = item.CaseNumM;

                dr["PayAmtM"] = item.PayAmtM;

                dr["RPayAmtM"] = item.RPayAmtM;

                dr["RatePayAmtM"] = item.PayAmtM == 0 ? 0 : item.RPayAmtM / item.PayAmtM * 100;


                dr["CaseNumMP"] = item.CaseNumMP;

                dr["PayAmtMP"] = item.PayAmtMP;

                dr["RPayAmtMP"] = item.RPayAmtMP;

                dr["RatePayAmtMP"] = item.PayAmtMP == 0 ? 0 : item.RPayAmtMP / item.PayAmtMP * 100;


                dr["CaseNumY"] = item.CaseNumY;

                dr["PayAmtY"] = item.PayAmtY;

                dr["RPayAmtY"] = item.RPayAmtY;

                dr["RatePayAmtY"] = item.PayAmtY == 0 ? 0 : item.RPayAmtY / item.PayAmtY * 100;


                dr["CaseNumYP"] = item.CaseNumYP;

                dr["PayAmtYP"] = item.PayAmtYP;


                dr["LoanBalance30"] = item.LoanBalance30;

                dr["LoanBalance60"] = item.LoanBalance60;


                dr["LoanBalanceRate30"] = item.DelayRate30 * 100;

                dr["LoanBalanceRate60"] = item.DelayRate60 * 100;


                DS_Report.Tables[DSTableTB].Rows.Add(dr);

            }            

        }

    }

}

Quartz.Net

 Qqartz.Net官網 https://www.quartz-scheduler.net/ 


 Ref:


 Console範例 https://www.itread01.com/content/1561705564.html


WebForm範例未用Web.config https://www.huanlintalk.com/2014/03/aspnet-background-tasks-using-quartznet.html


 

            //.WithCronSchedule("0 0 22 * * ?")    //每天22點執行

            //.WithCronSchedule("0 0/1 * * * ?")    //每分鐘一次

            //.WithCronSchedule("0/5 * * * * ?")    //每5秒一次


C#/.NET/.NET Core/.NET Framework 版本

.Net Framework 4.0,  V S2010, C# 4.0 (2010/4) .Net Framework 4.5, VS2012, C# 5.0 (2012/08) .Net Framework 4.5.1,   VS2013, C#5.0  (2012/08) ...