├── .gitignore ├── BaseWeb ├── Models │ ├── XiDateDto.cs │ ├── XiLinkDto.cs │ ├── XiHideDto.cs │ ├── XiIntDto.cs │ ├── XiDecDto.cs │ ├── XiDtDto.cs │ ├── XiHtmlDto.cs │ ├── XiCheckDto.cs │ ├── XiSelectDto.cs │ ├── XiReadDto.cs │ ├── XiTextareaDto.cs │ ├── XiTextDto.cs │ ├── XiRadioDto.cs │ ├── XgFindTbarDto.cs │ ├── XgThDto.cs │ ├── XiFileDto.cs │ └── XiBaseDto.cs ├── readme.txt ├── BaseWeb.csproj.user ├── Properties │ └── launchSettings.json ├── Services │ ├── XpResourceService.c_old │ ├── _ActionResult.cs_old │ ├── _Session.cs_old │ ├── _BR.cs_old │ └── ImageData.cs_old ├── ViewComponents │ ├── XiReadViewComponent.cs │ ├── XgGroupViewComponent.cs │ ├── XiDtViewComponent.cs │ ├── XgHideLinkViewComponent.cs │ ├── XiSelectViewComponent.cs │ ├── XiTextareaViewComponent.cs │ ├── XiRadio0ViewComponent.cs │ ├── XiHideIdViewComponent.cs │ ├── XiHtmlViewComponent.cs │ ├── XiDecViewComponent.cs │ ├── XiIntViewComponent.cs │ ├── XiLinkViewComponent.cs │ ├── XiHideViewComponent.cs │ ├── XiRadioViewComponent.cs │ ├── XiTextViewComponent.cs │ ├── XiDateViewComponent.cs │ ├── XgCreateViewComponent.cs │ ├── XgProgPathViewComponent.cs │ ├── XgExportViewComponent.cs │ ├── XiCheckViewComponent.cs │ ├── XiFileViewComponent.cs │ ├── XgSaveViewComponent.cs │ ├── XgAddRowViewComponent.cs │ ├── XgDeleteRowViewComponent.cs │ ├── XgOpenModalViewComponent.cs │ ├── XgSaveBackViewComponent.cs │ ├── XgDeleteUpDownViewComponent.cs │ ├── XgThViewComponent.cs │ ├── XgCol4ViewComponent.cs │ ├── XgCrudFunViewComponent.cs │ ├── XgFindTbarViewComponent.cs │ └── XgLeftMenuViewComponent.cs ├── Helpers_old │ ├── XgTitleHelper.cs │ ├── XgFormHelper.cs │ ├── XiCheckAllHelper.cs │ ├── XiTextMaskHelper.cs │ └── XiRadioHelper.cs ├── Enums │ └── XiEstr.cs └── BaseWeb.csproj ├── Base ├── Models │ ├── SnNumDto.cs │ ├── SnStrDto.cs │ ├── IdNumDto.cs │ ├── PropDateDto.c_old │ ├── IdStrDto.cs │ ├── RowColNumDto.cs │ ├── IdStrExtDto.cs │ ├── IdStrExt2Dto.cs │ ├── ExcelImportFieldDto.cs │ ├── PropRadioDto.c_old │ ├── WordImageDto.cs │ ├── PdfImageDto.cs │ ├── PropCheckDto.c_old │ ├── WordImageRunDto.c_old │ ├── ExcelRowModel.cs_old │ ├── ChartItemDto.cs │ ├── ProgAuthDto.cs_old │ ├── PropSelectDto.c_old │ ├── WordSetTplDto.cs │ ├── ChartDto.cs │ ├── ChartGroupItemDto.cs │ ├── CountDto.cs │ ├── AdUserDto.cs │ ├── ChartGroupDto.cs │ ├── GroupIdStrsDto.cs │ ├── SqlDto.cs │ ├── LoginVo.cs │ ├── ExcelSheetModel.cs_old │ ├── ChangeValueDto.cs │ ├── WordRowsDto.cs_old │ ├── UserProfile0Model.cs_old │ ├── PropFileDto.c_old │ ├── SmtpDto.cs │ ├── PropTextAreaDto.c_old │ ├── PropTextDto.c_old │ ├── UploadDto.cs │ ├── DbFormatDto.cs_old │ ├── QitemDto.cs │ ├── ErrorFieldDto.cs_old │ ├── SignLineDto.cs │ ├── CrudTbarDto.cs │ ├── ErrorRowDto.cs │ ├── EmailDto.cs │ ├── PropNumDto.c_old │ ├── ResultImportDto.cs │ ├── EasyPageDto.cs_old │ ├── SqlArgModel.cs_old │ ├── CacheReadModel.cs_old │ ├── MenuDto.cs │ ├── ResultDto.cs │ ├── PageOut.cs │ ├── CalendarEventDto.cs │ ├── EitemDto.cs │ ├── BaseUserDto.cs │ ├── BaseResDto.cs │ ├── PageIn.cs │ ├── EasyDtDto.cs │ ├── RBDto.cs_old │ ├── DtDto.cs │ ├── PropBaseDto.c_old │ ├── ReadDto.cs │ ├── Select2PropModel.cs_old │ └── ExcelImportDto.cs ├── Interfaces │ ├── IBaseUserSvc.cs │ ├── ISmsSvc.cs │ ├── ICacheSvc.cs │ └── IPdfSvc.cs ├── Services │ ├── IBaseResService.cs_old │ ├── _Time.cs │ ├── LogError.cs_old │ ├── _Cast.cs_old │ ├── zz_Cache0Service.cs_old │ ├── _Test.cs │ ├── _Result.cs │ ├── _Office.cs │ ├── _Datatable.cs │ ├── _Var.cs │ ├── BaseUserSvc.cs │ ├── _Guid.cs │ ├── _Array.cs │ ├── CrudGetSvc.cs │ ├── _LogTime.cs │ ├── _ModeUR.cs │ ├── _Pwd.cs │ ├── _Xml.cs │ ├── _Cache.cs │ ├── _Ad.cs │ ├── _Net.cs │ ├── _Seo.cs │ ├── CacheMemSvc.cs │ ├── _Config.cs_old │ ├── BaseEditSvc.cs │ ├── _Num.cs │ ├── _Page.cs │ ├── _Login.cs_old │ ├── _Redis.cs_old │ ├── CacheRedisSvc.cs │ └── Extension.cs_old ├── Enums │ ├── DbTypeEnum.cs │ ├── NodeTypeEstr.cs │ ├── OrderTypeEnum.cs │ ├── zz_EnumOrderDir.cs_old │ ├── RandomTypeEnum.cs │ ├── AuthRangeEnum.cs │ ├── LoginTypeEstr.cs │ ├── LocaleEstr.cs │ ├── FlowBackTypeEnum.cs │ ├── AuthTypeEnum.cs │ ├── BrFormatEstr.cs │ ├── ValidTypeEstr.cs │ ├── ModelTypeEstr.cs │ ├── ContentTypeEstr.cs │ ├── OtpTypeEstr.cs │ ├── zz_LaunchStatusEstr.cs_old │ ├── EnumCacheStatus.cs_old │ ├── InputPatternEstr.cs │ ├── CrudEnum.cs │ ├── DataTypeEnum.cs │ ├── LineOpEstr.cs │ ├── EnumCacheDb.cs_old │ ├── QitemTypeEnum.cs │ ├── SignerTypeEstr.cs │ ├── TextTypeEstr.cs │ ├── CheckTypeEstr.cs │ ├── PatternEstr.cs │ ├── InputTypeEstr.cs │ └── ItemOpEstr.cs ├── Base.csproj.user └── Properties │ └── launchSettings.json ├── BaseFlow ├── Areas │ ├── _ViewImports.cshtml │ └── XpFlow │ │ └── FlowTest.cshtml ├── Services │ └── XgFlowR.cs └── BaseFlow.csproj ├── BaseApi ├── Attributes │ ├── XgStrLenAttribute.cs │ ├── XgReqAttribute.cs │ ├── XgRB0Attribute.cs_old │ ├── XgLoginAttribute.cs │ ├── XgRBAttribute.cs_old │ └── XgServerAttribute.cs ├── Services │ ├── _HttpSafe.cs │ ├── _Device.cs │ ├── XgFlowRead.cs │ ├── XgEasyRptRead.cs │ ├── XgProgRead.cs │ ├── XgTranLogRead.cs │ ├── XgEasyRptEdit.cs │ ├── XgImportRead.cs │ ├── _Html.cs │ ├── XgProgEdit.cs │ ├── _AuthFB.cs │ └── _HttpWord.cs ├── Extensions │ └── SessionExtension.cs ├── BaseApi.csproj └── Controllers │ └── BaseCtrl.cs ├── SmsTaiwan ├── SmsTaiwan.csproj └── Models │ └── SmsDto.cs ├── PdfSpire ├── PdfSpire.csproj └── SpireSvc.cs ├── BaseEther ├── BaseEther.csproj ├── Models │ └── EventLogDto.cs └── Services │ └── _Ether.cs ├── Readme-CN.md ├── Readme-TW.md └── Readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | bin/ 3 | obj/ 4 | _log/ 5 | packages/ 6 | *.rar 7 | *.bak 8 | zz_*.* 9 | old/ 10 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiDateDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiDateDto : XiBaseDto 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /BaseWeb/readme.txt: -------------------------------------------------------------------------------- 1 | csproj檔: 2 | -> 3 | Library -------------------------------------------------------------------------------- /Base/Models/SnNumDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | public class SnNumDto 4 | { 5 | public int Sn { get; set; } 6 | public int Num { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /Base/Models/SnStrDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | public class SnStrDto 4 | { 5 | public int Sn { get; set; } 6 | public string Str { get; set; } = ""; 7 | } 8 | } -------------------------------------------------------------------------------- /Base/Models/IdNumDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | public class IdNumDto 4 | { 5 | public string Id { get; set; } = ""; 6 | public int Num { get; set; } 7 | 8 | }//class 9 | } -------------------------------------------------------------------------------- /Base/Models/PropDateDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// date property 6 | /// 7 | public class PropDateDto : PropTextDto 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /Base/Models/IdStrDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | //for select option 4 | public class IdStrDto 5 | { 6 | public string Id { get; set; } = ""; 7 | public string Str { get; set; } = ""; 8 | } 9 | } -------------------------------------------------------------------------------- /Base/Interfaces/IBaseUserSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | 3 | namespace Base.Interfaces 4 | { 5 | public interface IBaseUserSvc 6 | { 7 | //get base info dto 8 | BaseUserDto GetData(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Base/Services/IBaseResService.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | 3 | namespace Base.Services 4 | { 5 | public interface IBaseResService 6 | { 7 | //get base info dto 8 | BaseResDto GetData(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiLinkDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiLinkDto : XiBaseDto 4 | { 5 | public string Table { get; set; } = ""; 6 | //public string FnOnViewFile { get; set; } = ""; 7 | } 8 | } -------------------------------------------------------------------------------- /Base/Enums/DbTypeEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// Db type 6 | /// 7 | public enum DbTypeEnum 8 | { 9 | MSSql, 10 | MySql, 11 | Oracle 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Enums/NodeTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | public static class NodeTypeEstr 4 | { 5 | public const string Start = "S"; 6 | public const string End = "E"; 7 | public const string Normal = "N"; 8 | } 9 | } -------------------------------------------------------------------------------- /Base/Base.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /Base/Enums/OrderTypeEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// jquery datatables order type 6 | /// 7 | public enum OrderTypeEnum 8 | { 9 | Asc, 10 | Desc 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Base/Enums/zz_EnumOrderDir.cs_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// for jquery datatable order 6 | /// 7 | public enum EnumOrderDir 8 | { 9 | Asc, 10 | Desc 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BaseWeb/BaseWeb.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /Base/Models/RowColNumDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | public class RowColNumDto 5 | { 6 | public string Row { get; set; } = ""; 7 | public string Col { get; set; } = ""; 8 | public int Num { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Base/Interfaces/ISmsSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System.Threading.Tasks; 3 | 4 | namespace Base.Interfaces 5 | { 6 | //簡訊服務介面 7 | public interface ISmsSvc 8 | { 9 | Task SendA(string phone, string msg); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Base/Models/IdStrExtDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | public class IdStrExtDto 5 | { 6 | public string Id { get; set; } = ""; 7 | public string Str { get; set; } = ""; 8 | public string Ext { get; set; } = ""; 9 | } 10 | } -------------------------------------------------------------------------------- /Base/Enums/RandomTypeEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// random type 6 | /// 7 | public enum RandomTypeEnum 8 | { 9 | Num, 10 | UpEng, 11 | UpEngNum, 12 | All, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Base/Services/_Time.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Services 2 | { 3 | public class _Time 4 | { 5 | //stop mini second 6 | public static void Sleep(int miniSec) 7 | { 8 | System.Threading.Thread.Sleep(miniSec); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Base/Enums/AuthRangeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// crud auth range 5 | /// 6 | public enum AuthRangeEnum 7 | { 8 | None, //0 9 | User, //1 10 | Dept, //2 11 | All = 9, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Enums/LoginTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// login type 5 | /// 6 | public class LoginTypeEstr 7 | { 8 | public const string None = "0"; 9 | public const string Pwd = "Pwd"; 10 | public const string Ad = "Ad"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Base/Models/IdStrExt2Dto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | public class IdStrExt2Dto 5 | { 6 | public string Id { get; set; } = ""; 7 | public string Str { get; set; } = ""; 8 | public string Ext { get; set; } = ""; 9 | public string Ext2 { get; set; } = ""; 10 | } 11 | } -------------------------------------------------------------------------------- /Base/Services/LogError.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Services 2 | { 3 | //parent class for Log Error function 4 | public class LogError 5 | { 6 | public string Error { get; set; } 7 | 8 | public bool IsError() 9 | { 10 | return !_Str.IsEmpty(Error); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiHideDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiHideDto 4 | { 5 | public string Fid { get; set; } = ""; 6 | public string Value { get; set; } = ""; 7 | public string InputAttr { get; set; } = ""; 8 | //public string ClsBox { get; set; } = ""; 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /Base/Enums/LocaleEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// multiple language 6 | /// 7 | public class LocaleEstr 8 | { 9 | public const string TW = "zh-TW"; 10 | public const string US = "en-US"; 11 | public const string CN = "zh-CN"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Models/ExcelImportFieldDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | public class ExcelImportFieldDto 5 | { 6 | public string Fid { get; set; } = ""; 7 | //public int Fno { get; set; } 8 | public string CellName { get; set; } = ""; 9 | public bool IsDate { get; set; } = false; 10 | } 11 | } -------------------------------------------------------------------------------- /Base/Models/PropRadioDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// radio group 6 | /// 7 | public class PropRadioDto : PropBaseDto 8 | { 9 | /// 10 | /// Vertical or not 11 | /// 12 | public bool IsVertical = false; 13 | } 14 | } -------------------------------------------------------------------------------- /Base/Enums/FlowBackTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// program auth type, see _Cruc.AuthType 5 | /// 6 | public enum FlowBackTypeEnum 7 | { 8 | Close, //close flow 9 | ToFirst, //to first level 10 | ToPrev, //to prev level 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Base/Models/WordImageDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | //word image 4 | public class WordImageDto 5 | { 6 | public string Code = ""; 7 | 8 | public string FilePath = ""; 9 | 10 | public double Width; 11 | 12 | public double Height; 13 | 14 | public string Tag = ""; 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /Base/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Base": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "applicationUrl": "https://localhost:52373;http://localhost:52374" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Base/Enums/AuthTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// program auth type, see _Cruc.AuthType 5 | /// 6 | public enum AuthTypeEnum 7 | { 8 | None, //0 9 | Ctrl, //1:controller 10 | Action, //2:action 11 | Row, //3:db rows 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Services/_Cast.cs_old: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Base.Services 4 | { 5 | //move to _Str 6 | public class _Cast 7 | { 8 | //convert string to enum type 9 | public static T StrToEnum(string value) 10 | { 11 | return (T) Enum.Parse(typeof(T), value, true); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BaseFlow/Areas/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using Base.Enums 2 | @using Base.Models 3 | @using Base.Services 4 | @using BaseApi.Services 5 | @using BaseWeb.Models 6 | @using BaseWeb.Services 7 | @using BaseWeb.ViewComponents 8 | @using Microsoft.AspNetCore.Mvc.Localization 9 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 10 | @addTagHelper *, BaseWeb -------------------------------------------------------------------------------- /BaseWeb/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "BaseWeb": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "environmentVariables": { 7 | "ASPNETCORE_ENVIRONMENT": "Development" 8 | }, 9 | "applicationUrl": "https://localhost:55568;http://localhost:55569" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /BaseWeb/Services/XpResourceService.c_old: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Localization; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BaseWeb.Services 9 | { 10 | public class XpResourceService : IStringLocalizerFactory 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiIntDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiIntDto : XiBaseDto 4 | { 5 | /* 6 | public XiIntDto() 7 | { 8 | Min = 0; 9 | Max = 0; 10 | } 11 | */ 12 | 13 | public int Min { get; set; } = 0; 14 | public int Max { get; set; } = 0; 15 | } 16 | } -------------------------------------------------------------------------------- /Base/Models/PdfImageDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | //pdf image 4 | public class PdfImageDto 5 | { 6 | public string FilePath = ""; 7 | 8 | public double PosX; 9 | 10 | public double PosY; 11 | 12 | //等比例縮放, 只考慮 width 13 | public double Width; 14 | 15 | //public double Height; 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /Base/Models/PropCheckDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// checkbox property 6 | /// 7 | public class PropCheckDto : PropBaseDto 8 | { 9 | /// 10 | /// inline or not, only for title is emtpy 11 | /// 12 | public bool IsCenter = false; 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /BaseWeb/Models/XiDecDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiDecDto : XiBaseDto 4 | { 5 | /* 6 | public XiDecDto() 7 | { 8 | Min = 0; 9 | Max = 0; 10 | } 11 | */ 12 | 13 | public decimal Min { get; set; } = 0; 14 | public decimal Max { get; set; } = 0; 15 | } 16 | } -------------------------------------------------------------------------------- /Base/Models/WordImageRunDto.c_old: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Base.Models 4 | { 5 | //word(office) image Run 6 | public class WordImageRunDto 7 | { 8 | public string FileName = ""; 9 | public string ImageCode = ""; 10 | public Stream? DataStream; 11 | public int WidthEmu; 12 | public int HeightEmu; 13 | } 14 | } -------------------------------------------------------------------------------- /Base/Services/zz_Cache0Service.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Services 2 | { 3 | public abstract class Cache0Service 4 | { 5 | 6 | public abstract string GetStr(string key); 7 | 8 | public abstract bool SetStr(string key, string value); 9 | 10 | public abstract bool DeleteKey(string key); 11 | 12 | //Task FlushDbA(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiDtDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiDtDto : XiBaseDto 4 | { 5 | /* 6 | public XiDtDto() 7 | { 8 | MinuteStep = 10; 9 | } 10 | */ 11 | 12 | public int MinuteStep { get; set; } = 10; 13 | 14 | public string FnOnChange { get; set; } = ""; 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /Base/Enums/BrFormatEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | //format type for iread field, map to fid of _BR.js !! 4 | public static class BrFormatEstr 5 | { 6 | public const string Date = "MmUiDateFmt"; 7 | public const string Dt = "MmUiDtFmt"; //datetime 8 | public const string Dt2 = "MmUiDt2Fmt"; //datetime without second 9 | } 10 | } -------------------------------------------------------------------------------- /BaseWeb/Models/XiHtmlDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiHtmlDto : XiBaseDto 4 | { 5 | /* 6 | public XiHtmlDto() 7 | { 8 | MaxLen = 0; 9 | //RowsCount = 10; 10 | } 11 | */ 12 | 13 | public int MaxLen { get; set; } = 0; 14 | //public int RowsCount { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Base/Enums/ValidTypeEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// client jquery validate 6 | /// 7 | public class ValidTypeEstr 8 | { 9 | public const string None = ""; 10 | public const string Email = "Email"; 11 | public const string Phone = "Phone"; 12 | public const string Html = "Html"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Base/Interfaces/ICacheSvc.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Base.Interfaces 4 | { 5 | public interface ICacheSvc 6 | { 7 | 8 | string? GetStr(string userId, string key); 9 | 10 | bool SetStr(string userId, string key, string value); 11 | 12 | bool DeleteKey(string userId, string key); 13 | 14 | Task ResetDbA(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Base/Models/ExcelRowModel.cs_old: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// Row 7 | /// 8 | public class ExcelRowModel 9 | { 10 | public ExcelRowModel() 11 | { 12 | Cells = new List(); 13 | } 14 | public List Cells { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Base/Enums/ModelTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /** 4 | * model 的欄位種類, 匯入excel時先建立model, 以下為可使用的種類清單 5 | */ 6 | public static class ModelTypeEstr 7 | { 8 | //public const string Date = "Date"; 9 | public const string Datetime = "Datetime"; 10 | public const string Int = "Int"; 11 | public const string String = "String"; 12 | } 13 | } -------------------------------------------------------------------------------- /Base/Enums/ContentTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | //content type 4 | public static class ContentTypeEstr 5 | { 6 | public const string Excel = "application/msexcel"; 7 | public const string Word = "application/ms-word"; 8 | public const string Pdf = "application/pdf"; 9 | public const string Json = "application/json"; 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Base/Enums/OtpTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// otp type 5 | /// 6 | public class OtpTypeEstr 7 | { 8 | public const string Email = "E"; 9 | public const string EmailLink = "EL"; 10 | public const string Sms = "S"; 11 | public const string Auth = "A"; //Microsoft & Google Authenticator 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Models/ChartItemDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | //for output group bar chart, 欄位名稱和大小寫配合 Chart.js 6 | public class ChartItemDto 7 | { 8 | //public string label { get; set; } 9 | 10 | public List backgroundColor { get; set; } = null!; 11 | 12 | public List data { get; set; } = null!; 13 | } 14 | } -------------------------------------------------------------------------------- /Base/Models/ProgAuthDto.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// program auth 5 | /// 6 | public class ProgAuthDto 7 | { 8 | //program id 9 | public string ProgCode { get; set; } 10 | 11 | //program name 12 | //public string ProgName { get; set; } 13 | 14 | public string AuthStr { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Base/Models/PropSelectDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// select field 6 | /// 7 | public class PropSelectDto : PropTextDto 8 | { 9 | /// 10 | /// add empty row 11 | /// 12 | public bool AddEmptyRow = true; 13 | 14 | //public string OnChangeFn = ""; 15 | 16 | }//class 17 | } -------------------------------------------------------------------------------- /Base/Models/WordSetTplDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | //word set template dto 4 | public class WordSetTplDto 5 | { 6 | //found template string 7 | public string TplStr = ""; 8 | 9 | //found start pos 10 | public int StartPos = 0; 11 | 12 | //found end pos(include found end string length) 13 | public int EndPos = 0; 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /Base/Models/ChartDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | //欄位名稱和大小寫配合 Chart.js 6 | public class ChartDto 7 | { 8 | public string title { get; set; } = ""; 9 | 10 | //label list 11 | public List labels { get; set; } = null!; 12 | 13 | public List datasets { get; set; } = null!; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Base/Models/ChartGroupItemDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | //for output group bar chart, 欄位名稱和大小寫配合 Chart.js 6 | public class ChartGroupItemDto 7 | { 8 | public string label { get; set; } = ""; 9 | 10 | public string backgroundColor { get; set; } = ""; 11 | 12 | public List data { get; set; } = null!; 13 | } 14 | } -------------------------------------------------------------------------------- /Base/Enums/zz_LaunchStatusEstr.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// 產品上下架狀態 5 | /// 6 | public class LaunchStatusEstr 7 | { 8 | public const string No = "0"; //未上架 9 | public const string Doing = "1"; //準備上架 10 | public const string Yes = "2"; //已上架 11 | public const string Over = "3"; //下架 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Models/CountDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// summary data 5 | /// 6 | public class CountDto 7 | { 8 | //data type 9 | public string DataType { get; set; } = ""; 10 | 11 | //row type 12 | public string RowType { get; set; } = ""; 13 | 14 | //amount 15 | public int Amount { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Base/Enums/EnumCacheStatus.cs_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// 查詢cache結果的狀態 6 | /// 7 | public enum EnumCacheStatus 8 | { 9 | Ok, //成功, 包含資料內容是null的情形(與找不到資料不同) 10 | //OkButNull, //成功, 但是資料內容是null 11 | Miss, //資料有遺失(因資料異動被刪除) 12 | Empty, //查無資料 13 | Error, //系統錯誤(cache程式會記錄error) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Base/Enums/InputPatternEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// input pattern 6 | /// 7 | public class InputPatternEstr 8 | { 9 | public const string None = "none"; //中文 10 | public const string EngNum = "[A-Za-z0-9]+"; //英數 11 | public const string EngNumExt = "[A-Za-z0-9\\(\\)\\-\\/ ]+"; //英數()-/(空白), 此為default 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Base/Models/AdUserDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// summary data 5 | /// 6 | public class AdUserDto 7 | { 8 | //(SamAccountName) 9 | public string Id { get; set; } = ""; 10 | 11 | //(sn) 12 | public string Name { get; set; } = ""; 13 | 14 | //(mail) 15 | public string Email { get; set; } = ""; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Base/Models/ChartGroupDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | //欄位名稱和大小寫配合 Chart.js 6 | public class ChartGroupDto 7 | { 8 | public string title { get; set; } = ""; 9 | 10 | //label list 11 | public List labels { get; set; } = null!; 12 | 13 | public List datasets { get; set; } = null!; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiReadViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | //readonly field 8 | public class XiReadViewComponent 9 | { 10 | public HtmlString Invoke(XiReadDto dto) 11 | { 12 | return new HtmlString(_Input.XiRead(dto)); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Base/Enums/CrudEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// crud fun type 6 | /// 7 | public enum CrudEnum 8 | { 9 | AuthRow, //pos 0, fun is auth row or not(0/1) 10 | Create, 11 | Read, 12 | Update, 13 | Delete, 14 | Print, 15 | Export, 16 | View, 17 | Other, 18 | Empty = 99 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Base/Services/_Test.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Services 3 | { 4 | /// 5 | /// ?? 6 | /// 7 | public class _Test 8 | { 9 | public static string GetHello() 10 | { 11 | return "Hello."; 12 | } 13 | 14 | public static string RunSql(string sql) 15 | { 16 | //xxx 17 | 18 | return "OK"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Base/Enums/DataTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// Db data type 5 | /// 6 | public class DataTypeEnum 7 | { 8 | public const int Datetime = 1; 9 | public const int Date = 2; 10 | public const int Bit = 3; 11 | public const int Int = 4; 12 | public const int Decimal = 5; 13 | public const int Other = 9; //string 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Base/Models/GroupIdStrsDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | public class GroupIdStrsDto 6 | { 7 | /// 8 | /// group text 9 | /// 10 | public string Group { get; set; } = ""; 11 | 12 | /// 13 | /// for select options 14 | /// 15 | public List Items { get; set; } = null!; 16 | } 17 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgGroupViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XgGroupViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke(string label, bool icon = false) 10 | { 11 | return new HtmlString(_Input.XgGroup(label, icon)); 12 | } 13 | 14 | } //class 15 | } -------------------------------------------------------------------------------- /Base/Enums/LineOpEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | public static class LineOpEstr 4 | { 5 | public const string Eq = "EQ"; //= 6 | public const string NotEq = "NEQ"; //!= 7 | public const string Gt = "GT"; //> 8 | public const string Ge = "GE"; //>= 9 | public const string St = "ST"; //< 10 | public const string Se = "SE"; //<= 11 | //public const string Else = "else"; //其他狀況?? 12 | } 13 | } -------------------------------------------------------------------------------- /Base/Models/SqlDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | //sql string each block 5 | public class SqlDto 6 | { 7 | //sql statement without "Select" key word 8 | public string Select = ""; 9 | 10 | //column list 11 | public string[] Columns = {}; 12 | 13 | public string From = ""; 14 | public string Where = ""; 15 | public string Group = ""; 16 | public string Order = ""; 17 | } 18 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiDtViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.Helpers 7 | { 8 | //use bootstrap datepicker 9 | public class XiDtViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(XiDtDto dto) 12 | { 13 | return new HtmlString(_Input.XiDt(dto)); 14 | } 15 | 16 | }//calss 17 | } 18 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiCheckDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiCheckDto : XiBaseDto 4 | { 5 | /* 6 | public XiCheckDto() 7 | { 8 | IsCheck = false; 9 | Label = ""; 10 | FnOnClick = ""; 11 | } 12 | */ 13 | 14 | public bool IsCheck { get; set; } = false; 15 | public string Label { get; set; } = ""; 16 | public string FnOnClick { get; set; } = ""; 17 | } 18 | } -------------------------------------------------------------------------------- /Base/Models/LoginVo.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | public class LoginVo 4 | { 5 | public string Account { get; set; } = ""; 6 | public string Pwd { get; set; } = ""; 7 | //public string Locale { get; set; } 8 | 9 | public string FromUrl { get; set; } = ""; 10 | 11 | public string AccountMsg { get; set; } = ""; 12 | public string PwdMsg { get; set; } = ""; 13 | public string ErrorMsg { get; set; } = ""; 14 | } 15 | } -------------------------------------------------------------------------------- /BaseApi/Attributes/XgStrLenAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace BaseApi.Attributes 4 | { 5 | public class XgStrLenAttribute : StringLengthAttribute 6 | { 7 | public XgStrLenAttribute(int maxLen) : base(maxLen) 8 | { 9 | //ErrorMessage = string.Format(_Locale.GetBaseRes()!.StrLen, maxLen); 10 | ErrorMessage = string.Format("max length={0}", maxLen); 11 | } 12 | 13 | } //class 14 | } 15 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgHideLinkViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Html; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace BaseWeb.ViewComponents 5 | { 6 | //hidden link for pjax call 7 | public class XgHideLinkViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke() 10 | { 11 | var html = ""; 12 | return new HtmlString(html); 13 | } 14 | }//class 15 | } 16 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiSelectViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //select input 9 | public class XiSelectViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(XiSelectDto dto) 12 | { 13 | return new HtmlString(_Input.XiSelect(dto)); 14 | } 15 | 16 | }//class 17 | } 18 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiTextareaViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //textarea input 9 | public class XiTextareaViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(XiTextareaDto dto) 12 | { 13 | return new HtmlString(_Input.XiTextarea(dto)); 14 | } 15 | 16 | } //class 17 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiRadio0ViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | //只有一個 radio 按鈕, 自行組合 6 | namespace BaseWeb.ViewComponents 7 | { 8 | public class XiRadio0ViewComponent : ViewComponent 9 | { 10 | public HtmlString Invoke(string fid, string value, string label) 11 | { 12 | return new HtmlString(_Input.XiRadio0(fid, value, label)); 13 | } 14 | 15 | }//class 16 | } 17 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiHideIdViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XiHideIdViewComponent : ViewComponent 8 | { 9 | /// 10 | /// hidden field 11 | /// 12 | public HtmlString Invoke() 13 | { 14 | return new HtmlString(_Input.XiHideId()); 15 | } 16 | 17 | }//class 18 | } 19 | -------------------------------------------------------------------------------- /Base/Models/ExcelSheetModel.cs_old: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | //工作表Model 6 | public class ExcelSheetModel 7 | { 8 | /// 9 | /// 建構式 10 | /// 11 | public ExcelSheetModel() 12 | { 13 | Rows = new List(); 14 | } 15 | 16 | public string SheetName { get; set; } 17 | 18 | public List Rows { get; set; } 19 | 20 | } //class 21 | } 22 | -------------------------------------------------------------------------------- /Base/Enums/EnumCacheDb.cs_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// Redis cache database 序號, 其值為 database area, 最多12個 6 | /// 7 | public enum EnumCacheDb 8 | { 9 | //第1群 10 | Table, 11 | Column, 12 | Rows, 13 | Row, 14 | 15 | //第2群 16 | QueryTable, 17 | Query, 18 | 19 | //第3群 20 | Group, 21 | 22 | //其他 23 | Session, 24 | Log, 25 | Mail, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BaseApi/Services/_HttpSafe.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System.Web; 3 | //.Security.AntiXss; 4 | 5 | namespace BaseApi.Services 6 | { 7 | /// 8 | /// handle web security issue 9 | /// 10 | public class _HttpSafe 11 | { 12 | public static string JsonToStr(JObject json) 13 | { 14 | return (json == null) 15 | ? "" 16 | : HttpUtility.HtmlEncode(json.ToString()); 17 | } 18 | 19 | }//class 20 | } 21 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiHtmlViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | /// 9 | /// html editor 10 | /// 11 | public class XiHtmlViewComponent : ViewComponent 12 | { 13 | public HtmlString Invoke(XiHtmlDto dto) 14 | { 15 | return new HtmlString(_Input.XiHtml(dto)); 16 | } 17 | 18 | } //class 19 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiDecViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //integer/decimal input(3 different: class name, input arg, digit=true !!) 9 | public class XiDecViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(XiDecDto dto) 12 | { 13 | return new HtmlString(_Input.XiDec(dto)); 14 | } 15 | 16 | }//class 17 | } 18 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiIntViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //integer/decimal input(3 different: class name, input arg, digit=true !!) 9 | public class XiIntViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(XiIntDto dto) 12 | { 13 | return new HtmlString(_Input.XiInt(dto)); 14 | } 15 | 16 | }//class 17 | } 18 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiLinkViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | /// 9 | /// link file 10 | /// 11 | public class XiLinkViewComponent : ViewComponent 12 | { 13 | public HtmlString Invoke(XiLinkDto dto) 14 | { 15 | return new HtmlString(_Input.XiLink(dto)); 16 | } 17 | 18 | } //class 19 | } 20 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiSelectDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace BaseWeb.Models 5 | { 6 | public class XiSelectDto : XiBaseDto 7 | { 8 | /* 9 | public XiSelectDto() 10 | { 11 | AddEmptyRow = true; 12 | } 13 | */ 14 | 15 | public List? Rows { get; set; } 16 | 17 | //AddEmptyRow -> AddEmpty 18 | public bool AddEmpty { get; set; } = true; 19 | public string FnOnChange { get; set; } = ""; 20 | } 21 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiHideViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | public class XiHideViewComponent : ViewComponent 9 | { 10 | /// 11 | /// hidden field 12 | /// 13 | public HtmlString Invoke(XiHideDto dto) 14 | { 15 | return new HtmlString(_Input.XiHide(dto)); 16 | } 17 | 18 | }//class 19 | } 20 | -------------------------------------------------------------------------------- /SmsTaiwan/SmsTaiwan.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiRadioViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | //TODO: modifing 7 | namespace BaseWeb.ViewComponents 8 | { 9 | //Radio button group, consider horizontal or vertical 10 | public class XiRadioViewComponent : ViewComponent 11 | { 12 | public HtmlString Invoke(XiRadioDto dto) 13 | { 14 | return new HtmlString(_Input.XiRadio(dto)); 15 | } 16 | 17 | }//class 18 | } 19 | -------------------------------------------------------------------------------- /PdfSpire/PdfSpire.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiReadDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiReadDto : XiBaseDto 4 | { 5 | public string Format { get; set; } = ""; 6 | 7 | /// 8 | /// 是否儲存DB, default false 9 | /// 10 | public bool SaveDb { get; set; } = false; 11 | 12 | /// 13 | /// edit field style, default false 14 | /// 15 | public bool EditStyle { get; set; } = false; 16 | 17 | //public int Width { get; set; } = 0; 18 | } 19 | } -------------------------------------------------------------------------------- /Base/Models/ChangeValueDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | //for edit form 5 | public class ChangeValueDto 6 | { 7 | /// 8 | /// key 9 | /// 10 | public string Key { get; set; } = ""; 11 | 12 | /// 13 | /// old value 14 | /// 15 | public string OldValue { get; set; } = ""; 16 | 17 | /// 18 | /// new value 19 | /// 20 | public string NewValue { get; set; } = ""; 21 | } 22 | } -------------------------------------------------------------------------------- /Base/Models/WordRowsDto.cs_old: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | 3 | namespace Base.Models 4 | { 5 | //for word rows 6 | public class WordRowsDto 7 | { 8 | /// 9 | /// box tag(tr) 10 | /// 11 | public string TagName = "tr"; 12 | 13 | /// 14 | /// box tag 15 | /// 16 | public string BoxTag = "tr"; 17 | 18 | /// 19 | /// rows 20 | /// 21 | public JArray Rows = null; 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /BaseEther/BaseEther.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Base/Enums/QitemTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// query item type 5 | /// 6 | public enum QitemTypeEnum 7 | { 8 | //Identity, 9 | //Identity2, //child table maps to parent Identity 10 | None, 11 | //Num, 12 | Date, //if only input one date then find this day, if date of xxx2 existed then find range 13 | Date2, //2nd date field(start/end), for query 14 | DT, //datetime 15 | //TimeTick, 16 | //Html, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BaseFlow/Services/XgFlowR.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | using Newtonsoft.Json.Linq; 4 | 5 | namespace BaseFlow.Services 6 | { 7 | public class XgFlowR 8 | { 9 | private readonly ReadDto dto = new() 10 | { 11 | ReadSql = @" 12 | select * 13 | from dbo.XpFlow 14 | order by Id 15 | ", 16 | }; 17 | 18 | public async Task GetPageA(string ctrl, DtDto dt) 19 | { 20 | return await new CrudReadSvc().GetPageA(dto, dt, ctrl); 21 | } 22 | 23 | } //class 24 | } 25 | -------------------------------------------------------------------------------- /Base/Enums/SignerTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | //match to Code.Type="SignerType" 4 | public static class SignerTypeEstr 5 | { 6 | //public const string User = "U"; //assign user 7 | public const string Fid = "F"; //assign field id 8 | public const string UserMgr = "UM"; //user dept manager 9 | public const string DeptMgr = "DM"; //assign dept manager 10 | public const string Role = "R"; //assign dept manager 11 | //public const string Role = "R"; //temp remark 12 | } 13 | } -------------------------------------------------------------------------------- /Base/Enums/TextTypeEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// text type for jquery validate 6 | /// 7 | public class TextTypeEstr 8 | { 9 | public const string Text = "text"; 10 | public const string Password = "password"; 11 | public const string Email = "email"; 12 | public const string Url = "url"; 13 | //public const string Digits = "digits"; //integer 14 | //public const string Number = "number"; //float 15 | public const string CreditCard = "creditcard"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BaseApi/Services/_Device.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace BaseApi.Services 3 | { 4 | //device related 5 | public class _Device 6 | { 7 | /// 8 | /// check mobile 9 | /// 10 | /* 11 | public static bool IsMobile() 12 | { 13 | return false; 14 | var browser = _Http.GetRequest().Browser; 15 | //System.Web.HttpBrowserCapabilitiesBase myBrowserCaps = Request.Browser; 16 | return _Http.GetRequest().Browser.IsMobileDevice; 17 | } 18 | */ 19 | }//class 20 | } 21 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiTextareaDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace BaseWeb.Models 4 | { 5 | public class XiTextareaDto : XiBaseDto 6 | { 7 | /* 8 | public XiTextareaDto() 9 | { 10 | MaxLen = 0; 11 | RowsCount = 3; 12 | } 13 | */ 14 | 15 | public int MaxLen { get; set; } = 0; 16 | public int RowsCount { get; set; } = 3; 17 | 18 | /// 19 | /// 對應 InputPatternEstr 20 | /// 21 | public string Pattern { get; set; } = InputPatternEstr.EngNumExt; 22 | } 23 | } -------------------------------------------------------------------------------- /Base/Models/UserProfile0Model.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System; 3 | 4 | namespace Base.Models 5 | { 6 | /// 7 | /// basic user profile data for base class 8 | /// 9 | public class UserProfile0Model 10 | { 11 | //user id 12 | public string UserId = ""; 13 | 14 | //user id 15 | public string DeptId = ""; 16 | 17 | //locale code 18 | public string Locale = _Fun.Locale; 19 | 20 | //diffence hours to GMT for Db saving 21 | public Double DiffHour = 0; 22 | 23 | }//class 24 | } 25 | -------------------------------------------------------------------------------- /BaseApi/Services/XgFlowRead.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | using Newtonsoft.Json.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace BaseApi.Services 7 | { 8 | public class XgFlowRead 9 | { 10 | private readonly ReadDto dto = new() 11 | { 12 | ReadSql = @" 13 | select * 14 | from dbo.XpFlow 15 | order by Id 16 | ", 17 | }; 18 | 19 | public async Task GetPageA(string ctrl, DtDto dt) 20 | { 21 | return await new CrudReadSvc().GetPageA(dto, dt, ctrl); 22 | } 23 | 24 | } //class 25 | } 26 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiTextDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace BaseWeb.Models 4 | { 5 | public class XiTextDto : XiBaseDto 6 | { 7 | /* 8 | public XiTextDto() 9 | { 10 | MaxLen = 0; 11 | IsPwd = false; 12 | } 13 | */ 14 | 15 | public int MaxLen { get; set; } = 0; 16 | public bool IsPwd { get; set; } = false; 17 | 18 | /// 19 | /// 對應 InputPatternEstr, 如為中文, 則會 20 | /// 21 | public string Pattern { get; set; } = InputPatternEstr.EngNumExt; 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /Base/Models/PropFileDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// file property 6 | /// 7 | public class PropFileDto : PropBaseDto 8 | { 9 | 10 | /// 11 | /// max size(M) 12 | /// 13 | public int MaxSize = 5; 14 | 15 | /// 16 | /// allow extension list, sep with "," 17 | /// 18 | public string FileExts = ""; 19 | 20 | /// 21 | /// description 22 | /// 23 | public string Note = ""; 24 | 25 | }//class 26 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiTextViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | /// 9 | /// text input 10 | /// xi-box用來顯示 validation error(相鄰位置), 大多數欄位的xi-box即為輸入欄位 11 | /// ClsBox會加到 xi-box上面 12 | /// 13 | public class XiTextViewComponent : ViewComponent 14 | { 15 | public HtmlString Invoke(XiTextDto dto) 16 | { 17 | return new HtmlString(_Input.XiText(dto)); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Base/Models/SmtpDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// smtp email 6 | /// 7 | public class SmtpDto 8 | { 9 | public string FromEmail { get; set; } = ""; 10 | 11 | //display sender name when get email 12 | public string FromName { get; set; } = ""; 13 | 14 | public string Host { get; set; } = ""; 15 | public int Port { get; set; } 16 | 17 | //sender account 18 | public string Id { get; set; } = ""; 19 | 20 | public string Pwd { get; set; } = ""; 21 | public bool Ssl = true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Base/Models/PropTextAreaDto.c_old: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// text/textarea field 7 | /// 8 | public class PropTextAreaDto : PropBaseDto 9 | { 10 | 11 | /// 12 | /// placeholder 13 | /// 14 | public string PlaceHolder = ""; 15 | 16 | /// 17 | /// width 18 | /// 19 | public string Width = "100%"; 20 | 21 | /// 22 | /// data type 23 | /// 24 | public int RowsNum = 3; 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /BaseWeb/Models/XiRadioDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace BaseWeb.Models 5 | { 6 | public class XiRadioDto : XiBaseDto 7 | { 8 | /* 9 | public XiRadioDto() 10 | { 11 | IsHori = true; 12 | } 13 | */ 14 | 15 | public List Rows { get; set; } = null!; 16 | 17 | /** 18 | * 預設為水平排列 19 | */ 20 | public bool IsHori { get; set; } = true; 21 | 22 | //FnOnChange -> FnOnClick(實際使用 onclick 事件) 23 | public string FnOnClick { get; set; } = ""; 24 | } 25 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiDateViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseWeb.Models; 3 | using BaseWeb.Services; 4 | using Microsoft.AspNetCore.Html; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace BaseWeb.Helpers 8 | { 9 | //use bootstrap datepicker 10 | public class XiDateViewComponent : ViewComponent 11 | { 12 | /// 13 | /// date field 14 | /// 15 | /// 16 | public HtmlString Invoke(XiDateDto dto) 17 | { 18 | return new HtmlString(_Input.XiDate(dto)); 19 | } 20 | 21 | }//calss 22 | } 23 | -------------------------------------------------------------------------------- /Base/Enums/CheckTypeEstr.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Enums 2 | { 3 | /// 4 | /// mapping to jquery validate 5 | /// 6 | public class CheckTypeEstr 7 | { 8 | public const string None = "0"; 9 | public const string Email = "Email"; 10 | public const string Url = "Url"; 11 | public const string Min = "Min"; 12 | public const string Max = "Max"; 13 | public const string Range = "Range"; 14 | //public const string CreditCard = "CC"; 15 | //public const string Digits = "DI"; 16 | //public const string Number = "NU"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Base/Models/PropTextDto.c_old: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// text/textarea field 7 | /// 8 | public class PropTextDto : PropBaseDto 9 | { 10 | 11 | /// 12 | /// placeholder 13 | /// 14 | public string PlaceHolder = ""; 15 | 16 | /// 17 | /// width 18 | /// 19 | public string Width = "100%"; 20 | 21 | /// 22 | /// data type 23 | /// 24 | public string Type = TextTypeEstr.Text; 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Base/Services/_Result.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System; 3 | using System.DirectoryServices; 4 | 5 | namespace Base.Services 6 | { 7 | //後端執行結果 8 | public class _Result 9 | { 10 | /// 11 | /// 檢查是否有錯誤 12 | /// 13 | /// 14 | /// 15 | public static bool HasError(ResultDto result) 16 | { 17 | return _Str.NotEmpty(result._ErrorMsg) 18 | ? true 19 | : (result.ErrorRows != null && result.ErrorRows.Count > 0); 20 | } 21 | 22 | }//class 23 | } 24 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgCreateViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XgCreateViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke(string fnOnClick = "_me.crudR.onCreate") 10 | { 11 | var label = _Locale.GetBaseRes().BtnCreate; 12 | return new HtmlString($@" 13 | "); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgProgPathViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Html; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace BaseWeb.ViewComponents 5 | { 6 | public class XgProgPathViewComponent : ViewComponent 7 | { 8 | /// 9 | /// program path 10 | /// 11 | /// prog path list 12 | /// 13 | public HtmlString Invoke(string path = "") 14 | { 15 | var html = $"
{path}
"; 16 | return new HtmlString(html); 17 | } 18 | 19 | } //class 20 | } -------------------------------------------------------------------------------- /Base/Services/_Office.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Newtonsoft.Json.Linq; 3 | using NPOI.SS.UserModel; 4 | using NPOI.XSSF.UserModel; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Threading.Tasks; 9 | 10 | namespace Base.Services 11 | { 12 | //for word, excel file 13 | public class _Office 14 | { 15 | 16 | public static bool DocxToFile(IWorkbook docx, string filePath) 17 | { 18 | using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); 19 | docx.Write(fs); 20 | return true; 21 | } 22 | } //class 23 | } 24 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgExportViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XgExportViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke(string fnOnClick = "_me.crudR.onExport") 10 | { 11 | //var rb = _Locale.RB; 12 | var html = $""; 13 | return new HtmlString(html); 14 | } 15 | 16 | } //class 17 | } -------------------------------------------------------------------------------- /BaseFlow/BaseFlow.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiCheckViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | /// 9 | /// checkbox component 10 | /// 11 | public class XiCheckViewComponent : ViewComponent 12 | { 13 | /// 14 | /// checkbox component 15 | /// 16 | /// 17 | public HtmlString Invoke(XiCheckDto dto) 18 | { 19 | return new HtmlString(_Input.XiCheck(dto)); 20 | } 21 | 22 | }//class 23 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XiFileViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Models; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | /// 9 | /// file input 10 | /// 11 | public class XiFileViewComponent : ViewComponent 12 | { 13 | /// 14 | /// file upload, 15 | /// 16 | /// 17 | public HtmlString Invoke(XiFileDto dto) 18 | { 19 | return new HtmlString(_Input.XiFile(dto)); 20 | } 21 | 22 | } //class 23 | } 24 | -------------------------------------------------------------------------------- /BaseEther/Models/EventLogDto.cs: -------------------------------------------------------------------------------- 1 | using Nethereum.ABI.FunctionEncoding.Attributes; 2 | 3 | namespace BaseEther.Models 4 | { 5 | [Event("EventLog")] 6 | public class EventLogDto : IEventDTO 7 | { 8 | //第4個參數表示是否建立索引, 必須與solidity event內容一致 9 | //log屬性配合solidity使用小寫 10 | [Parameter("string", "log", 1, false)] 11 | public string log { get; set; } 12 | 13 | /* 14 | [Parameter("string", "myString", 1, true)] 15 | public string MyString { get; set; } 16 | 17 | [Parameter("uint256", "myNumber", 2, true)] 18 | public BigInteger MyNumber { get; set; } 19 | */ 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Base/Models/UploadDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | //for 檔案上傳 4 | public class UploadDto 5 | { 6 | /// 7 | /// 主機實體路徑 for save檔案, 如果空白則表示目前程式路徑 8 | /// Path表示實際路徑, url表示連結路徑 9 | /// 10 | public string ServerPath = ""; 11 | 12 | /// 13 | /// 儲存目錄, 不可空白 14 | /// ServerPath + SaveDir + 檔案名稱 = 儲存路徑 15 | /// 16 | public string SaveDir = ""; 17 | 18 | /// 19 | /// 檔案連結前面的字串 20 | /// PreUrl + SaveDir + 檔案名稱 = 檔案在網頁上的 url 21 | /// 22 | public string PreUrl = ""; 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /Base/Models/DbFormatDto.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// transform format when read db, ex:date, dollar... 5 | /// 6 | public class DbFormatDto 7 | { 8 | // 9 | //public string DataType { get; set; } 10 | 11 | //backend read db to client 12 | public string FrontDate { get; set; } 13 | public string FrontDt { get; set; } 14 | public string FrontDtNoSec { get; set; } //no second 15 | 16 | //client to backend for write db 17 | //public string BackDt = "yyyy/MM/dd hh:mm:ss"; //24 hour 18 | //public string BackDate = "yyyy/MM/dd"; 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BaseApi/Services/XgEasyRptRead.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | using Newtonsoft.Json.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace BaseApi.Services 7 | { 8 | public class XgEasyRptRead 9 | { 10 | private readonly ReadDto dto = new() 11 | { 12 | ReadSql = @" 13 | select * from dbo.XpEasyRpt 14 | order by Id 15 | ", 16 | Items = [ 17 | new() { Fid = "Name" }, 18 | ], 19 | }; 20 | 21 | public async Task GetPageA(string ctrl, DtDto dt) 22 | { 23 | return await new CrudReadSvc().GetPageA(dto, dt, ctrl); 24 | } 25 | 26 | } //class 27 | } -------------------------------------------------------------------------------- /Base/Services/_Datatable.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | 3 | namespace Base.Services 4 | { 5 | public static class _Datatable 6 | { 7 | //get value in findJson 8 | public static string GetFindValue(DtDto dt, string fid) 9 | { 10 | if (dt.findJson == null) return ""; 11 | var json = _Str.ToJson(dt.findJson); 12 | return (json == null) 13 | ? "" : _Json.NullFieldToEmpty(json, fid); 14 | 15 | //return _Json.NullFieldToEmpty(_Str.ToJson(dt.findJson), fid); 16 | //return (findJson == null) 17 | // ? _Object.NullToEmpty(findJson![fid]) 18 | // : ""; 19 | } 20 | 21 | }//class 22 | } 23 | -------------------------------------------------------------------------------- /Base/Models/QitemDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace Base.Models 4 | { 5 | //query fields 6 | public class QitemDto 7 | { 8 | //client field id 9 | public string Fid = ""; 10 | 11 | //column id, has table alias 12 | public string Col = ""; 13 | 14 | /// 15 | /// where compare operator, default ItemOpEstr.Equal 16 | /// 17 | public string Op = ItemOpEstr.Equal; 18 | 19 | //query field data type 20 | public QitemTypeEnum Type = QitemTypeEnum.None; 21 | 22 | //other info, when Type=Date2, Other=another Date Col, ex: ShowEnd/u.ShowEnd 23 | public string Other = ""; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Base/Services/_Var.cs: -------------------------------------------------------------------------------- 1 | using DocumentFormat.OpenXml.Office2013.PowerPoint.Roaming; 2 | 3 | namespace Base.Services 4 | { 5 | public class _Var 6 | { 7 | public static bool IsEmpty(object? data) 8 | { 9 | return (data == null || data.ToString() == ""); 10 | } 11 | 12 | public static bool NotEmpty(object? data) 13 | { 14 | return !_Var.IsEmpty(data); 15 | } 16 | 17 | public static bool ToBool(object? data) 18 | { 19 | if (data == null) return false; 20 | var value = data.ToString()!; 21 | return (value == "1" || value.ToLower() == "true"); 22 | ; 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgSaveViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XgSaveViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke(string align = "center", string fnOnSave = "_me.crudE.onSaveA()") 10 | { 11 | var baseR = _Locale.GetBaseRes(); 12 | var html = $@" 13 |
14 | 15 |
16 | "; 17 | return new HtmlString(html); 18 | } 19 | 20 | } //class 21 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgAddRowViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //add row button 9 | public class XgAddRowViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(string fnOnClick) 12 | { 13 | //todo: 14 | var attr = _Input.GetEventAttr("onclick", fnOnClick); 15 | var html = $@" 16 | 19 | "; 20 | return new HtmlString(html); 21 | } 22 | }//class 23 | } 24 | -------------------------------------------------------------------------------- /Base/Models/ErrorFieldDto.cs_old: -------------------------------------------------------------------------------- 1 | //using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | public class ErrorFieldDto 6 | { 7 | /// 8 | /// 錯誤訊息 9 | /// 10 | public string Fid = ""; 11 | 12 | /// 13 | /// 錯誤訊息 14 | /// 15 | public string ErrorMsg = ""; 16 | 17 | /// 18 | /// 資料群組, base 0 19 | /// 20 | public int GroupNo = 0; 21 | 22 | /// 23 | /// 是否多筆 24 | /// 25 | public bool IsMulti = false; 26 | 27 | /// 28 | /// 資料序號 29 | /// 30 | public int RowNo = 0; 31 | } 32 | } -------------------------------------------------------------------------------- /BaseWeb/Helpers_old/XgTitleHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Html; 2 | using Microsoft.AspNetCore.Mvc.Rendering; 3 | 4 | namespace BaseWeb.Helpers 5 | { 6 | //field title, no row container 7 | //title is before field, label is after field 8 | public static class XgTitleHelper 9 | { 10 | public static IHtmlContent XgTitle(this IHtmlHelper htmlHelper, string label, bool required = false, int cols = 2) 11 | { 12 | var reqStr = required ? "*" : ""; 13 | var html = string.Format(@" 14 |
{0} 15 | {2} 16 |
17 | ", label, cols, reqStr); 18 | 19 | return new HtmlString(html); 20 | } 21 | 22 | }//class 23 | } 24 | -------------------------------------------------------------------------------- /BaseWeb/Models/XgFindTbarDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XgFindTbarDto 4 | { 5 | /* 6 | public XgFindTbarDto() 7 | { 8 | IsHori = true; 9 | HasReset = false; 10 | HasFind2 = false; 11 | } 12 | */ 13 | 14 | //span mode, default false, 表示工具列會包在col裡面, 如果true, 則此工具列會和緊鄰左側欄位 15 | public bool SpanMode { get; set; } = false; 16 | public bool IsHori { get; set; } = true; 17 | public bool HasReset { get; set; } = false; 18 | public bool HasFind2 { get; set; } = false; 19 | 20 | /// 21 | /// 傳回bool 22 | /// 23 | //public string FnWhenFind { get; set; } = ""; 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /Base/Enums/PatternEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// input pattern 6 | /// 7 | public class PatternEstr 8 | { 9 | //alphabetic 10 | //public const string AlphaNum = "[A-Z0-9a-z]"; 11 | 12 | //numeric 13 | //public const string Number = "[\\d]"; 14 | 15 | //alphabetic, underline(c# need escape) 16 | public const string Word = @"^[\w]+$"; 17 | 18 | //numeric, space 19 | public const string Phone = @"^[\d\s]+$"; 20 | 21 | //Word, chinese, space, ".", "_" 22 | public const string Normal = @"^[\u4e00-\u9fa5\w\s._]+$"; 23 | 24 | //html 25 | //public const string Html = "textarea"; 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgDeleteRowViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseApi.Services; 3 | using BaseWeb.Services; 4 | using Microsoft.AspNetCore.Html; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace BaseWeb.ViewComponents 8 | { 9 | //add row button 10 | public class XgDeleteRowViewComponent : ViewComponent 11 | { 12 | public HtmlString Invoke(string fnOnClick) 13 | { 14 | //var rb = _Locale.RB; 15 | var html = string.Format(@" 16 | ", fnOnClick, _Locale.GetBaseRes().TipDeleteRow); 19 | 20 | return new HtmlString(html); 21 | } 22 | 23 | }//class 24 | } 25 | -------------------------------------------------------------------------------- /BaseApi/Services/XgProgRead.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Models; 3 | using Base.Services; 4 | using Newtonsoft.Json.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace BaseApi.Services 8 | { 9 | public class XgProgRead 10 | { 11 | private readonly ReadDto dto = new() 12 | { 13 | ReadSql = @" 14 | select * from dbo.XpProg 15 | order by Sort 16 | ", 17 | Items = [ 18 | new() { Fid = "Code", Op = ItemOpEstr.Like }, 19 | new() { Fid = "Name", Op = ItemOpEstr.Like }, 20 | ], 21 | }; 22 | 23 | public async Task GetPageA(string ctrl, DtDto dt) 24 | { 25 | return await new CrudReadSvc().GetPageA(dto, dt, ctrl); 26 | } 27 | 28 | } //class 29 | } -------------------------------------------------------------------------------- /Base/Models/SignLineDto.cs: -------------------------------------------------------------------------------- 1 | //using Base.Enums; 2 | 3 | namespace Base.Models 4 | { 5 | //workflow sign line 6 | public class SignLineDto 7 | { 8 | public string FlowId { get; set; } = ""; 9 | public string FromNodeId { get; set; } = ""; 10 | public string FromNodeName { get; set; } = ""; 11 | public string FromNodeType { get; set; } = ""; 12 | 13 | public string ToNodeId { get; set; } = ""; 14 | public string ToNodeName { get; set; } = ""; 15 | public string ToNodeType { get; set; } = ""; 16 | 17 | public string SignerType { get; set; } = ""; 18 | public string SignerValue { get; set; } = ""; 19 | 20 | public int Sort { get; set; } 21 | public string CondStr { get; set; } = ""; 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /Base/Models/CrudTbarDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// crud toolbar model 6 | /// 7 | public class CrudTbarDto 8 | { 9 | /// 10 | /// fn onclick find button 11 | /// 12 | public string FnOnFind = "_me.crudR.onFind()"; 13 | 14 | /// 15 | /// fn onclick find2 button 16 | /// 17 | public string FnOnFind2 = "_me.crudR.onFind2()"; 18 | 19 | /// 20 | /// onCreate 21 | /// 22 | public string FnOnCreate = "_me.crudR.onCreate()"; 23 | 24 | /// 25 | /// onCreate 26 | /// 27 | public string FnOnExport = "_me.crudR.onExport()"; 28 | } 29 | } -------------------------------------------------------------------------------- /Base/Models/ErrorRowDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | public class ErrorRowDto 4 | { 5 | //constructor 6 | public ErrorRowDto() 7 | { 8 | Fid = ""; 9 | Msg = ""; 10 | FormId = ""; 11 | RowId = ""; 12 | } 13 | 14 | public string Fid { get; set; } 15 | public string Msg { get; set; } 16 | public string FormId { get; set; } 17 | 18 | /// 19 | /// 用這個欄位來判別錯誤欄位是在那一個資料群組, for update多筆資料時 20 | /// 21 | public string RowId { get; set; } 22 | 23 | /// 24 | /// 輸入錯誤的欄位id清單, type為Key(id), Value(錯誤訊息) 25 | /// 26 | //public List ErrorFields { get; set; } = null!; 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /Base/Interfaces/IPdfSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | 3 | namespace Base.Interfaces 4 | { 5 | public interface IPdfSvc 6 | { 7 | 8 | void SetKey(string keyPath); 9 | 10 | /// 11 | /// convert word(docx) to pdf 12 | /// 13 | /// 14 | /// 15 | byte[] WordToPdf(byte[] wordBytes, string keyPath = ""); 16 | 17 | /// 18 | /// pdf 增加多個圖檔 19 | /// 20 | /// 21 | /// 新pdf檔案 22 | /// 23 | /// 24 | bool AddImages(string fromPath, string toPath, PdfImageDto[] imageDtos); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Base/Models/EmailDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// smtp email 7 | /// 8 | public class EmailDto 9 | { 10 | public string Subject { get; set; } = ""; 11 | 12 | //email body 13 | public string Body { get; set; } = ""; 14 | 15 | public List ToUsers { get; set; } = null!; 16 | 17 | public List? CcUsers { get; set; } 18 | 19 | //attach files 20 | public List? Files { get; set; } 21 | 22 | public List? Images { get; set; } 23 | 24 | //image id list 25 | //public List ImageIds { get; set; } 26 | 27 | //image path list 28 | //public List ImagePaths { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BaseApi/Attributes/XgReqAttribute.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace BaseApi.Attributes 5 | { 6 | public class XgReqAttribute : RequiredAttribute 7 | { 8 | /* 9 | public XgReqAttribute() 10 | { 11 | ErrorMessage = _Fun.GetBaseRes().Required; 12 | } 13 | */ 14 | 15 | protected override ValidationResult IsValid(object? value, ValidationContext validationContext) 16 | { 17 | //_Locale.GetBaseRes()!.Required 18 | var result = base.IsValid(value, validationContext); 19 | if (_Str.NotEmpty(ErrorMessage)) 20 | ErrorMessage = validationContext.MemberName + " Required"; 21 | return result!; 22 | } 23 | 24 | } //class 25 | } 26 | -------------------------------------------------------------------------------- /BaseWeb/Models/XgThDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XgThDto 4 | { 5 | /* 6 | public XgThDto() 7 | { 8 | Title = ""; 9 | Tip = ""; 10 | Required = false; 11 | ClsExt = ""; 12 | HideRwd = false; 13 | MinWidth = 0; 14 | } 15 | */ 16 | 17 | public string Title { get; set; } = ""; 18 | public string Tip { get; set; } = ""; 19 | public bool Required { get; set; } = false; 20 | 21 | //ExtClass -> ClsExt 22 | public string ClsExt { get; set; } = ""; 23 | 24 | //min width, 0 for not set 25 | public int MinWidth { get; set; } = 0; 26 | 27 | //hide for RWD phone 28 | public bool HideRwd { get; set; } = false; 29 | } 30 | } -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgOpenModalViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | //open modal for table 8 | //link with button style(always enabled) 9 | public class XgOpenModalViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(string title, string fid, bool required, int maxLen) 12 | { 13 | var btnOpen = _Locale.GetBaseRes().BtnOpen; 14 | var req = required ? "true" : "false"; 15 | var html = $"{btnOpen}"; 16 | return new HtmlString(html); 17 | } 18 | 19 | }//class 20 | } 21 | -------------------------------------------------------------------------------- /Base/Models/PropNumDto.c_old: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// text/textarea field 5 | /// 6 | public class PropNumDto : PropBaseDto 7 | { 8 | 9 | /// 10 | /// placeholder 11 | /// 12 | public string PlaceHolder = ""; 13 | 14 | /// 15 | /// width 16 | /// 17 | public string Width = "100%"; 18 | 19 | /// 20 | /// digits(true) or float(false) 21 | /// 22 | public bool IsDigit = true; 23 | 24 | public decimal? MaxValue = null; 25 | public decimal? MinValue = null; 26 | 27 | /// 28 | /// data type 29 | /// 30 | //public string Type = EnumTextType.Text; 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /BaseApi/Services/XgTranLogRead.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Models; 3 | using Base.Services; 4 | using Newtonsoft.Json.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace BaseApi.Services 8 | { 9 | public class XgTranLogRead 10 | { 11 | private readonly ReadDto dto = new() 12 | { 13 | ReadSql = @" 14 | select * 15 | from dbo.XpTranLog 16 | order by Sn desc 17 | ", 18 | Items = new QitemDto[] { 19 | new() { Fid = "TableName", Op = ItemOpEstr.Like }, 20 | new() { Fid = "ColName", Op = ItemOpEstr.Like }, 21 | new() { Fid = "RowId" }, 22 | }, 23 | }; 24 | 25 | public async Task GetPageA(string ctrl, DtDto dt) 26 | { 27 | return await new CrudReadSvc().GetPageA(dto, dt, ctrl); 28 | } 29 | 30 | } //class 31 | } -------------------------------------------------------------------------------- /Base/Models/ResultImportDto.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// import result dto, namig for file sorting 6 | /// 7 | public class ResultImportDto 8 | { 9 | /// 10 | /// row id 11 | /// 12 | public string LogRowId = ""; 13 | 14 | /// 15 | /// ok rows count 16 | /// 17 | public int OkCount; 18 | 19 | /// 20 | /// fail rows count 21 | /// 22 | public int FailCount; 23 | 24 | /// 25 | /// total rows count 26 | /// 27 | public int TotalCount; 28 | 29 | /// 30 | /// error msg if any (necessary field for resultXXX dto) 31 | /// 32 | public string _ErrorMsg = ""; 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /BaseFlow/Areas/XpFlow/FlowTest.cshtml: -------------------------------------------------------------------------------- 1 | @using BaseWeb.ViewComponents 2 | @using BaseWeb.Models 3 | 4 |
5 |
6 | @await Component.InvokeAsync("XiTextarea", new XiTextareaDto { Title = "輸入流程資料", Fid = "Data", Required = true, RowsCount = 6, InRow = true, Cols = "2,4" }) 7 |
8 | 範例(JSON格式),UserId必填:
9 | UserId: "Alex",
10 | AgentId: "Nick",
11 | LeaveType: "S",
12 | Hours: 8,
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 | 21 | 22 |
23 |
24 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiFileDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiFileDto : XiBaseDto 4 | { 5 | /* 6 | public XiFileDto() 7 | { 8 | MaxSize = 10; 9 | FileType = "I"; //image 10 | //FnOnOpenFile = "_ifile.onOpenFile(this)"; 11 | //FnOnDeleteFile = "_ifile.onDeleteFile(this)"; 12 | } 13 | */ 14 | 15 | //for onViewFile() 16 | public string Table { get; set; } = ""; 17 | 18 | public int MaxSize { get; set; } = 10; 19 | 20 | //*(all),I(image),E(excel),W(word) 21 | public string FileType { get; set; } = "I"; //image 22 | 23 | //取消, 固定呼叫_me.onViewFile, 同時傳入table, fid 24 | //public string FnOnViewFile { get; set; } = ""; 25 | //public string FnOnOpenFile { get; set; } 26 | //public string FnOnDeleteFile { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /BaseApi/Attributes/XgRB0Attribute.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Mvc.Filters; 4 | 5 | namespace BaseWeb.Attributes 6 | { 7 | //設定ViewBag.RB for locale, 同時切換多國語for view 8 | //annotation for controller only !! 9 | public class XgRB0Attribute : ActionFilterAttribute 10 | { 11 | //外部傳入參數(語系), 如果無, 則取預設值 12 | public string Locale = ""; 13 | 14 | public override void OnActionExecuting(ActionExecutingContext context) 15 | { 16 | /* //todo 17 | string locale = (Locale != "") ? Locale : _Fun.DefaultLocale; 18 | if (_Helper.SetRB(context, locale)) 19 | base.OnActionExecuting(context); 20 | */ 21 | 22 | //return 23 | //base.OnActionExecuting(context); 24 | //return; 25 | } 26 | 27 | }//class 28 | } 29 | -------------------------------------------------------------------------------- /Base/Models/EasyPageDto.cs_old: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// for return to jquery simple pagination 7 | /// refer CrudRead.cs GetPageAsync() return json 8 | /// 9 | /// 10 | public class EasyPageDto 11 | { 12 | public EasyPageDto() 13 | { 14 | data = new List(); 15 | } 16 | 17 | //public int draw { get; set; } 18 | public int page { get; set; } 19 | 20 | //condition rows count 21 | public int recordsFiltered { get; set; } 22 | 23 | public List data { get; set; } 24 | 25 | /// 26 | /// error msg if any (necessary field for resultXXX dto) 27 | /// refer ResultDto.cs 28 | /// 29 | public string ErrorMsg { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /BaseApi/Extensions/SessionExtension.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using Microsoft.AspNetCore.Http; 3 | using Newtonsoft.Json; 4 | 5 | namespace BaseApi.Extensions 6 | { 7 | public static class SessionExtension 8 | { 9 | public static void Set(this ISession session, string key, T value) 10 | { 11 | //var http = _Http.GetHttp(); 12 | //session.SetString(key, JsonSerializer.Serialize(value)); 13 | session.SetString(key, _Model.ToJsonStr(value)); 14 | } 15 | 16 | public static T? Get(this ISession session, string key) 17 | { 18 | var value = session.GetString(key); 19 | //return value == null ? default : JsonSerializer.Deserialize(value); 20 | return (value == null) 21 | ? default : JsonConvert.DeserializeObject(value); 22 | } 23 | 24 | } //class 25 | } 26 | -------------------------------------------------------------------------------- /BaseWeb/Enums/XiEstr.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Enums 2 | { 3 | /// 4 | /// 自訂輸入欄位元件名稱 5 | /// 6 | public class XiEstr 7 | { 8 | public const string Check = "XiCheck"; 9 | public const string Date = "XiDate"; 10 | public const string Dt = "XiDt"; 11 | public const string Dec = "XiDec"; 12 | public const string File = "XiFile"; 13 | public const string Hide = "XiHide"; 14 | public const string Html = "XiHtml"; 15 | public const string Int = "XiInt"; 16 | public const string Link = "XiLink"; 17 | public const string Modal = "XiModal"; 18 | public const string Radio = "XiRadio"; 19 | public const string Read = "XiRead"; 20 | public const string Select = "XiSelect"; 21 | public const string Text = "XiText"; 22 | public const string Textarea = "XiTextarea"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgSaveBackViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | public class XgSaveBackViewComponent : ViewComponent 8 | { 9 | public HtmlString Invoke(string align = "center", string fnOnSave = "_me.crudE.onSaveA", string fnOnBack = "_me.crudR.onToRead" ) 10 | { 11 | var baseR = _Locale.GetBaseRes(); 12 | var html = $@" 13 |
14 | 15 | 16 |
17 | "; 18 | return new HtmlString(html); 19 | } 20 | 21 | } //class 22 | } -------------------------------------------------------------------------------- /BaseApi/Services/XgEasyRptEdit.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | 4 | namespace BaseApi.Services 5 | { 6 | public class XgEasyRptEdit : BaseEditSvc 7 | { 8 | public XgEasyRptEdit(string ctrl) : base(ctrl) { } 9 | 10 | override public EditDto GetDto() 11 | { 12 | return new EditDto 13 | { 14 | Table = "dbo.XpEasyRpt", 15 | PkeyFid = "Id", 16 | Col4 = null, 17 | Items = 18 | [ 19 | new() { Fid = "Id" }, 20 | new() { Fid = "Name", Required = true }, 21 | new() { Fid = "TplFile", Required = true }, 22 | new() { Fid = "ToEmails" }, 23 | //new() { Fid = "ToRoles" }, 24 | new() { Fid = "Sql", Required = true }, 25 | new() { Fid = "Status" }, 26 | ], 27 | }; 28 | } 29 | 30 | } //class 31 | } 32 | -------------------------------------------------------------------------------- /Base/Models/SqlArgModel.cs_old: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// 7 | /// 8 | public class SqlArgModel 9 | { 10 | /// 11 | /// 讀取的欄位清單(逗號分隔) 12 | /// 此欄位用來考慮cache(有值: cache type1, 空白表示cache type2) 13 | /// 14 | //public string ColList = ""; 15 | 16 | /// 17 | /// sql statement 18 | /// 19 | public string Sql = ""; 20 | 21 | /// 22 | /// 傳入參數的欄位名稱 23 | /// 24 | public List ArgFids = null; 25 | 26 | /// 27 | /// 傳入參數的欄位值 28 | /// 29 | public List ArgValues = null; 30 | 31 | /// 32 | /// db 連線時間(秒), 如果為0則使用預設時間 33 | /// 34 | //public int ConnectSec = 0; 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /Base/Models/CacheReadModel.cs_old: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// 存取DB時使用的 cache組態 7 | /// 8 | public class CacheReadModel 9 | { 10 | /// 11 | /// primary key 的欄位名稱 12 | /// 13 | public string Kid; 14 | 15 | /// 16 | /// primary key 是否為字串, default true 17 | /// 18 | public bool KeyIsString = true; 19 | 20 | /// 21 | /// 是否 join table, default false. 22 | /// 23 | public bool IsJoinTable = false; 24 | 25 | /// 26 | /// 讀取的 table 清單, 系統會轉小寫 27 | /// 28 | public string[] Tables; 29 | 30 | /// 31 | /// where 和 order by 的欄位清單, 不包含 table alias 32 | /// 33 | public List WhereOrders; 34 | } 35 | } -------------------------------------------------------------------------------- /Base/Models/MenuDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// menu item 7 | /// 8 | public class MenuDto 9 | { 10 | /* 11 | public MenuDto() 12 | { 13 | Items = new List(); 14 | } 15 | */ 16 | 17 | //如果功能表有2層, 使用GroupName分群 18 | public string GroupName { get; set; } = ""; 19 | 20 | //program Id 21 | public string Code { get; set; } = ""; 22 | 23 | //program name 24 | public string Name { get; set; } = ""; 25 | 26 | //if emtpy, means has child menu 27 | public string Url { get; set; } = ""; 28 | 29 | //sort 30 | public int Sort { get; set; } 31 | 32 | //icon class name 33 | public string Icon { get; set; } = ""; 34 | 35 | //sub menu items 36 | public List Items { get; set; } = new(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Base/Services/BaseUserSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Interfaces; 2 | using Base.Models; 3 | 4 | namespace Base.Services 5 | { 6 | public class BaseUserSvc : IBaseUserSvc 7 | { 8 | //private BaseUserDto _baseUser; 9 | 10 | /* 11 | //constructor 12 | public BaseUserService() 13 | { 14 | _baseUser = new BaseUserDto() 15 | { 16 | Locale = _Fun.Config.Locale, 17 | //UserId = "System", 18 | //UserName = "System", 19 | //HourDiff = 0, 20 | }; 21 | } 22 | */ 23 | 24 | //get base user info 25 | public BaseUserDto GetData() 26 | { 27 | return new BaseUserDto() 28 | { 29 | //Locale = _Fun.Config.Locale, 30 | //UserId = "System", 31 | //UserName = "System", 32 | //HourDiff = 0, 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Base/Models/ResultDto.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Models 5 | { 6 | /// 7 | /// for send server side result to front end 8 | /// 9 | public class ResultDto 10 | { 11 | /// 12 | /// result value 13 | /// 14 | public string Value = ""; 15 | 16 | /// 17 | /// error code if any 18 | /// 19 | public string Code = ""; 20 | 21 | /// 22 | /// error msg if any (necessary field for resultXXX dto) 23 | /// 避開資料表欄位, 前面加底線 24 | /// 25 | public string _ErrorMsg = ""; 26 | 27 | /// 28 | /// validation error list 29 | /// 30 | public List? ErrorRows = null; 31 | 32 | /// 33 | /// error js _BR fid 34 | /// 35 | //public string ErrorBrFid = ""; 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /Base/Services/_Guid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Base.Services 4 | { 5 | // 6 | public static class _Guid 7 | { 8 | public static string NewStr() 9 | { 10 | return Guid.NewGuid().ToString(); 11 | } 12 | 13 | public static string Encode(string guidText) 14 | { 15 | var guid = new Guid(guidText); 16 | return Encode(guid); 17 | } 18 | 19 | public static string Encode(Guid guid) 20 | { 21 | var code = Convert.ToBase64String(guid.ToByteArray()); 22 | code = code.Replace("/", "_"); 23 | code = code.Replace("+", "-"); 24 | return code[..22]; 25 | } 26 | 27 | public static Guid Decode(string encode) 28 | { 29 | encode = encode.Replace("_", "/"); 30 | encode = encode.Replace("-", "+"); 31 | var buffer = Convert.FromBase64String(encode + "=="); 32 | return new Guid(buffer); 33 | } 34 | 35 | }//class 36 | } 37 | -------------------------------------------------------------------------------- /Base/Services/_Array.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Services 5 | { 6 | public class _Array 7 | { 8 | //string[] to string 9 | public static string ToStr(string[] list, string sep = ",") 10 | { 11 | return (list.Length == 0) 12 | ? "" : string.Join(sep, list); 13 | } 14 | 15 | /// 16 | /// convert string array to IdStrDto list 17 | /// 18 | /// 19 | /// 20 | public static List ToIdStrs(params string[] args) 21 | { 22 | var data = new List(); 23 | for (var i=0; i 4 | /// 取代 DbAdm.Enums.QEitemTypeEstr 5 | /// input type, 對應輸入欄位 data-type=xxx(小camel) 6 | /// 7 | public class InputTypeEstr 8 | { 9 | public const string Check = "check"; 10 | public const string Date = "date"; 11 | public const string DateTime = "dt"; 12 | public const string Decimal = "dec"; 13 | public const string File = "file"; 14 | public const string Hide = "hide"; 15 | public const string Html = "html"; 16 | public const string Integer = "int"; 17 | public const string Link = "link"; 18 | public const string Modal = "modal"; 19 | public const string Password = "pwd"; 20 | public const string Radio = "radio"; 21 | public const string Read = "read"; 22 | public const string Select = "select"; 23 | public const string Sort = "sort"; 24 | public const string Text = "text"; 25 | public const string Textarea = "textarea"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Base/Models/PageOut.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// for RWD pagin output(jquery simple pagination) 7 | /// refer CrudRead.cs GetPageA() return json 8 | /// 9 | /// 10 | public class PageOut 11 | { 12 | /* 13 | public PageOut() 14 | { 15 | Rows = new List(); 16 | } 17 | */ 18 | 19 | //json string has: pageNo, pageRows, filterRows 20 | public string PageArg { get; set; } = ""; 21 | /* 22 | //public int draw { get; set; } 23 | public int page { get; set; } 24 | 25 | //condition rows count 26 | public int recordsFiltered { get; set; } 27 | */ 28 | 29 | public List? Rows { get; set; } 30 | 31 | /// 32 | /// error msg if any (necessary field for resultXXX dto) 33 | /// refer ResultDto.cs 34 | /// 35 | public string _ErrorMsg { get; set; } = ""; 36 | } 37 | } -------------------------------------------------------------------------------- /BaseApi/Services/XgImportRead.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Models; 3 | using Base.Services; 4 | using Newtonsoft.Json.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace BaseApi.Services 8 | { 9 | public class XgImportRead 10 | { 11 | private readonly string _importType; 12 | 13 | //constructor 14 | public XgImportRead(string importType) 15 | { 16 | _importType = importType; 17 | } 18 | 19 | private ReadDto GetDto() 20 | { 21 | return new ReadDto() 22 | { 23 | ReadSql = $@" 24 | select * 25 | from dbo.XpImportLog 26 | where Type='{_importType}' 27 | order by Created desc 28 | ", 29 | Items = [ 30 | new() { Fid = "FileName", Op = ItemOpEstr.Like }, 31 | ], 32 | }; 33 | } 34 | 35 | public async Task GetPageA(string ctrl, DtDto dt) 36 | { 37 | return await new CrudReadSvc().GetPageA(GetDto(), dt, ctrl); 38 | } 39 | 40 | } //class 41 | } -------------------------------------------------------------------------------- /Base/Services/CrudGetSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Models; 3 | using Newtonsoft.Json.Linq; 4 | using System.Threading.Tasks; 5 | 6 | /// 7 | /// 繼承 CrudEditGetSvc, 利用 EditDto 來讀取資料庫資料, 簡化子代內容 8 | /// 1.remove cache function 9 | /// 2.add read/write multiple table fun 10 | /// 11 | namespace Base.Services 12 | { 13 | /// 14 | /// for Crud Edit Service 15 | /// 16 | public class CrudGetSvc : CrudEditGetSvc 17 | { 18 | //constructor 19 | public CrudGetSvc(string ctrl, EditDto editDto, string dbStr = "") 20 | : base(ctrl, editDto, dbStr) 21 | { 22 | _ctrl = ctrl; 23 | _editDto = editDto; 24 | _dbStr = dbStr; 25 | } 26 | 27 | public async Task GetUpdJsonA(string key) 28 | { 29 | return await GetJsonByFunA(CrudEnum.Update, key); 30 | } 31 | public async Task GetViewJsonA(string key) 32 | { 33 | return await GetJsonByFunA(CrudEnum.View, key); 34 | } 35 | 36 | }//class 37 | } -------------------------------------------------------------------------------- /Base/Models/CalendarEventDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Base.Models 4 | { 5 | //https://www.helloweba.com/view-blog-231.html 6 | public class CalendarEventDto 7 | { 8 | public string id { get; set; } = ""; 9 | public string title { get; set; } = ""; 10 | public bool allDay { get; set; } 11 | public DateTime startDT { get; set; } 12 | public DateTime endDT { get; set; } 13 | public string start 14 | { 15 | get 16 | { 17 | return startDT.ToString("s"); 18 | } 19 | } 20 | public string end 21 | { 22 | get 23 | { 24 | return endDT.ToString("s"); 25 | } 26 | } 27 | 28 | public string color { get; set; } = ""; 29 | public string textColor { get; set; } = ""; 30 | 31 | /* 32 | public string url 33 | { 34 | get 35 | { 36 | return "/Calendar/Detail/" + id; 37 | } 38 | } 39 | */ 40 | 41 | }//class 42 | } 43 | -------------------------------------------------------------------------------- /BaseApi/Attributes/XgLoginAttribute.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseApi.Services; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | using Microsoft.AspNetCore.Routing; 6 | 7 | namespace BaseApi.Attributes 8 | { 9 | public class XgLoginAttribute : ActionFilterAttribute 10 | { 11 | public override void OnActionExecuting(ActionExecutingContext context) 12 | { 13 | var baseUser = _Fun.GetBaseUser(); 14 | if (baseUser.UserId == "") 15 | { 16 | //redirect to login action 17 | context.Result = new RedirectToRouteResult( 18 | new RouteValueDictionary 19 | { 20 | { "controller", "Home" }, 21 | { "action", "Login" }, 22 | { "url", _Http.GetWebPath() }, 23 | }); 24 | } 25 | else 26 | { 27 | //case of ok 28 | base.OnActionExecuting(context); 29 | } 30 | } 31 | 32 | } //class 33 | } 34 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgDeleteUpDownViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | //多筆資料的新增,刪除按鈕 8 | public class XgDeleteUpDownViewComponent : ViewComponent 9 | { 10 | //use button for control status 11 | //mName: EditMany.js variables name 12 | public HtmlString Invoke(string mName, string fnDeleteRow = "") 13 | { 14 | if (_Str.IsEmpty(fnDeleteRow)) 15 | fnDeleteRow = $"{mName}.onDeleteRow"; 16 | 17 | var html = $@" 18 | 21 | 24 | "; 27 | return new HtmlString(html); 28 | } 29 | 30 | }//class 31 | } 32 | -------------------------------------------------------------------------------- /Base/Services/_LogTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Base 4 | { 5 | //log running time 6 | public class _LogTime 7 | { 8 | //instance variables 9 | private static DateTime _start; 10 | private static DateTime _now; 11 | private static string _result = ""; 12 | 13 | private const string _newLine = "\r\n"; 14 | 15 | //constructor 16 | public static void Init(string name = "") 17 | { 18 | if (name != "") name += _newLine; 19 | _start = DateTime.Now; 20 | _now = _start; 21 | _result = _newLine + name; 22 | } 23 | 24 | //log time 25 | public static void Log(string name) 26 | { 27 | var now = DateTime.Now; 28 | _result += name + ":" + (int)(now - _now).TotalMilliseconds + "/" + (int)(now - _start).TotalMilliseconds + _newLine; 29 | _now = DateTime.Now; //reset 30 | } 31 | 32 | //return log string 33 | public static string GetLogMsg() 34 | { 35 | return _result; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Base/Services/_ModeUR.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System.Threading.Tasks; 3 | 4 | namespace Base.Services 5 | { 6 | /// 7 | /// URM(user role mode), 未來會有多種mode, 所以mode在前 8 | /// role的部分為多筆, 以checkbox輸入 9 | /// 10 | public class _ModeUR 11 | { 12 | /// 13 | /// (URM) get child rows 14 | /// 15 | /// master table name(主檔) 16 | /// slave table name(資料檔) 17 | /// table2 fid for join 18 | /// table2 fid for where 19 | /// 20 | /// 21 | /// 22 | public static async Task GetValueRows(string table, string dataFid, string whereFid, string key, Db? db = null) 23 | { 24 | var sql = $@" 25 | select Id, Str={dataFid} 26 | from {table} 27 | where {whereFid}=@Id 28 | "; 29 | return await _Db.GetRowsA(sql, new() { "Id", key }, db); 30 | } 31 | 32 | }//class 33 | } -------------------------------------------------------------------------------- /BaseApi/Attributes/XgRBAttribute.cs_old: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using Microsoft.AspNetCore.Mvc.Filters; 3 | 4 | namespace BaseWeb.Attributes 5 | { 6 | //設定ViewBag.RB for locale, 同時切換多國語for view 7 | //annotation for controller only !! 8 | public class XgRBAttribute : ActionFilterAttribute 9 | { 10 | public override void OnActionExecuting(ActionExecutingContext context) 11 | { 12 | /* //todo 13 | if (_Helper.SetRB(context)) 14 | base.OnActionExecuting(context); 15 | */ 16 | 17 | /* 18 | //get controller -> viewBag 19 | var controller = context.Controller as Controller; 20 | if (controller == null) 21 | return; 22 | 23 | //set ViewBag.RB 24 | string locale = (Locale != "") ? Locale : _Locale.GetLocale(); 25 | _Locale.SetCulture(locale); 26 | controller.ViewBag.RB = _Locale.GetRB(locale); 27 | */ 28 | 29 | //return 30 | //base.OnActionExecuting(context); 31 | //return; 32 | } 33 | 34 | }//class 35 | } 36 | -------------------------------------------------------------------------------- /BaseWeb/Helpers_old/XgFormHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Rendering; 2 | using System; 3 | 4 | namespace BaseWeb.Helpers 5 | { 6 | //see: http://www.nogginbox.co.uk/blog/mvc-html-wrapper-helper 7 | public static class XgFormHelper 8 | { 9 | //header 10 | public static XgForm BeginXgForm(this IHtmlHelper helper) 11 | { 12 | var html = @" 13 |
14 | "; 15 | 16 | helper.ViewContext.Writer.Write(html); 17 | return new XgForm(helper); 18 | } 19 | 20 | //tailer 21 | public static void EndXgForm(this IHtmlHelper helper) 22 | { 23 | var html = @" 24 |
25 | "; 26 | helper.ViewContext.Writer.Write(html); 27 | } 28 | }//class(XgFormHelper) 29 | 30 | 31 | public class XgForm : IDisposable 32 | { 33 | private readonly IHtmlHelper _helper; 34 | public XgForm(IHtmlHelper helper) 35 | { 36 | _helper = helper; 37 | } 38 | public void Dispose() 39 | { 40 | _helper.EndXgForm(); 41 | } 42 | }//class(XpForm) 43 | } 44 | -------------------------------------------------------------------------------- /BaseWeb/Services/_ActionResult.cs_old: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Mvc; 3 | using Base.Services; 4 | 5 | namespace BaseWeb.Services 6 | { 7 | public static class _ActionResult 8 | { 9 | /// 10 | /// ?? 11 | /// get partialView htmlString 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static string PartialView(this ActionResult result, ControllerContext controllerContext) 17 | { 18 | using (var ext = new ActionResultExt(controllerContext.RequestContext.HttpContext.Response)) 19 | { 20 | try 21 | { 22 | result.ExecuteResult(controllerContext); 23 | return ext.ToString(); 24 | } 25 | catch (Exception ex) 26 | { 27 | _Log.Error("_ActionResult.cs PartialView() failed: " + ex.Message); 28 | return ex.Message; 29 | } 30 | } 31 | } 32 | 33 | } //class 34 | } //namespace 35 | -------------------------------------------------------------------------------- /BaseWeb/Helpers_old/XiCheckAllHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Html; 2 | using Microsoft.AspNetCore.Mvc.Rendering; 3 | 4 | namespace BaseWeb.Helpers 5 | { 6 | public static class XiCheckAllHelper 7 | { 8 | /// 9 | /// (edit form) datatables header checkbox for checked all rows 10 | /// checkbox onclick fixed call _crud.onCheckAll() 11 | /// 12 | /// 13 | /// box container 14 | /// check fid(data-id value) 15 | /// 16 | public static IHtmlContent XiCheckAll(this IHtmlHelper htmlHelper, string boxStr, string dataFid) 17 | { 18 | //tail span is need for checkbox 19 | var html = string.Format(@" 20 | 21 | 25 | 26 | ", boxStr, dataFid); 27 | 28 | return new HtmlString(html); 29 | } 30 | 31 | } //class 32 | } 33 | -------------------------------------------------------------------------------- /Base/Models/EitemDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | 3 | namespace Base.Models 4 | { 5 | /// 6 | /// for crud edit form field 7 | /// 8 | public class EitemDto 9 | { 10 | //frent side field id 11 | public string Fid = ""; 12 | 13 | //where column id, has table alias 14 | public string Col = ""; 15 | 16 | //field type 17 | //public QitemTypeEnum Type = QitemTypeEnum.None; 18 | 19 | //check type 20 | public string CheckType = CheckTypeEstr.None; 21 | 22 | //check data for CheckType, ex: 23 | //"1,5" for Range, "1" for Min/Max 24 | public string CheckData = ""; 25 | 26 | /// 27 | /// default value when add new 28 | /// 29 | public object? Value; 30 | 31 | //required or not 32 | public bool Required = false; 33 | 34 | //if true, Create/Update will skip 35 | public bool Read = false; 36 | 37 | //allow create 38 | public bool Create = true; 39 | 40 | //allow update 41 | public bool Update = true; 42 | 43 | //allow update 44 | public bool IsHtml = false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Readme-CN.md: -------------------------------------------------------------------------------- 1 | 其他语系:[繁中](Readme-TW.md)、[英文](Readme.md) 2 | 3 | ### 1.介绍 4 | 5 | Base Repo 的性质是公用程式,在开发各类 c# 专案时可以参照,节省开发的时间,它里面包含4个 project,各自使用在不同的场合: 6 | - Base:最底层的公用程式,主要的功能是:各种基本资料的处理、档案存取、CRUD服务。所有专案像是Console、API、Web MVC都必须参照Base专案。 7 | - BaseApi:在开发API、MVC专案时需要参照,主要的功能有:权限控制、HTTP档案输出、CRUD功能、报表、签核流程、Excel汇入、交易记录…等。 8 | - BaseEther:存取以太坊智能合约、区块链和IPFS(分散式档案系统)。 9 | - BaseWeb:在开发 MVC 专案时需要参照,内容主要是SSR(Server Side Rendering)的自订输入栏位。 10 | 11 | ### 2.下载 & 执行 12 | 从 GitHub 下载 Base Repo 档案,解压缩到本机目录,其他专案可以正确参照 Base 相关专案即可。在系统启动必须呼叫 _Base/Services/_Fun.Init 函数来进行初始化,以确保功能正常运作,它包含以下传入参数: 13 | * isDev:是否为开发模式,系统会自动读取目前的执行模式然后传入。 14 | * diBox:ASP.NET Core使用许多DI(dependency injection依赖注入)服务,将这个服务供应者(service provider)以参数传入,可以方便我们在公用程式里面使用这些DI服务。 15 | * dbType:表示系统所使用的资料库种类,目前的选择有MS SQL、Oracle、MySQL。 16 | * authType:表示系统可以处理的权限等级,按照宽松程度依次分成4个等级: 17 | 1. 没有任何权限限制,表示所有人可以执行所有的作业。 18 | 2. Controller等级:只控制能不能执行某个完整的作业,当使用者进入该作业之后,他可以执行里面所有的按钮或是子功能。 19 | 3. Action等级:例如系统可以针对某个作业,设定使用者能否执行其中的新增、查询、修改、删除等CRUD子功能的权限。 20 | 4. 资料等级:使用者在执行作业内的每个子功能时,只能存取权限范围内的资料,例如当使用者在某个作业的修改权限被设定为"个人",则无法修改别人拥有的记录。 21 | 22 | ### 3.作者 23 | 24 | - Bruce Chen - *Initial work* 25 | 26 | ### 4.版权说明 27 | 28 | 本专案使用 [MIT 授权许可](https://zh.wikipedia.org/zh-cn/MIT許可證)。 -------------------------------------------------------------------------------- /Readme-TW.md: -------------------------------------------------------------------------------- 1 | 其他語系:[簡中](Readme-CN.md)、[英文](Readme.md) 2 | 3 | ### 1.介紹 4 | 5 | Base Repo 的性質是公用程式,在開發各類 c# 專案時可以參照,節省開發的時間,它裡面包含4個 project,各自使用在不同的場合: 6 | - Base:最底層的公用程式,主要的功能是:各種基本資料的處理、檔案存取、CRUD服務。所有專案像是Console、API、Web MVC都必須參照Base專案。 7 | - BaseApi:在開發API、MVC專案時需要參照,主要的功能有:權限控制、HTTP檔案輸出、CRUD功能、報表、簽核流程、Excel匯入、交易記錄…等。 8 | - BaseEther:存取以太坊智能合約、區塊鏈和IPFS(分散式檔案系統)。 9 | - BaseWeb:在開發 MVC 專案時需要參照,內容主要是SSR(Server Side Rendering)的自訂輸入欄位。 10 | 11 | ### 2.下載 & 執行 12 | 從 GitHub 下載 Base Repo 檔案,解壓縮到本機目錄,其他專案可以正確參照 Base 相關專案即可。在系統啟動必須呼叫 _Base/Services/_Fun.Init 函數來進行初始化,以確保功能正常運作,它包含以下傳入參數: 13 | * isDev:是否為開發模式,系統會自動讀取目前的執行模式然後傳入。 14 | * diBox:ASP.NET Core使用許多DI(dependency injection依賴注入)服務,將這個服務供應者(service provider)以參數傳入,可以方便我們在公用程式裡面使用這些DI服務。 15 | * dbType:表示系統所使用的資料庫種類,目前的選擇有MS SQL、Oracle、MySQL。 16 | * authType:表示系統可以處理的權限等級,按照寬鬆程度依次分成4個等級: 17 | 1. 沒有任何權限限制,表示所有人可以執行所有的作業。 18 | 2. Controller等級:只控制能不能執行某個完整的作業,當使用者進入該作業之後,他可以執行裡面所有的按鈕或是子功能。 19 | 3. Action等級:例如系統可以針對某個作業,設定使用者能否執行其中的新增、查詢、修改、刪除等CRUD子功能的權限。 20 | 4. 資料等級:使用者在執行作業內的每個子功能時,只能存取權限範圍內的資料,例如當使用者在某個作業的修改權限被設定為"個人",則無法修改別人擁有的記錄。 21 | 22 | ### 3.作者 23 | 24 | - Bruce Chen - *Initial work* 25 | 26 | ### 4.版權說明 27 | 28 | 本專案使用 [MIT 授權許可](https://zh.wikipedia.org/zh-tw/MIT許可證)。 -------------------------------------------------------------------------------- /Base/Models/BaseUserDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// basic user profile data for base class 5 | /// 6 | public class BaseUserDto 7 | { 8 | //login or not 9 | //public bool IsLogin; 10 | public bool HasPwd = false; 11 | 12 | //locale code 13 | public string Locale = ""; 14 | 15 | //user id/name 16 | public string UserId = ""; 17 | public string UserName = ""; 18 | 19 | //dept id/name 20 | public string DeptId = ""; 21 | public string DeptName = ""; 22 | 23 | //user type, PG define 24 | public string UserType = ""; 25 | 26 | /// 27 | /// 額外欄位值, 呼叫 _Login.cs LoginByVoA() 傳入, 後續透過 _Fun.GetBaseUser().ExtCol 讀取 28 | /// 超過3個欄位則使用合併 29 | /// 30 | public string ExtCol = ""; 31 | public string ExtCol2 = ""; 32 | public string ExtCol3 = ""; 33 | 34 | //diffence hours to GMT for Db saving 35 | //public double HourDiff = 0; 36 | 37 | /// 38 | /// authed program list, format=progId:CRUDPEV,... 39 | /// 40 | public string ProgAuthStrs = ""; 41 | 42 | }//class 43 | } 44 | -------------------------------------------------------------------------------- /BaseApi/BaseApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | Debug;Release;Debug-Local;Debug-IP 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Base/Models/BaseResDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// locale resource for base class 5 | /// 調用 _Json.CopyModel(), 必須宣告為類別屬性 !! 6 | /// 7 | public class BaseResDto 8 | { 9 | public string BtnCreate { get; set; } = ""; 10 | public string BtnAddRow { get; set; } = ""; 11 | public string BtnFind { get; set; } = ""; 12 | public string BtnFind2 { get; set; } = ""; 13 | public string BtnSave { get; set; } = ""; 14 | public string BtnToRead { get; set; } = ""; 15 | public string BtnExport { get; set; } = ""; 16 | public string BtnOpen { get; set; } = ""; 17 | public string BtnReset { get; set; } = ""; 18 | public string BtnYes { get; set; } = ""; 19 | public string BtnCancel { get; set; } = ""; 20 | public string BtnClose { get; set; } = ""; 21 | 22 | public string TipUpdate { get; set; } = ""; 23 | public string TipDelete { get; set; } = ""; 24 | public string TipView { get; set; } = ""; 25 | public string TipDeleteRow { get; set; } = ""; 26 | 27 | public string PlsSelect { get; set; } = ""; 28 | public string NoAuth { get; set; } = ""; 29 | public string Working { get; set; } = ""; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Base/Services/_Pwd.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace Base 5 | { 6 | public class _Pwd 7 | { 8 | /// 9 | /// 檢查密碼強度 10 | /// 11 | /// 12 | /// 13 | /// error msg if any(無多國語) 14 | public static string CheckStrong(string pwd) 15 | { 16 | switch (_Fun.PwdStrongLevel) 17 | { 18 | //無限制 19 | case 0: return ""; 20 | 21 | //英數字 22 | case 1: 23 | return Regex.IsMatch(pwd, @"^(?=.*[a-zA-Z])(?=.*\d).+$") 24 | ? "" : "密碼必須包含英數字"; 25 | 26 | //大小寫英文,數字,特殊符號,長度10以上 27 | default: 28 | var status = (pwd.Length < 10) ? false : 29 | !Regex.IsMatch(pwd, "[a-z]") ? false : 30 | !Regex.IsMatch(pwd, "[A-Z]") ? false : 31 | !Regex.IsMatch(pwd, "[0-9]") ? false : 32 | Regex.IsMatch(pwd, "[!-/:-@\\[-`{-~]"); 33 | return status 34 | ? "" : "密碼必須包含大小寫英文、數字、特殊符號、長度10以上。"; 35 | } 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Base/Models/PageIn.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// for RWD pagin input, use lower camel(jquery/app/vue simple pagination) 5 | /// 6 | public class PageIn 7 | { 8 | public PageIn() 9 | { 10 | //start = 0; 11 | page = 1; 12 | length = 10; 13 | filterRows = -1; 14 | findJson = ""; 15 | } 16 | 17 | //Draw counter, jQuery Datatables need for control async ajax sequence 18 | //public int draw { get; set; } 19 | 20 | //start row position, base 0 21 | //public int start { get; set; } 22 | //page no 23 | public int page { get; set; } 24 | 25 | //rows count to display 26 | public int length { get; set; } 27 | 28 | //-1: re-count filtered rows count(means change jquery condition) 29 | public int filterRows { get; set; } 30 | 31 | //query condition json in string type 32 | public string findJson { get; set; } 33 | 34 | //search word 35 | //public DtSearchDto search { get; set; } 36 | 37 | /// 38 | /// sorting, get from jQuery DataTables, then get OrderBy, OrderDir 39 | /// 40 | //public List order { get; set; } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /BaseApi/Services/_Html.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.Text.RegularExpressions; 3 | using System.Web; 4 | 5 | namespace BaseApi.Services 6 | { 7 | public static class _Html 8 | { 9 | /// 10 | /// convert value to Html encoding for special code 11 | /// 12 | /// 13 | /// 14 | public static string Encode(string data) 15 | { 16 | return HttpUtility.HtmlEncode(data); 17 | } 18 | 19 | public static string Decode(string value) 20 | { 21 | return HttpUtility.HtmlDecode(value); 22 | } 23 | 24 | /// 25 | /// remove html tag 26 | /// 27 | /// 28 | /// 29 | public static string RemoveHtmlTag(string html) 30 | { 31 | if (_Str.NotEmpty(html)) 32 | { 33 | //remove js code. 34 | html = Regex.Replace(html, @"[\d\D]*?", string.Empty); 35 | 36 | //remove html tag. 37 | html = Regex.Replace(html, @"<[^>]*>", string.Empty); 38 | } 39 | 40 | return html; 41 | } 42 | 43 | } //class 44 | } 45 | -------------------------------------------------------------------------------- /Base/Models/EasyDtDto.cs: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// easy datatable input argument, use lower camel 5 | /// refer DtDto.cs 6 | /// 7 | public class EasyDtDto 8 | { 9 | /* 10 | public EasyDtDto() 11 | { 12 | start = 0; 13 | length = 10; 14 | recordsFiltered = -1; 15 | findJson = ""; 16 | sort = ""; 17 | } 18 | */ 19 | 20 | //Draw counter, jQuery Datatables need for control async ajax sequence 21 | //public int draw { get; set; } 22 | 23 | //start row position, base 0 24 | public int start { get; set; } = 0; 25 | 26 | //rows count to display 27 | public int length { get; set; } = 10; 28 | 29 | //-1: re-count filtered rows count(means change jquery condition) 30 | public int recordsFiltered { get; set; } = -1; 31 | 32 | //query condition json in string type 33 | public string findJson { get; set; } = ""; 34 | 35 | //A/D + fid, ex:Au.Account 36 | public string sort { get; set; } = ""; 37 | 38 | //與DtDto.search的資料結構不同, 所以使用不同欄位名稱 39 | public string search2 { get; set; } = ""; 40 | 41 | //search word 42 | //public DtSearchDto search { get; set; } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /BaseWeb/Services/_Session.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | //using LightInject; 4 | 5 | namespace BaseWeb.Services 6 | { 7 | public static class _Session 8 | { 9 | private static Session0Service _service = null; 10 | //private static ISession _service = null; 11 | 12 | //constructor 13 | static _Session() 14 | { 15 | //_service = _Fun.GetDI().GetInstance(); 16 | _service = (Session0Service)_Fun.GetDI().GetService(typeof(Session0Service)); 17 | } 18 | 19 | public static string NewKey() 20 | { 21 | return _service.NewKey(); 22 | } 23 | 24 | //get user profile 25 | //return null if not login 26 | public static BaseUserInfoDto GetUserInfo() 27 | { 28 | return _service.GetUserInfo(); 29 | } 30 | 31 | //set user profile 32 | public static void SetUserInfo(string key, BaseUserInfoDto model) 33 | { 34 | _service.SetUserInfo(key, model); 35 | } 36 | 37 | public static void SetClientKey(string key) 38 | { 39 | _service.SetClientKey(key); 40 | } 41 | 42 | //reset user profile 43 | public static void Reset() 44 | { 45 | _service.Reset(); 46 | } 47 | 48 | }//class 49 | } 50 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgThViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseWeb.Models; 3 | using BaseWeb.Services; 4 | using Microsoft.AspNetCore.Html; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace BaseWeb.ViewComponents 8 | { 9 | //配合 _xp.js 10 | public class XgThViewComponent : ViewComponent 11 | { 12 | /// 13 | /// table th 14 | /// 15 | /// 16 | /// prog path list 17 | /// 18 | /// 19 | /// 20 | public HtmlString Invoke(XgThDto dto) 21 | { 22 | var title = _Input.GetRequiredSpan(dto.Required) + dto.Title; 23 | var html = (dto.Tip == "") 24 | ? "" + title + "" 25 | : "" + title + ""; 26 | 27 | //class 28 | var cls = dto.ClsExt; 29 | if (dto.MinWidth > 0) 30 | cls += $" g-iw{dto.MinWidth}"; 31 | if (dto.HideRwd) 32 | cls += " " + _Fun.ClsHideRwd; 33 | if (cls != "") 34 | cls = $" class='{cls}'"; 35 | return new HtmlString(string.Format(html, cls)); 36 | } 37 | 38 | } //class 39 | } -------------------------------------------------------------------------------- /Base/Enums/ItemOpEstr.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Enums 3 | { 4 | /// 5 | /// for query field 6 | /// 7 | public class ItemOpEstr 8 | { 9 | //=== same as sql op === 10 | public const string Equal = "Equal"; 11 | public const string Like = "Like"; 12 | public const string NotLike = "NotLike"; 13 | 14 | //input string list as: u01,u02,...multiple in query for one field 15 | //backend will replace carrier line to comma for TextArea field 16 | public const string In = "In"; 17 | 18 | 19 | //=== not same as sql op === 20 | //%xxx% compare 21 | public const string Like2 = "Like2"; 22 | 23 | //input string list as: u01,u02,... multiple like query for one field 24 | public const string LikeList = "LikeList"; 25 | 26 | //input one string, do like query for multiple columns(set Col field) 27 | public const string LikeCols = "LikeCols"; 28 | 29 | //do like('%xxx%') query for multiple columns(set Col and seperate with comma) 30 | public const string Like2Cols = "Like2Cols"; 31 | 32 | public const string Is = "Is"; 33 | public const string IsNull = "IsNull"; 34 | public const string NotNull = "NotNull"; 35 | public const string InRange = "InRange"; 36 | 37 | //PG defined 38 | public const string UserDefined = "UD"; 39 | 40 | }//class 41 | } 42 | -------------------------------------------------------------------------------- /BaseApi/Controllers/BaseCtrl.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Services; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Newtonsoft.Json.Linq; 5 | 6 | namespace BaseApi.Controllers 7 | { 8 | public class BaseCtrl : Controller 9 | { 10 | //controller name 11 | public string Ctrl; 12 | 13 | //new way. 14 | public BaseCtrl() 15 | { 16 | Ctrl = this.GetType().Name.Replace("Controller", ""); 17 | } 18 | 19 | /* 20 | override public void OnActionExecuting(ActionExecutingContext context) 21 | { 22 | //put constructor will not work !! 23 | Ctrl = ControllerContext.ActionDescriptor.ControllerName; 24 | base.OnActionExecuting(context); 25 | } 26 | */ 27 | 28 | /// 29 | /// json to content result 30 | /// 31 | /// 32 | /// 33 | protected ContentResult JsonToCnt(JObject? json) 34 | { 35 | json ??= _Json.GetBrError("FindNone"); 36 | return Content(json.ToString(), ContentTypeEstr.Json); 37 | } 38 | 39 | protected ContentResult JsonsToCnt(JArray? rows) 40 | { 41 | //如果傳回空字串前端會parser error !! 42 | string json = rows?.ToString(Newtonsoft.Json.Formatting.None) ?? "[]"; 43 | return Content(json, ContentTypeEstr.Json); 44 | } 45 | 46 | }//class 47 | } -------------------------------------------------------------------------------- /Base/Services/_Xml.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.IO; 4 | using System.Xml; 5 | 6 | namespace Base.Services 7 | { 8 | public class _Xml 9 | { 10 | public static string ToStr(XmlNode node) 11 | { 12 | return JsonConvert.SerializeXmlNode(node); 13 | } 14 | 15 | /// 16 | /// get key property(attriibute) 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static string? GetKeyProp(string filePath, string keyPath, string propName) 22 | { 23 | //check 24 | if (string.IsNullOrEmpty(filePath)) 25 | return null; 26 | 27 | if (!File.Exists(filePath)) 28 | { 29 | _Log.Error($"No File: {filePath}"); 30 | return null; 31 | } 32 | 33 | var xmlDoc = new XmlDocument(); 34 | xmlDoc.Load(filePath); 35 | 36 | var node = xmlDoc.SelectSingleNode(keyPath); 37 | if (node == null) 38 | return null; 39 | if (node?.Attributes == null || node?.Attributes.Count == 0) 40 | return null; 41 | 42 | var prop = node?.Attributes[propName]; 43 | return (prop == null) 44 | ? null 45 | : prop.Value; 46 | } 47 | 48 | }//class 49 | } 50 | -------------------------------------------------------------------------------- /BaseWeb/Models/XiBaseDto.cs: -------------------------------------------------------------------------------- 1 | namespace BaseWeb.Models 2 | { 3 | public class XiBaseDto 4 | { 5 | public string Title { get; set; } = ""; 6 | 7 | //LabelTip -> TitleTip 8 | public string TitleTip { get; set; } = ""; 9 | public string Fid { get; set; } = ""; 10 | public string Value { get; set; } = ""; 11 | 12 | /// 13 | /// C(create), U(update), Other for none 14 | /// 15 | public string Edit { get; set; } = ""; 16 | 17 | /// 18 | /// 如果true, 則不會加上外層 row 19 | /// 20 | public bool InRow { get; set; } 21 | 22 | public bool Required { get; set; } 23 | 24 | //placeholder 25 | public string InputTip { get; set; } = ""; 26 | 27 | public string InputAttr { get; set; } = ""; 28 | 29 | //欄位右方提示文字(.x-input-note) 30 | public string InputNote { get; set; } = ""; 31 | 32 | /// 33 | /// css class, 如果單一欄位在加在本身tag, 複合欄位會加在外層div 34 | /// 35 | public string ClsBox { get; set; } = ""; 36 | 37 | public string Cols { get; set; } = ""; 38 | 39 | /// 40 | /// 停用 inline style for CSRF !! 41 | /// form-control預設100%, 如果不是則系統會設定為inline-block 42 | /// 43 | public int Width { get; set; } = 0; 44 | 45 | //onclick, onchange event 傳入參數, 多個參數時用逗號分隔 46 | public string EventArgs { get; set; } = ""; 47 | } 48 | } -------------------------------------------------------------------------------- /Base/Services/_Cache.cs: -------------------------------------------------------------------------------- 1 | using Base.Interfaces; 2 | using System.Threading.Tasks; 3 | 4 | namespace Base.Services 5 | { 6 | /// 7 | /// 將 Cache class 包裝成靜態類別, 存取 ICacheService 介面 8 | /// 9 | public class _Cache 10 | { 11 | 12 | private static ICacheSvc GetService() 13 | { 14 | return (ICacheSvc)_Fun.DiBox!.GetService(typeof(ICacheSvc))!; 15 | } 16 | 17 | public static string? GetStr(string userId, string key) 18 | { 19 | return GetService().GetStr(userId, key); 20 | } 21 | 22 | public static bool SetStr(string userId, string key, string value) 23 | { 24 | return GetService().SetStr(userId, key, value); 25 | } 26 | 27 | public static T? GetModel(string userId, string key) 28 | { 29 | var str = GetService().GetStr(userId, key); 30 | return _Str.IsEmpty(str) 31 | ? default : _Model.JsonStrToModel(str!); 32 | } 33 | 34 | public static bool SetModel(string userId, string key, T model) 35 | { 36 | return GetService().SetStr(userId, key, _Model.ToJsonStr(model)); 37 | } 38 | 39 | public static bool DeleteKey(string userId, string key) 40 | { 41 | return GetService().DeleteKey(userId, key); 42 | } 43 | 44 | public static async Task ResetDbA() 45 | { 46 | await GetService().ResetDbA(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Base/Services/_Ad.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using System; 3 | using System.DirectoryServices; 4 | 5 | namespace Base.Services 6 | { 7 | public class _Ad 8 | { 9 | //login Ad server 10 | //see: http://www.itread01.com/articles/1478571605.html 11 | public static AdUserDto? Login(string server, string id, string pwd) 12 | { 13 | var entry = new DirectoryEntry(server, id, pwd); 14 | try 15 | { 16 | //object obj = entry.NativeObject; 17 | var search = new DirectorySearcher(entry) 18 | { 19 | Filter = string.Format("(SAMAccountName={0})", id) 20 | }; 21 | 22 | // 指定需要傳回的屬性 23 | search.PropertiesToLoad.Add("sn"); //姓名 24 | search.PropertiesToLoad.Add("mail"); //電子郵件 25 | 26 | SearchResult result = search.FindOne(); 27 | return (result == null) 28 | ? null 29 | : new AdUserDto() 30 | { 31 | Id = id, 32 | Name = result.Properties["sn"][0]!.ToString(), 33 | Email = result.Properties["mail"][0]!.ToString(), 34 | }; 35 | } 36 | catch 37 | { 38 | return null; 39 | } 40 | finally 41 | { 42 | entry.Close(); 43 | } 44 | } 45 | 46 | }//class 47 | } 48 | -------------------------------------------------------------------------------- /BaseWeb/Helpers_old/XiTextMaskHelper.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using System; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc.Rendering; 5 | 6 | //todo 7 | namespace BaseWeb.Helpers 8 | { 9 | public static class XiTextMaskHelper 10 | { 11 | /// 12 | /// text input mask 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | public static IHtmlContent XiTextMask(this IHtmlHelper htmlHelper, string fid, string dataMask, string value="", string placeholder="") 21 | { 22 | return GetStr(fid, dataMask, value, placeholder); 23 | } 24 | 25 | /// 26 | /// todo 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | private static IHtmlContent GetStr(string fid, string dataMask, string value, string placeholder) 34 | { 35 | var html = @""; 36 | html = String.Format(html, fid, value, dataMask, placeholder, fid + _WebFun.ErrTail, _WebFun.ErrLabCls); 37 | return new HtmlString(html); 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Base/Models/RBDto.cs_old: -------------------------------------------------------------------------------- 1 | namespace Base.Models 2 | { 3 | /// 4 | /// resource for case class 5 | /// 6 | public class RBDto 7 | { 8 | //constructor 9 | public RBDto() 10 | { 11 | BtnCreate = "新增"; 12 | BtnAddRow = "新增一列"; 13 | BtnFind = "查詢"; 14 | BtnFind2 = "進階"; 15 | BtnSave = "儲存"; 16 | BtnToRead = "回上一頁"; 17 | BtnExport = "匯出"; 18 | BtnOpen = "開啟"; 19 | 20 | TipDeleteRow = "刪除這筆資料"; 21 | PlsSelect = "-請選擇-"; 22 | 23 | FrontDateFormat = "yyyy/M/d"; 24 | FrontDtFormat = "yyyy/M/d HH:mm:ss"; //24hour 25 | } 26 | 27 | //=== for html helper === 28 | public string BtnCreate { get; set; } 29 | 30 | public string BtnAddRow { get; set; } 31 | 32 | public string BtnFind2 { get; set; } 33 | public string BtnFind { get; set; } 34 | 35 | public string BtnSave { get; set; } 36 | public string BtnToRead { get; set; } 37 | public string BtnExport { get; set; } 38 | public string BtnOpen { get; set; } 39 | 40 | public string PlsSelect { get; set; } 41 | 42 | //多筆資料 deleteRow 43 | public string TipDeleteRow { get; set; } 44 | 45 | //=== datetime format === 46 | public string FrontDateFormat { get; set; } 47 | public string FrontDtFormat { get; set; } 48 | 49 | //public string DtCrudFun = "CRUD"; 50 | //public string DtFun = "功能"; 51 | //public string DtStatus = "狀態"; 52 | //=== for client side === 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BaseWeb/Services/_BR.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | using BaseApi.Services; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace BaseWeb.Services 10 | { 11 | //for web system only 12 | public static class _BR 13 | { 14 | //loaded localization list, 15 | private static Dictionary _brList = new(); 16 | 17 | /// 18 | /// (GetBaseRes) get base resource 19 | /// 20 | /// default to user locale 21 | /// 22 | public static BaseResDto GetData(string locale) 23 | { 24 | //if (locale == "") locale = _Locale.GetLocaleByUser(); 25 | var dict = _brList.FirstOrDefault(a => a.Key == locale); 26 | return dict.Equals(default(Dictionary)) 27 | ? new() : dict.Value; 28 | } 29 | 30 | //(ReadBaseResA) 31 | private static async Task ReadFileA(string locale) 32 | { 33 | //error = ""; //initial 34 | var file = _FunApi.DirWeb + "locale/" + locale + "/BR.json"; 35 | if (!File.Exists(file)) 36 | { 37 | _Log.Error("no file: " + file); 38 | return null; 39 | } 40 | 41 | //set _br 42 | var br = new BaseResDto(); //initial value 43 | var json = _Str.ToJson((await _File.ToStrA(file))!); 44 | _Json.CopyToModel(json!, br); 45 | return br; 46 | } 47 | 48 | }//class 49 | } 50 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgCol4ViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using BaseWeb.Services; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | //add row button 9 | public class XgCol4ViewComponent : ViewComponent 10 | { 11 | public HtmlString Invoke(string cols = "") 12 | { 13 | //here!! 14 | var colList = _Str.ToIntList(cols); 15 | if (colList.Count < 2) 16 | colList = _Fun.DefHoriColList; 17 | 18 | var html = string.Format(@" 19 |
20 |
建檔人員
21 |
22 | 23 |
24 |
修改人員
25 |
26 | 27 |
28 |
29 |
30 |
建檔時間
31 |
32 | 33 |
34 |
修改日期
35 |
36 | 37 |
38 |
39 | ", colList[0], colList[1]); 40 | 41 | return new HtmlString(html); 42 | } 43 | }//class 44 | } 45 | -------------------------------------------------------------------------------- /Base/Models/DtDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Models 5 | { 6 | /// 7 | /// for jQuery datatables input argument, use low camel 8 | /// 9 | public class DtDto 10 | { 11 | //Draw counter, jQuery Datatables need for control async ajax sequence 12 | public int draw { get; set; } 13 | 14 | //start row position, base 0 15 | public int start { get; set; } 16 | 17 | //rows count to display 18 | public int length { get; set; } 19 | 20 | //-1: re-count filtered rows count(means change jquery condition) 21 | public int recordsFiltered { get; set; } 22 | 23 | //query condition json in string type 24 | public string findJson { get; set; } = ""; 25 | 26 | //優先考慮 sort 欄位, 內容為: A/D + fid, ex:Au.Account 27 | public string sort { get; set; } = ""; 28 | 29 | //search word 30 | public DtSearchDto? search { get; set; } 31 | 32 | /// 33 | /// sorting, get from jQuery DataTables, then get OrderBy, OrderDir 34 | /// 35 | public List? order { get; set; } 36 | 37 | } 38 | 39 | 40 | //for jQuery datatables 41 | public class DtOrderDto 42 | { 43 | //sorting column index, base 0 44 | public int column { get; set; } 45 | 46 | //sorting column name 47 | public string fid { get; set; } 48 | 49 | //sorting type: ASC(default), DESC 50 | public OrderTypeEnum dir { get; set; } 51 | } 52 | 53 | 54 | //for jQuery datatables 55 | public class DtSearchDto 56 | { 57 | //search value 58 | public string value { get; set; } = ""; 59 | 60 | //no used now 61 | public bool regex { get; set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Base/Models/PropBaseDto.c_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | /// 5 | /// all input field, some properties are not available 6 | /// 7 | public class PropBaseDto 8 | { 9 | 10 | //=== for all input === 11 | /// 12 | /// true(use id), false(use data-id) 13 | /// 14 | //public bool IsId = true; 15 | 16 | /// 17 | /// is in datatable ?? 18 | /// 19 | //public bool InDt = false; 20 | 21 | /// 22 | /// title RWD col num(2-12) 23 | /// only for title is not empty 24 | /// 25 | //public int TitleCols = 2; 26 | 27 | /// 28 | /// is inline ? 29 | /// only for title is not empty 30 | /// 31 | //public bool Inline = false; 32 | 33 | /// 34 | /// extra className, sep with "," 35 | /// 36 | public string ExtClass = ""; 37 | 38 | /// 39 | /// extra attr, sep with "," 40 | /// for jquery validate could be: range='[a,b]', max='a', min='b' 41 | /// 42 | public string ExtAttr = ""; 43 | 44 | /// 45 | /// editable or not 46 | /// 47 | public bool Editable = true; 48 | 49 | /// 50 | /// call function on change 51 | /// 52 | public string FnOnChange = ""; 53 | 54 | /// 55 | /// tooltip for label 56 | /// 57 | public string Tip = ""; 58 | 59 | //=== only for part field === 60 | /// 61 | /// container className 62 | /// 63 | //public string BoxClass = ""; 64 | 65 | }//class 66 | } -------------------------------------------------------------------------------- /Base/Services/_Net.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | //網路連線 6 | public static class _Net 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | private class NetResourceDto 10 | { 11 | public int dwScope = 0; 12 | public int dwType = 1; // RESOURCETYPE_DISK 13 | public int dwDisplayType = 0; 14 | public int dwUsage = 0; 15 | public string lpLocalName = null!; 16 | public string lpRemoteName = null!; 17 | public string lpComment = null!; 18 | public string lpProvider = null!; 19 | } 20 | 21 | //名稱固定不可改 22 | [DllImport("mpr.dll")] 23 | private static extern int WNetAddConnection2( 24 | NetResourceDto lpNetResource, 25 | string lpPassword, 26 | string lpUsername, 27 | int dwFlags); 28 | 29 | //名稱固定不可改 30 | [DllImport("mpr.dll")] 31 | private static extern int WNetCancelConnection2(string lpName, int dwFlags, bool bForce); 32 | 33 | /// 34 | /// 嘗試連線至需要帳號密碼的網路共用目錄 35 | /// 36 | public static bool Connect(string netPath, string userId, string pwd) 37 | { 38 | //連線前先取消連線,避免重複連線, 造成error 39 | Disconnect(netPath); 40 | 41 | //連線 42 | var netResource = new NetResourceDto 43 | { 44 | lpRemoteName = netPath 45 | }; 46 | 47 | var result = WNetAddConnection2(netResource, pwd, userId, 0); 48 | var status = (result == 0); 49 | if (!status) 50 | { 51 | _Log.Error($"_Net.cs Connect fail, result={result}, path={netPath}"); 52 | } 53 | return status; 54 | } 55 | 56 | /// 57 | /// 取消網路共用目錄連線 58 | /// 59 | public static void Disconnect(string netPath) 60 | { 61 | WNetCancelConnection2(netPath, 0, true); 62 | } 63 | } -------------------------------------------------------------------------------- /Base/Services/_Seo.cs: -------------------------------------------------------------------------------- 1 | using HandlebarsDotNet; 2 | using Newtonsoft.Json.Linq; 3 | using System.Web; 4 | 5 | namespace Base 6 | { 7 | //SEO 8 | public class _Seo 9 | { 10 | //instance variables 11 | //private static DateTime _start; 12 | //private const string _newLine = "\r\n"; 13 | 14 | /// 15 | /// 產生 seo siteMap.xml 檔案 16 | /// 17 | /// 18 | /// 包含Loc, LastMod 2個欄位 19 | /// 20 | /// 21 | /// 22 | public static byte[]? GenSiteMapFile(string domain, JArray? rows, string changeFreq = "weekly", string priority = "1.0") 23 | { 24 | if (rows == null) return null; 25 | 26 | //handleBars 多筆區域內只能使用自己的欄位 27 | foreach(JObject row in rows) 28 | { 29 | row["Loc"] = domain + "/" + row["Loc"]; 30 | row["ChangeFreq"] = changeFreq; 31 | row["Priority"] = priority; 32 | } 33 | 34 | //siteMap file template 35 | var fileTpl = @" 36 | 37 | 38 | {{#each Items}} 39 | 40 | {{Loc}} 41 | {{LastMod}} 42 | {{ChangeFreq}} 43 | {{Priority}} 44 | 45 | {{/each}} 46 | 47 | "; 48 | var json = new { Items = rows }; 49 | var mustache = Handlebars.Compile(fileTpl); 50 | var result = HttpUtility.HtmlDecode(mustache(json).ToString().Trim()); 51 | return System.Text.Encoding.UTF8.GetBytes(result); 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /SmsTaiwan/Models/SmsDto.cs: -------------------------------------------------------------------------------- 1 | namespace SmsTaiwan.Models 2 | { 3 | using System; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | 7 | //[Table("sendMessage")] 8 | public partial class SmsDto 9 | { 10 | [Key] 11 | public int sid { get; set; } 12 | 13 | //public string username { get; set; } 14 | 15 | //public string password { get; set; } 16 | 17 | //[StringLength(5)] 18 | //public string rateplan { get; set; } 19 | 20 | //[StringLength(50)] 21 | //public string srcaddr { get; set; } 22 | 23 | //public string dstaddr { get; set; } 24 | 25 | [StringLength(10)] 26 | public string encoding { get; set; } 27 | 28 | public string smbody { get; set; } 29 | 30 | //public string smbodyOriginal { get; set; } 31 | 32 | //public int? vldtime { get; set; } 33 | 34 | //[StringLength(128)] 35 | //public string response { get; set; } 36 | 37 | //[StringLength(50)] 38 | //public string msgid { get; set; } 39 | 40 | //public int? statuscode { get; set; } 41 | 42 | //[StringLength(16)] 43 | //public string statusstr { get; set; } 44 | 45 | //[StringLength(32)] 46 | //public string donetime { get; set; } 47 | 48 | //public int? point { get; set; } 49 | 50 | //[StringLength(20)] 51 | //public string createUser { get; set; } 52 | 53 | //public DateTime? createDate { get; set; } 54 | 55 | //[DatabaseGenerated(DatabaseGeneratedOption.Computed)] 56 | //public int? createYear { get; set; } 57 | 58 | //[DatabaseGenerated(DatabaseGeneratedOption.Computed)] 59 | //public int? createMonth { get; set; } 60 | 61 | //[StringLength(50)] 62 | //public string dlvtime { get; set; } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Base/Models/ReadDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Models 5 | { 6 | /// 7 | /// for Crud List/Query form 8 | /// 9 | public class ReadDto 10 | { 11 | /// 12 | /// same as DbReadModel.ColList 13 | /// 14 | public string ColList = ""; 15 | 16 | /// 17 | /// sql string, column select order must same to client side for datatable sorting !! 18 | /// 19 | public string ReadSql = ""; 20 | 21 | /// 22 | /// sql string for export excel, default to ReadSql. 23 | /// 24 | public string ExportSql = ""; 25 | 26 | /// 27 | /// sql use square, as: [from],[where],[group],[order] 28 | /// (TODO: add [whereCond] for client condition !!) 29 | /// 30 | public bool UseSquare = false; 31 | 32 | /// 33 | /// default table alias name 34 | /// 35 | public string TableAs = ""; 36 | 37 | /// 38 | /// (for AuthType=Row only) user fid, default to _Fun.FindUserFid 39 | /// 40 | public string WhereUserFid = _Fun.UserEqual; 41 | 42 | /// 43 | /// (for AuthType=Row only) dept fid, default to _Fun.FindDeptFid 44 | /// 45 | public string WhereDeptFid = _Fun.DeptEqual; 46 | 47 | /// 48 | /// for quick search, include table alias, will get like %xx% query 49 | /// 50 | public string[]? FindCols; 51 | 52 | /// 53 | /// or query for column group, suggest to List more easy !! 54 | /// 55 | public List>? OrGroups; 56 | 57 | /// 58 | /// query condition fields 59 | /// 60 | public QitemDto[]? Items; 61 | 62 | }//class 63 | } 64 | -------------------------------------------------------------------------------- /BaseEther/Services/_Ether.cs: -------------------------------------------------------------------------------- 1 | using BaseEther.Models; 2 | using Nethereum.Contracts; 3 | using Nethereum.RPC.Eth.DTOs; 4 | using Nethereum.Web3; 5 | using Account = Nethereum.Web3.Accounts.Account; 6 | 7 | namespace BaseEther.Services 8 | { 9 | #pragma warning disable IDE1006 // 命名樣式 10 | public static class _Ether 11 | #pragma warning restore IDE1006 // 命名樣式 12 | { 13 | 14 | /// 15 | /// log info only when _Fun.LogInfo flag is true !! 16 | /// 17 | /// log msg 18 | public static Contract? GetContract(string nodeUrl, string address, string abi) 19 | { 20 | var web3 = new Web3(nodeUrl); 21 | var contract = web3.Eth.GetContract(abi, address); 22 | return contract; 23 | } 24 | 25 | /// 26 | /// get contract for transaction 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | public static Contract? GetTxContract(string nodeUrl, string address, string abi, string privateKey) 34 | { 35 | var account = new Account(privateKey); 36 | var web3 = new Web3(account, nodeUrl); 37 | return web3.Eth.GetContract(abi, address); 38 | } 39 | 40 | public static async Task GetLogA(string nodeUrl, string txHash) 41 | { 42 | var web3 = new Web3(nodeUrl); 43 | var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash); 44 | if (receipt == null || receipt.Logs == null || receipt.Logs.Count == 0) 45 | return ""; 46 | 47 | var log = receipt.Logs[0].ToObject(); //jToken -> FilterLog 48 | var eventData = log.DecodeEvent(); 49 | return eventData.Event.log; 50 | } 51 | 52 | }//class 53 | } -------------------------------------------------------------------------------- /Base/Services/CacheMemSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Interfaces; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | namespace Base.Services 7 | { 8 | //memory cache server 9 | public class CacheMemSvc : ICacheSvc 10 | { 11 | private readonly IMemoryCache _cache; 12 | //private string _preKey; 13 | 14 | //constructor 15 | public CacheMemSvc(IMemoryCache cache) 16 | { 17 | _cache = cache; 18 | //_preKey = _Fun.UserId() + "_"; 19 | } 20 | 21 | private string GetKey(string userId, string key) 22 | { 23 | return userId + "_" + key; 24 | } 25 | 26 | public string? GetStr(string userId, string key) 27 | { 28 | _cache.TryGetValue(GetKey(userId, key), out string? result); 29 | return result ?? null; 30 | } 31 | 32 | /// 33 | /// 設定內容, 同時指定有效期限 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// 39 | public bool SetStr(string userId, string key, string value) 40 | { 41 | _cache.Set(GetKey(userId, key), value, new MemoryCacheEntryOptions() 42 | .SetSlidingExpiration(TimeSpan.FromMinutes(_Fun.TimeOut))); 43 | return true; 44 | } 45 | 46 | public bool DeleteKey(string userId, string key) 47 | { 48 | _cache.Remove(GetKey(userId, key)); 49 | return true; 50 | } 51 | 52 | /* 53 | */ 54 | /// 55 | /// delete all keys in current database index 56 | /// 57 | #pragma warning disable CS1998 // Async 方法缺乏 'await' 運算子,將同步執行 58 | public async Task ResetDbA() 59 | #pragma warning restore CS1998 // Async 方法缺乏 'await' 運算子,將同步執行 60 | { 61 | (_cache as MemoryCache)!.Compact(1.0); 62 | } 63 | 64 | } //class 65 | } 66 | -------------------------------------------------------------------------------- /Base/Models/Select2PropModel.cs_old: -------------------------------------------------------------------------------- 1 | 2 | namespace Base.Models 3 | { 4 | // (for bootstrap-select) 5 | /// 6 | /// 下拉式欄位可接受的屬性(bootstrap-select), 屬性名稱配合 bootstrap-select 7 | /// 8 | public class Select2PropModel 9 | { 10 | //constructor 11 | public Select2PropModel() 12 | { 13 | //default value 14 | ShowOptionTitle = false; 15 | AddEmptyRow = true; 16 | Separator = '|'; 17 | DropUpAuto = true; 18 | ButtonClass = "xg-select-btn"; 19 | } 20 | 21 | /// 22 | /// 是否顯示 option title 在下拉式畫面 23 | /// 24 | public bool ShowOptionTitle { get; set; } 25 | 26 | /// 27 | /// 是否增加一筆空白的資料在最上面, option label = placeHolder 28 | /// 29 | public bool AddEmptyRow { get; set; } 30 | 31 | /// 32 | /// placeholder 33 | /// 34 | public string PlaceHolder { get; set; } 35 | 36 | /// 37 | /// className 38 | /// 39 | public string ClassName { get; set; } 40 | 41 | /// 42 | /// select onChange event name 43 | /// 44 | public string OnChange { get; set; } 45 | 46 | /// 47 | /// column amount, 大於1表示多欄 48 | /// 49 | public int Columns { get; set; } 50 | 51 | /// 52 | /// 多選欄位值的分隔符號 53 | /// 54 | public char Separator { get; set; } 55 | 56 | /// 57 | /// 指定下拉式欄位要顯示的筆數(for 考慮畫面空間) 58 | /// 59 | public int Size { get; set; } 60 | 61 | /// 62 | /// 是否由系統指定下拉式欄位展開方向, 如果否則往下展開 63 | /// 64 | public bool DropUpAuto { get; set; } 65 | 66 | /// 67 | /// button class name, default to xg-select-btn 68 | /// 69 | public string ButtonClass { get; set; } 70 | } 71 | } -------------------------------------------------------------------------------- /Base/Services/_Config.cs_old: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | 4 | namespace Base.Services 5 | { 6 | public class _Config 7 | { 8 | /// 9 | /// get db connection string in web.config 10 | /// 11 | /// 12 | /// 13 | public static string GetDbStr(string field) 14 | { 15 | if (ConfigurationManager.ConnectionStrings[field] != null) 16 | return ConfigurationManager.ConnectionStrings[field].ConnectionString; 17 | 18 | _Log.Error("config no db connection field. (" + field + ")"); 19 | return ""; 20 | } 21 | 22 | /// 23 | /// get config string value 24 | /// 25 | /// field name 26 | /// default value 27 | /// log error or not, default yes 28 | /// 變數值 29 | public static string GetStr(string field, string value = "", bool log = true) 30 | { 31 | if (ConfigurationManager.AppSettings[field] != null) 32 | return ConfigurationManager.AppSettings[field]; 33 | 34 | if (log) 35 | _Log.Error("config file has no field. (" + field + ")"); 36 | return value; 37 | } 38 | 39 | public static bool GetBool(string field, bool value = false, bool log = true) 40 | { 41 | var data = GetStr(field, "", log).ToLower(); 42 | return (data == "") 43 | ? value 44 | : (data == "true"); 45 | } 46 | 47 | public static int GetInt(string field, int value = 0, bool log = true) 48 | { 49 | //int value; 50 | if (Int32.TryParse(GetStr(field, "", log), out value)) 51 | return value; 52 | 53 | _Log.Error("config file int field wrong. (" + field + ")"); 54 | return value; 55 | } 56 | 57 | }//class 58 | } 59 | -------------------------------------------------------------------------------- /Base/Services/BaseEditSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Newtonsoft.Json.Linq; 3 | using System.Threading.Tasks; 4 | 5 | namespace Base.Services 6 | { 7 | /// 8 | /// auto Ctrl variables for all xxxEdit.cs/xxxE.cs 9 | /// 包含 CrudGet、CrudEdit 功能 10 | /// 11 | abstract public class BaseEditSvc 12 | { 13 | /// 14 | /// controller name, auto set 15 | /// 16 | public string Ctrl; 17 | 18 | /// 19 | /// 自行函數 for 設定 new key 20 | /// 21 | //public FnValidate? fnValidate { get; set; } 22 | //public Func?>? FnValidate { get; set; } 23 | 24 | public BaseEditSvc(string ctrl) 25 | { 26 | Ctrl = ctrl; 27 | } 28 | 29 | //derived class implement. 30 | abstract public EditDto GetDto(); 31 | 32 | //EditService -> EditSvc 33 | public CrudEditSvc EditSvc() 34 | { 35 | return new CrudEditSvc(Ctrl, GetDto()); 36 | } 37 | 38 | //GetService -> GetSvc 39 | public CrudGetSvc GetSvc() 40 | { 41 | return new CrudGetSvc(Ctrl, GetDto()); 42 | } 43 | 44 | public virtual async Task GetUpdJsonA(string key) 45 | { 46 | return await GetSvc().GetUpdJsonA(key); 47 | } 48 | 49 | public virtual async Task GetViewJsonA(string key) 50 | { 51 | return await GetSvc().GetViewJsonA(key); 52 | } 53 | 54 | public virtual async Task CreateA(JObject json) 55 | { 56 | return await EditSvc().CreateA(json); 57 | } 58 | 59 | //can override 60 | public virtual async Task UpdateA(string key, JObject json) 61 | { 62 | return await EditSvc().UpdateA(key, json); 63 | } 64 | 65 | public virtual async Task DeleteA(string key) 66 | { 67 | return await EditSvc().DeleteA(key); 68 | } 69 | 70 | }//class 71 | } 72 | -------------------------------------------------------------------------------- /Base/Services/_Num.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Services 5 | { 6 | public class _Num 7 | { 8 | /// 9 | /// get RWD col number 10 | /// 11 | /// columns count, 1-12 12 | /// 13 | public static int NumToRwdCol(int itemCount) 14 | { 15 | return itemCount switch 16 | { 17 | 1 => 12, 18 | 2 => 6, 19 | 3 => 4, 20 | 4 => 3, 21 | 6 => 2, 22 | 12 => 1, 23 | _ => 12, 24 | }; 25 | } 26 | 27 | /// 28 | /// convert string into List 29 | /// 30 | /// 31 | /// 32 | /// 33 | public static List StrToList(string text, char sep) 34 | { 35 | var result = new List(); 36 | if (_Str.IsEmpty(text)) return result; 37 | 38 | var list = text.Split(sep); 39 | foreach (var item in list) 40 | if (int.TryParse(item, out var num)) result.Add(num); 41 | return result; 42 | } 43 | 44 | public static int TryParse(object? obj, int value) 45 | { 46 | return (obj == null) ? value : 47 | int.TryParse(obj.ToString(), out var num) ? num : value; 48 | } 49 | 50 | /// 51 | /// get random number 52 | /// consider Vulnerability "Use of Cryptographically Weak PRNG" 53 | /// @param maxNum max number 54 | /// 55 | /// 56 | public static int GetRandom(int maxNum) 57 | { 58 | var random = new Random(Guid.NewGuid().GetHashCode()); 59 | return random.Next(0, maxNum); 60 | /* 61 | var rng = new RNGCryptoServiceProvider(); 62 | var rndBytes = new byte[4]; 63 | rng.GetBytes(rndBytes); 64 | return BitConverter.ToInt32(rndBytes, 0); 65 | */ 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /BaseWeb/Helpers_old/XiRadioHelper.cs: -------------------------------------------------------------------------------- 1 | using BaseWeb.Services; 2 | using BaseWeb.Models; 3 | using Microsoft.AspNetCore.Html; 4 | using Microsoft.AspNetCore.Mvc.Rendering; 5 | 6 | namespace BaseWeb.Helpers 7 | { 8 | /// 9 | /// single radio, for single/multi edit form 10 | /// no validate span !! 11 | /// 12 | public static class XiRadioHelper 13 | { 14 | 15 | /// 16 | /// radio 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 25 | public static IHtmlContent XiRadio(this IHtmlHelper htmlHelper, string fid = "", bool isCheck = false, string value = "1", string label = "", PropInputDto prop = null) 26 | { 27 | if (prop == null) 28 | prop = new PropInputDto(); 29 | 30 | //adjust 31 | if (label == "") 32 | label = " "; //add space, or position will wrong !! 33 | 34 | //attr 35 | //第3個參數 isInDt: false 36 | var attr = _Helper.GetBaseAttr(fid, prop) + 37 | " value='" + value + "'" + 38 | _Helper.GetFnOnChange("onclick", prop, "this.checked"); 39 | if (isCheck) 40 | attr += " checked"; 41 | 42 | /* 43 | //box class 44 | var boxClass = prop.Inline ? "xg-inline" : ""; 45 | if (prop.BoxClass != "") 46 | boxClass += " " + prop.BoxClass; 47 | */ 48 | 49 | //ext class 50 | //var extClass = (prop.ExtClass == "") ? "" : " " + prop.ExtClass; 51 | //if (prop.InDt) 52 | // extClass += " xg-in-dt"; 53 | 54 | //沒有 box container, 只有radio !! 55 | var html = string.Format(@" 56 | 60 | ", prop.ExtClass, attr, label); 61 | 62 | return new HtmlString(html); 63 | } 64 | 65 | }//class 66 | } -------------------------------------------------------------------------------- /BaseWeb/Services/ImageData.cs_old: -------------------------------------------------------------------------------- 1 | using System; 2 | using DocumentFormat.OpenXml.Packaging; 3 | using System.Drawing; 4 | using System.IO; 5 | 6 | namespace BaseWeb.Services 7 | { 8 | public class ImageData 9 | { 10 | public string FileName = string.Empty; 11 | public byte[] BinaryData; 12 | public Stream DataStream => new MemoryStream(BinaryData); 13 | public ImagePartType ImageType 14 | { 15 | get 16 | { 17 | var ext = Path.GetExtension(FileName).TrimStart('.').ToLower(); 18 | switch (ext) 19 | { 20 | case "jpg": 21 | return ImagePartType.Jpeg; 22 | case "png": 23 | return ImagePartType.Png; 24 | case "": 25 | return ImagePartType.Gif; 26 | case "bmp": 27 | return ImagePartType.Bmp; 28 | } 29 | throw new ApplicationException($"Unsupported image type: {ext}"); 30 | } 31 | } 32 | public int SourceWidth; 33 | public int SourceHeight; 34 | public decimal Width; 35 | public decimal Height; 36 | public long WidthInEMU => Convert.ToInt64(Width * CM_TO_EMU); 37 | public long HeightInEMU => Convert.ToInt64(Height * CM_TO_EMU); 38 | private const decimal INCH_TO_CM = 2.54M; 39 | private const decimal CM_TO_EMU = 360000M; 40 | public string ImageName; 41 | public ImageData(string fileName, byte[] data, int dpi = 300) 42 | { 43 | FileName = fileName; 44 | BinaryData = data; 45 | Bitmap img = new Bitmap(new MemoryStream(data)); 46 | SourceWidth = img.Width; 47 | SourceHeight = img.Height; 48 | Width = ((decimal)SourceWidth) / dpi * INCH_TO_CM; 49 | Height = ((decimal)SourceHeight) / dpi * INCH_TO_CM; 50 | ImageName = $"IMG_{Guid.NewGuid().ToString().Substring(0, 8)}"; 51 | } 52 | public ImageData(string fileName, int dpi = 300) : 53 | this(fileName, File.ReadAllBytes(fileName), dpi) 54 | { 55 | } 56 | 57 | }//class 58 | } 59 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgCrudFunViewComponent.cs: -------------------------------------------------------------------------------- 1 | using BaseApi.Services; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BaseWeb.ViewComponents 6 | { 7 | //改成前端設定?? 8 | public class XgCrudFunViewComponent : ViewComponent 9 | { 10 | public HtmlString Invoke(string key, string rowName = "", 11 | bool hasUpdate = false, bool hasDelete = false, bool hasView = false, 12 | string fnOnUpdate = "", string fnOnDelete = "", string fnOnView = "") 13 | { 14 | var br = _Locale.GetBaseRes(); 15 | var funs = ""; 16 | /* 17 | if (hasUpdate) 18 | funs += string.Format("", ((fnOnUpdate == "") ? "_me.crudR.onUpdateA" : fnOnUpdate), key, br.TipUpdate); 19 | if (hasDelete) 20 | funs += string.Format("", ((fnOnDelete == "") ? "_me.crudR.onDeleteA" : fnOnDelete), key, rowName, br.TipDelete); 21 | if (hasView) 22 | funs += string.Format("", ((fnOnView == "") ? "_me.crudR.onViewA" : fnOnView), key, br.TipView); 23 | */ 24 | if (hasUpdate) 25 | funs += $""; 26 | if (hasDelete) 27 | funs += $""; 28 | if (hasView) 29 | funs += $""; 30 | return new HtmlString(funs); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /BaseWeb/BaseWeb.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | Library 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgFindTbarViewComponent.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp.Dom; 2 | using Base.Services; 3 | using BaseApi.Services; 4 | using BaseWeb.Models; 5 | using Microsoft.AspNetCore.Html; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | //查詢畫面右上方工具列 9 | namespace BaseWeb.ViewComponents 10 | { 11 | //配合 _xp.js 12 | public class XgFindTbarViewComponent : ViewComponent 13 | { 14 | /// 15 | /// program title: left(path), right(tool) 16 | /// 17 | /// 18 | /// 19 | public HtmlString Invoke(XgFindTbarDto? dto = null) 20 | { 21 | dto ??= new XgFindTbarDto(); 22 | 23 | /* 24 | var fnOnFind = _Str.IsEmpty(dto.FnWhenFind) 25 | ? "_me.crudR.onFind()" 26 | : dto.FnWhenFind; 27 | */ 28 | 29 | //set toolbar buttons, 使用string.format, 無法使用 $"" !! 30 | var baseR = _Locale.GetBaseRes(); 31 | var html = $""; 32 | if (dto.HasReset) 33 | html += $""; 34 | if (dto.HasFind2) 35 | html += $""; 36 | 37 | if (dto.IsHori) 38 | //html = "" + html + ""; 39 | html = dto.SpanMode 40 | ? $@" 41 |
42 | {html} 43 |
" 44 | : $@" 45 |
46 |
47 | {html} 48 |
49 |
"; 50 | else 51 | { 52 | //vertical 53 | html = $@" 54 |
55 |
56 |
57 | {html} 58 |
59 |
"; 60 | } 61 | return new HtmlString(html); 62 | } 63 | 64 | } //class 65 | } -------------------------------------------------------------------------------- /BaseApi/Services/XgProgEdit.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | 4 | namespace BaseApi.Services 5 | { 6 | public class XgProgEdit : BaseEditSvc 7 | { 8 | public XgProgEdit(string ctrl) : base(ctrl) { } 9 | 10 | override public EditDto GetDto() 11 | { 12 | return new EditDto 13 | { 14 | Table = "dbo.XpProg", 15 | PkeyFid = "Id", 16 | Col4 = null, 17 | Items = 18 | [ 19 | new() { Fid = "Id" }, 20 | new() { Fid = "Code", Required = true }, 21 | new() { Fid = "Name", Required = true }, 22 | //new() { Fid = "Icon" }, 23 | new() { Fid = "Url" }, 24 | new() { Fid = "Sort" }, 25 | new() { Fid = "AuthRow", Value = 0 }, //default 0 26 | new() { Fid = "FunCreate" }, 27 | new() { Fid = "FunRead" }, 28 | new() { Fid = "FunUpdate" }, 29 | new() { Fid = "FunDelete" }, 30 | new() { Fid = "FunPrint" }, 31 | new() { Fid = "FunExport" }, 32 | new() { Fid = "FunView" }, 33 | ], 34 | Childs = 35 | [ 36 | new EditDto 37 | { 38 | Table = "dbo.XpRoleProg", 39 | PkeyFid = "Id", 40 | FkeyFid = "ProgId", 41 | Col4 = null, 42 | Items = 43 | [ 44 | new() { Fid = "Id" }, 45 | new() { Fid = "ProgId" }, 46 | new() { Fid = "RoleId", Required = true }, 47 | new() { Fid = "FunCreate" }, 48 | new() { Fid = "FunRead" }, 49 | new() { Fid = "FunUpdate" }, 50 | new() { Fid = "FunDelete" }, 51 | new() { Fid = "FunPrint" }, 52 | new() { Fid = "FunExport" }, 53 | new() { Fid = "FunView" }, 54 | ], 55 | }, 56 | ], 57 | }; 58 | } 59 | 60 | } //class 61 | } 62 | -------------------------------------------------------------------------------- /Base/Models/ExcelImportDto.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.Collections.Generic; 3 | 4 | namespace Base.Models 5 | { 6 | //for excel import function 7 | //import source file name: Id + ".xlsx" 8 | //import failed file name: Id + "_fail.xlsx" 9 | public class ExcelImportDto where T : class, new() 10 | { 11 | //public FnCheckImportRow FnCheckImportRow = null; 12 | 13 | /// 14 | /// (delegate) save imported rows into DB 15 | /// ex: private List SaveImportRows(List okRows) 16 | /// 17 | public FnSaveImportRows? FnSaveImportRows; 18 | 19 | public FnSaveImportRowsA? FnSaveImportRowsA; 20 | 21 | /// 22 | /// map to ImportLog.Type 23 | /// 24 | public string ImportType = ""; 25 | 26 | /// 27 | /// template file path 28 | /// 29 | public string TplPath = ""; 30 | 31 | /// 32 | /// directory for save excel file(source & failed) 33 | /// 34 | //public string DirSaveFile; 35 | 36 | /// 37 | /// empty means excel row0 is fid, order should same to imported file 38 | /// c# 讀取 excel 日期欄位會變成數字(從1900/1/1開始計算), 如果的欄位type為string, 但excel欄位為日期, 39 | /// 則該欄位應寫為D:xxx, 表示系統會轉成日期字串再儲存 40 | /// 41 | public List ExcelFids = []; 42 | 43 | /// 44 | /// excel col name, ex:A,B.., if not empty then array/order should map th ExcelFids 45 | /// 46 | //public List ExcelColNames = new List(); 47 | 48 | /// 49 | /// excel data sheet no(base 0), default 0 50 | /// 51 | public int SheetNo = 0; 52 | 53 | /// 54 | /// excel fid start row(base 1, 與excel相同), default 1 55 | /// 56 | public int FidRowNo = 1; 57 | 58 | /// 59 | /// ImportLog table row Id, set to _Str.NewId() if empty 60 | /// 61 | public string LogRowId = ""; 62 | 63 | /// 64 | /// creator name 65 | /// 66 | public string CreatorName = ""; 67 | 68 | } 69 | } -------------------------------------------------------------------------------- /Base/Services/_Page.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Base.Services 6 | { 7 | /// 8 | /// for EasyDtDto 9 | /// 10 | public class _Page 11 | { 12 | //private static List PageRowRanges = new() { 10, 25, 50, 100 }; 13 | private static List PageRowRanges = [10, 20, 50, 100]; //for more friendly !! 14 | 15 | public static PageIn GetPageIn(int pageNo, int pageRows, int filterRows, List? args = null) 16 | { 17 | //pageRows = GetPageRows(pageRows); 18 | var result = new PageIn() 19 | { 20 | //start = (pageNo - 1) * pageRows, 21 | page = pageNo, 22 | length = pageRows, 23 | filterRows = filterRows, 24 | }; 25 | if (args != null) 26 | { 27 | var json = new JObject(); 28 | for (var i=0; i GetError(PageOut page, string error = "") where T : class 42 | { 43 | page._ErrorMsg = _Str.EmptyToValue(error, _Fun.SystemError); 44 | return page; 45 | } 46 | 47 | public static PageOut GetBrError(PageOut page, string fid) where T : class 48 | { 49 | page._ErrorMsg = _Fun.PreBrError + fid; 50 | return page; 51 | } 52 | 53 | /* 54 | public static void SetPageArg(PageOut page, int pageNo, int pageRows, int filterCount) where T : class 55 | { 56 | var json = JObject.FromObject(new 57 | { 58 | page = pageNo, 59 | filterCount = filterCount, 60 | pageRows = pageRows, 61 | }); 62 | page.PageArg = _Json.ToStr(json); 63 | } 64 | */ 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /BaseApi/Services/_AuthFB.cs: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using Newtonsoft.Json.Linq; 3 | using System.Threading.Tasks; 4 | 5 | namespace BaseApi.Services 6 | { 7 | //Facebook OAuth 8 | public static class _AuthFB 9 | { 10 | private static bool _init = false; 11 | private static string _redirect = ""; 12 | private static string _clientId = ""; 13 | private static string _clientSecret = ""; 14 | 15 | public static void Init(string redirect, string clientId, string clientSecret) 16 | { 17 | if (_init) return; 18 | 19 | _init = true; 20 | _redirect = redirect; 21 | _clientId = clientId; 22 | _clientSecret = clientSecret; 23 | } 24 | 25 | /// 26 | /// get auth url 27 | /// 28 | /// use state' for extra parameter 29 | /// 30 | public static string GetAuthUrl(string arg = "") 31 | { 32 | //response_type=code for call by server side !! 33 | var url = "https://www.facebook.com/v13.0/dialog/oauth"; 34 | url = $"{url}?redirect_uri={_redirect}&client_id={_clientId}&response_type=code&auth_type=reauthenticate"; 35 | if (arg != "") 36 | url += "&state=" + arg; 37 | return url; 38 | } 39 | 40 | //auth code to token 41 | public static async Task CodeToTokenA(string code) 42 | { 43 | var url = "https://graph.facebook.com/v13.0/oauth/access_token"; 44 | var args = $"code={code}&client_id={_clientId}&client_secret={_clientSecret}&redirect_uri={_redirect}&grant_type=authorization_code"; 45 | var json = _Str.ToJson(await _Http.GetUrlResultA(url, args, false)); 46 | return json!["access_token"]!.ToString(); 47 | } 48 | 49 | //email in it 50 | public static async Task GetUserA(string token) 51 | { 52 | var url = "https://graph.facebook.com/v2.3/me"; 53 | //url = $"{url}?fields=name,email&access_token={token}"; 54 | url = $"{url}?fields=email&access_token={token}"; 55 | var result = await _Http.GetUrlResultA(url); 56 | return _Str.ToJson(result); 57 | } 58 | 59 | }//class 60 | } 61 | -------------------------------------------------------------------------------- /BaseApi/Services/_HttpWord.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Base.Services; 3 | using System.Collections.Generic; 4 | using System.Runtime.Intrinsics.Arm; 5 | using System.Threading.Tasks; 6 | 7 | namespace BaseApi.Services 8 | { 9 | /// 10 | /// use NPOI output word(docx), cause duplicate, put here(not in _Http.cs) 11 | /// temlate has 2 type data: (need cancel spell check at word editor !!) 12 | /// 1.single row: ex:[StartDate], fixed rows could use copy/paste then change font !! 13 | /// //2.multi rows: ex:[m_Schools], must put bookmark in docx(named m_Schools) 14 | /// steps : 15 | /// 1.do multiple rows first: insert table into docx bookmark (use insertAfter) 16 | /// 2.then do single row: output docx to string, then find/replace 17 | /// note: 18 | /// 1.when edit word template file, word will cut your word auto, must keyin your word at one time !! 19 | /// 20 | public static class _HttpWord 21 | { 22 | /// 23 | /// ExportByTplRowA -> OutputTplA 24 | /// export file by template and row 25 | /// 26 | /// tpl path 27 | /// export file name 28 | /// 可為JObject或Model 29 | /// 可為JArray或List, IEnumerable for anonymous type 30 | /// 31 | /// error msg if any 32 | public static async Task OutputTplA(string tplPath, string fileName, dynamic row, 33 | List? childs = null, List? images = null) 34 | { 35 | var ms = await _Word.TplToMsA(tplPath, row, childs, images); 36 | if (ms == null) return false; 37 | 38 | await _FunApi.ExportByStreamA(ms, fileName); 39 | return true; 40 | } 41 | 42 | public static bool OutputTplA2() 43 | { 44 | var oldWordPath = "C:\\_project\\HrAdm\\_template\\zh-TW\\UserExt.docx"; 45 | var newWordPath = "C:\\_project\\HrAdm\\_template\\zh-TW\\UserExt_new.docx"; 46 | var newImagePath = "C:\\_project\\HrAdm\\_upload\\UserExt\\PhotoFile_Alex.png"; 47 | _Word.AddImage(oldWordPath, newWordPath, newImagePath); 48 | return false; 49 | } 50 | }//class 51 | } 52 | -------------------------------------------------------------------------------- /BaseWeb/ViewComponents/XgLeftMenuViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Base.Models; 2 | using Microsoft.AspNetCore.Html; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System.Collections.Generic; 5 | 6 | namespace BaseWeb.ViewComponents 7 | { 8 | 9 | public class XgLeftMenuViewComponent : ViewComponent 10 | { 11 | /// 12 | /// left side menu(max to 2 levels), outside class name is x-leftmenu 13 | /// 14 | /// 15 | /// menu rows 16 | /// px 17 | /// px 18 | /// 19 | public HtmlString Invoke(List rows, bool showSort = false) 20 | { 21 | if (showSort) 22 | { 23 | rows.ForEach(a => { 24 | a.Name = a.Sort + "." + a.Name; 25 | }); 26 | } 27 | 28 | var html = ""; 29 | foreach (var row in rows) 30 | { 31 | //no sub menu 32 | if (row.Items == null || row.Items.Count == 0) 33 | { 34 | html += string.Format(@" 35 |
  • 36 | 37 | {2} 38 | 39 |
  • 40 | ", row.Url, row.Icon, row.Name); 41 | } 42 | //has sub menu 43 | else 44 | { 45 | var childs = ""; 46 | foreach (var item in row.Items) 47 | { 48 | childs += string.Format(@" 49 |
  • {1}
  • 50 | ", item.Url, item.Name); 51 | } 52 | 53 | html += string.Format(@" 54 |
  • 55 | 59 | 62 |
  • 63 | ", row.Icon, row.Name, childs); 64 | 65 | }//if 66 | }//for 67 | 68 | //加上尾端 for 填空白 69 | html += "
  • "; 70 | 71 | //外面加上 ul 72 | html = "
      " + html + "
    "; 73 | return new HtmlString(html); 74 | } 75 | 76 | }//class 77 | } 78 | -------------------------------------------------------------------------------- /Base/Services/_Login.cs_old: -------------------------------------------------------------------------------- 1 | using Base.Services; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace Base 6 | { 7 | public class _Login 8 | { 9 | 10 | //記錄登入成功 11 | public static async Task LogOkA(string account, Db? db = null) 12 | { 13 | var newDb = _Db.CheckOpenDb(ref db); 14 | var args = new List() { "Account", account }; 15 | var count = await db!.ExecSqlA($@" 16 | update dbo.Login set LoginStatus=1, LoginTime=getDate(), FailCount=0 17 | where Account=@Account 18 | ", args); 19 | if (count == 0) 20 | { 21 | await db.ExecSqlA($@" 22 | insert into dbo.Login(Account, LoginStatus, LoginTime, FailCount) values ( 23 | @Account, 1, getDate(), 0 24 | )", args); 25 | } 26 | await _Db.CheckCloseDbA(db!, newDb); 27 | } 28 | 29 | /// 30 | /// 記錄登入失敗 31 | /// 32 | /// 33 | /// 34 | /// false表示失敗次數超過 _Fun.MaxLoginFail 35 | public static async Task LogFailA(string account, Db? db = null) 36 | { 37 | var newDb = _Db.CheckOpenDb(ref db); 38 | var args = new List() { "Account", account }; 39 | var failCount = await db!.GetIntA(@" 40 | select FailCount from dbo.Login 41 | where Account=@Account 42 | ", args); 43 | bool result; 44 | if (failCount == null) 45 | { 46 | await db.ExecSqlA(@" 47 | insert into dbo.Login(Account, LoginStatus, LoginTime, FailCount) values ( 48 | @Account, 1, getDate(), 1 49 | )", args); 50 | result = true; 51 | } 52 | else if (failCount < _Fun.MaxLoginFail) 53 | { 54 | await db!.ExecSqlA(@" 55 | update dbo.Login set LoginStatus=0, LoginTime=getDate(), FailCount=FailCount+1 56 | where Account=@Account 57 | ", args); 58 | result = true; 59 | } 60 | else 61 | { 62 | await db!.ExecSqlA(@" 63 | update dbo.[User] set IsLock=1 64 | where Account=@Account 65 | ", args); 66 | result = false; 67 | } 68 | 69 | await _Db.CheckCloseDbA(db!, newDb); 70 | return result; 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Base/Services/_Redis.cs_old: -------------------------------------------------------------------------------- 1 | using StackExchange.Redis; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace Base.Services 6 | { 7 | /// 8 | /// use StackExchange Redis currently 9 | /// 配合 memoryCache, 使用同步取值 10 | /// 11 | public static class _Redis 12 | { 13 | private static readonly ConnectionMultiplexer _redis; 14 | private static readonly IDatabase _db; //current redis database 15 | 16 | //constructor 17 | static _Redis() 18 | { 19 | try 20 | { 21 | _redis = ConnectionMultiplexer.Connect(_Fun.Config.Redis); 22 | _db = _redis.GetDatabase(); 23 | } 24 | catch(Exception ex) 25 | { 26 | _redis = null; 27 | _ = _Log.ErrorA("_Redis.cs failed: " + ex.Message); //discard result !! 28 | } 29 | } 30 | 31 | //is redis status ok or not 32 | private static bool IsOk() 33 | { 34 | return (_redis != null); 35 | } 36 | 37 | /// 38 | /// get string value 39 | /// 40 | /// 41 | /// null if not found 42 | public static string GetStr(string key) 43 | { 44 | if (!IsOk()) 45 | return null; 46 | 47 | var value = _db.StringGet(key); 48 | return (value.IsNull) 49 | ? null 50 | : value.ToString(); 51 | } 52 | 53 | public static bool SetStr(string key, string value) 54 | { 55 | if (!IsOk()) 56 | return false; 57 | 58 | return _db.StringSet(key, value); 59 | } 60 | 61 | public static bool DeleteKey(string key) 62 | { 63 | if (!IsOk()) 64 | return false; 65 | 66 | return _db.KeyDelete(key); 67 | } 68 | 69 | /* 70 | /// 71 | /// delete all keys in current database index 72 | /// 73 | public static async Task FlushDbA() 74 | { 75 | if (!IsOk()) 76 | return; 77 | 78 | var server = _redis.GetServer(_redis.GetEndPoints()[0]); 79 | await server.FlushDatabaseAsync(); 80 | } 81 | */ 82 | 83 | }//class 84 | } 85 | -------------------------------------------------------------------------------- /BaseApi/Attributes/XgServerAttribute.cs: -------------------------------------------------------------------------------- 1 | using Base.Enums; 2 | using Base.Services; 3 | using BaseApi.Services; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.AspNetCore.Mvc.Controllers; 6 | using Microsoft.AspNetCore.Mvc.Filters; 7 | using Microsoft.AspNetCore.Mvc.ModelBinding; 8 | using Microsoft.AspNetCore.Mvc.ViewFeatures; 9 | using Microsoft.AspNetCore.Routing; 10 | 11 | namespace BaseApi.Attributes 12 | { 13 | //檢查來源IP是否符合組態檔設定 14 | public class XgServerAttribute : ActionFilterAttribute 15 | { 16 | public override void OnActionExecuting(ActionExecutingContext context) 17 | { 18 | //check client ip 19 | var clientIp = _Http.GetIp(); 20 | if (_Auth.CheckClientIp(clientIp)) 21 | { 22 | //case of ok 23 | base.OnActionExecuting(context); 24 | return; 25 | } 26 | 27 | //log error 28 | _Log.Error($"Client IP 未授權: {clientIp}"); 29 | 30 | //case of error below 31 | //get return type 32 | var error = _Locale.GetBaseRes().NoAuth; 33 | var returnType = (context.ActionDescriptor is ControllerActionDescriptor actor) 34 | ? actor.MethodInfo.ReturnType.Name 35 | : "ActionResult"; //default 36 | 37 | //return error 38 | if (returnType == "ActionResult") 39 | { 40 | //return error view 41 | context.Result = new ViewResult 42 | { 43 | ViewName = "~/Views/Shared/Error.cshtml", 44 | //Model為唯讀, 必須用ViewData傳值 !! 45 | ViewData = new ViewDataDictionary( new EmptyModelMetadataProvider(), 46 | context.ModelState) 47 | { 48 | Model = error, 49 | } 50 | }; 51 | } 52 | else if (returnType == "JsonResult") 53 | { 54 | //4.return error model 55 | context.Result = new JsonResult(new 56 | { 57 | Value = new { _ErrorMsg = error } 58 | }); 59 | } 60 | else 61 | { 62 | //5.return error json(ContentResult) 63 | var json = _Json.GetError(error); 64 | context.Result = new ContentResult 65 | { 66 | Content = _Json.ToStr(json), 67 | }; 68 | } 69 | } 70 | } //class 71 | } 72 | -------------------------------------------------------------------------------- /Base/Services/CacheRedisSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Interfaces; 2 | using StackExchange.Redis; 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | namespace Base.Services 7 | { 8 | /// 9 | /// Redis cache server(use StackExchange) 10 | /// 配合 MemoryCache 使用同步取值 11 | /// 12 | public class CacheRedisSvc : ICacheSvc 13 | { 14 | private readonly IDatabase _db = null!; //current redis database 15 | private readonly bool _status; //redis connection status 16 | //private string _preKey = ""; 17 | private IConnectionMultiplexer _redis = null!; 18 | 19 | //constructor 20 | public CacheRedisSvc(IConnectionMultiplexer redis) 21 | { 22 | try 23 | { 24 | _redis = redis; 25 | _db = redis.GetDatabase(); 26 | //_preKey = _Fun.UserId() + "_"; 27 | _status = true; 28 | } 29 | catch(Exception ex) 30 | { 31 | _status = false; 32 | _Log.Error("CacheRedisService.cs failed: " + ex.Message); //discard result !! 33 | } 34 | } 35 | 36 | private string GetKey(string userId, string key) 37 | { 38 | return userId + "_" + key; 39 | } 40 | 41 | /// 42 | /// get string value 43 | /// 44 | /// 45 | /// null if not found 46 | public string? GetStr(string userId, string key) 47 | { 48 | if (!_status) return null; 49 | var value = _db.StringGet(GetKey(userId, key)); 50 | return (value.IsNull) 51 | ? null : value.ToString(); 52 | } 53 | 54 | public bool SetStr(string userId, string key, string value) 55 | { 56 | if (!_status) return false; 57 | return _db.StringSet(GetKey(userId, key), value); 58 | } 59 | 60 | public bool DeleteKey(string userId, string key) 61 | { 62 | if (!_status) return false; 63 | return _db.KeyDelete(GetKey(userId, key)); 64 | } 65 | 66 | /* 67 | */ 68 | /// 69 | /// delete all keys in current database index 70 | /// 71 | public async Task ResetDbA() 72 | { 73 | if (!_status) return; 74 | var server = _redis.GetServer(_redis.GetEndPoints()[0]); 75 | await server.FlushDatabaseAsync(); 76 | } 77 | 78 | }//class 79 | } 80 | -------------------------------------------------------------------------------- /Base/Services/Extension.cs_old: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Base.Services 10 | { 11 | //?? 12 | public static class Extension 13 | { 14 | public static string ToTaiwanShortDate(this DateTime dt) 15 | { 16 | return (dt.Year-1911).ToString() + "/" + dt.ToString("MM/dd"); 17 | } 18 | 19 | public static string ToTaiwanLongDate(this DateTime dt) 20 | { 21 | return (dt.Year - 1911).ToString() + "/" + dt.ToString("MM/dd hh:mm:ss"); 22 | } 23 | 24 | public static bool HasPro(this object obj, string propertyName) 25 | { 26 | return obj.GetType().GetProperty(propertyName) != null; 27 | } 28 | 29 | public static string GetProp(this object obj, string propertyName) 30 | { 31 | if (obj.HasPro(propertyName) && obj.GetType().GetProperty(propertyName).GetValue(obj) != null) 32 | return obj.GetType().GetProperty(propertyName).GetValue(obj).ToString(); 33 | return ""; 34 | } 35 | 36 | public static T GetProp(this object obj, string propertyName) 37 | { 38 | if (obj.HasPro(propertyName)) 39 | { 40 | if (obj.GetType().GetProperty(propertyName).GetValue(obj)!=null) 41 | return (T)obj.GetType().GetProperty(propertyName).GetValue(obj); 42 | else return default(T); 43 | } 44 | return default(T); 45 | } 46 | 47 | public static T Map(this NameValueCollection obj,T t) where T : class 48 | { 49 | foreach (string kvp in obj.AllKeys) 50 | { 51 | PropertyInfo pi = t.GetType().GetProperty(kvp, BindingFlags.Public | BindingFlags.Instance); 52 | if (pi != null) 53 | { 54 | var type = pi.GetType(); 55 | var value = obj[kvp]; 56 | if (value!="") 57 | pi.SetValue(t, obj[kvp], null); 58 | } 59 | } 60 | 61 | return t; 62 | } 63 | 64 | private static Random random = new Random(); 65 | 66 | public static string RandomString(int length) 67 | { 68 | const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; 69 | return new string(Enumerable.Repeat(chars, length) 70 | .Select(s => s[random.Next(s.Length)]).ToArray()); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 其他語系:[繁中](Readme-TW.md)、[簡中](Readme-CN.md) 2 | 3 | ### 1 Introduction 4 | 5 | Base Repo is a public program that can be used as a reference when developing various C# projects to save development time. It contains 4 projects, each of which is used in different situations: 6 | - Base: The lowest level utility, its main functions are: processing of various basic data, file access, and CRUD services. All projects such as Console, API, and Web MVC must refer to the Base project. 7 | - BaseApi: Need to be referenced when developing API and MVC projects. The main functions are: permission control, HTTP file output, CRUD function, reports, sign-off process, Excel import, transaction records, etc. 8 | - BaseEther: access Ethereum smart contracts, blockchain and IPFS (distributed file system). 9 | - BaseWeb: You need to refer to it when developing MVC projects. The content is mainly the custom input fields of SSR (Server Side Rendering). 10 | 11 | ### 2. Download & Execute 12 | Download the Base Repo file from GitHub and unzip it to the local directory. Other projects can correctly refer to the Base-related projects. The _Base/Services/_Fun.Init function must be called at system startup for initialization to ensure normal operation of the function. It contains the following incoming parameters: 13 | * isDev: Whether it is development mode, the system will automatically read the current execution mode and pass it in. 14 | * diBox: ASP.NET Core uses many DI (dependency injection) services. Passing this service provider (service provider) as a parameter can facilitate us to use these DI services in the utility program. 15 | * dbType: Indicates the type of database used by the system. Current choices include MS SQL, Oracle, and MySQL. 16 | * authType: Indicates the permission level that the system can handle, which is divided into 4 levels according to the degree of laxity: 17 | 1. There are no permission restrictions, which means everyone can perform all tasks. 18 | 2. Controller level: It only controls whether a complete operation can be executed. When the user enters the operation, he can execute all the buttons or sub-functions in it. 19 | 3. Action level: For example, the system can set the permissions for users to perform CRUD sub-functions such as adding, querying, modifying, deleting, etc. for a certain operation. 20 | 4. Data level: When executing each sub-function within the job, the user can only access data within the permission range. For example, when the user's modification permission for a certain job is set to "Personal", the user cannot modify other people's data. Records owned. 21 | 22 | ### 3. Author 23 | 24 | - Bruce Chen - *Initial work* 25 | 26 | ### 4. Copyright statement 27 | 28 | This project uses the [MIT License](https://en.wikipedia.org/wiki/MIT_License). -------------------------------------------------------------------------------- /PdfSpire/SpireSvc.cs: -------------------------------------------------------------------------------- 1 | using Base.Interfaces; 2 | using Base.Models; 3 | using Base.Services; 4 | using Spire.Doc; 5 | using Spire.Doc.License; 6 | using Spire.Pdf; 7 | using Spire.Pdf.Graphics; 8 | using System.Drawing; 9 | 10 | namespace PdfSpire 11 | { 12 | public class SpireSvc : IPdfSvc 13 | { 14 | //private string _key = ""; 15 | 16 | public void SetKey(string keyPath) 17 | { 18 | if (string.IsNullOrEmpty(keyPath)) 19 | return; 20 | 21 | var key = _Xml.GetKeyProp(keyPath, "/License", "Key"); 22 | if (_Str.NotEmpty(key)) 23 | LicenseProvider.SetLicenseKey(key); 24 | } 25 | 26 | public byte[] WordToPdf(byte[] wordBytes, string keyPath = "") 27 | { 28 | SetKey(keyPath); 29 | 30 | using var ms = new MemoryStream(wordBytes); 31 | // 使用 Spire.Doc 加載 Word 檔案 32 | var pdf = new Document(ms); 33 | 34 | using var pdfStream = new MemoryStream(); 35 | // 將 Word 轉換為 PDF 36 | pdf.SaveToStream(pdfStream, Spire.Doc.FileFormat.PDF); 37 | return pdfStream.ToArray(); 38 | } 39 | 40 | public bool AddImages(string fromPath, string toPath, PdfImageDto[] imageDtos) 41 | { 42 | // 建立新的 PDF 文件,從現有檔案載入 43 | var pdf = new PdfDocument(fromPath); 44 | // 找到要插入圖片的頁面,這裡假設是第 imageDto.PageIndex 頁(從 0 開始) 45 | var page = pdf.Pages[0]; 46 | var rotate = (page.Rotation == PdfPageRotateAngle.RotateAngle90); 47 | 48 | // 讀取圖片 49 | foreach (var imageDto in imageDtos) 50 | { 51 | 52 | // 載入圖片, Spire 無法跨平台, 必須使用 System.Drawing.Image !! 53 | using var image = Image.FromFile(imageDto.FilePath); 54 | if (rotate) 55 | image.RotateFlip(RotateFlipType.Rotate270FlipNone); // 轉正方向 56 | 57 | float imageWidth = image.Width; 58 | float imageHeight = image.Height; 59 | 60 | // 轉換成 PdfImage 61 | var pdfImage = PdfImage.FromImage(image); 62 | 63 | // 計算等比例縮放後的高度 64 | float newWidth = (float)imageDto.Width; 65 | float scale = newWidth / imageWidth; 66 | float newHeight = imageHeight * scale; 67 | 68 | // 插入圖片(位置與新尺寸) 69 | var rect = new RectangleF( 70 | x: (float)imageDto.PosX, 71 | y: (float)imageDto.PosY, 72 | width: newWidth, 73 | height: newHeight 74 | ); 75 | 76 | page.Canvas.DrawImage(pdfImage, rect); 77 | } 78 | 79 | // 儲存 PDF 80 | pdf.SaveToFile(toPath, Spire.Pdf.FileFormat.PDF); 81 | pdf.Close(); 82 | 83 | return true; 84 | } 85 | 86 | } 87 | } 88 | --------------------------------------------------------------------------------