public void Write() { var array = new string[] { }; var name = array.GetType().Name; var helper = new DefaultExcelBulkEditHelper(); var model = new ExcelDataModel <CategroyExcelBulkRow, ProductExcelBulkRow>(); using (var stream = new FileStream($"{DateTime.Now.ToUnixStampDateTime()}.xlsx", FileMode.Create)) { using (var database = factory.GenerateDatabase()) { model.Data1 = database.SqlQuery <CategroyExcelBulkRow>("SELECT * FROM [dbo].[Category] (NOLOCK)").ToArray(); model.Data2 = database.SqlQuery <ProductExcelBulkRow>("SELECT * FROM [dbo].[Product] (NOLOCK)").ToArray(); model.Data2.ToList().ForEach(ctx => { var settings = ctx.Settings.DeserializeToObject <ProductSettings>(); ctx.Options = settings?.Specifications.SerializeToJson(); ctx.Banners = string.Join(",", (settings?.Banners.Select(x => x.Replace("https://www.yourc.club/images/products/", string.Empty))) ?? new string[] { ctx.ImageUrl.Replace("https://www.yourc.club/images/products/", string.Empty) }); ctx.Size = settings?.Specifications[0].SerializeToJson(); ctx.Temperature = settings?.Specifications[1].SerializeToJson(); ctx.ImageUrl = ctx.ImageUrl?.Replace("https://www.yourc.club/images/products/", string.Empty); ctx.Banners = string.IsNullOrEmpty(ctx.Banners) ? ctx.ImageUrl : ctx.Banners; }); } model.DataMark = new ExcelDataMark() { DateTime = DateTime.Now.ToUnixStampDateTime(), Additional = new Dictionary <string, string>(), Version = "1.0" }; helper.Write(stream, model); stream.Flush(); } }
public void Save(IEnumerable <RewardLogging> results) { if (results == null || results.Count() == 0) { return; } var queryString = @" MERGE INTO [dbo].[RewardLogging] [target] USING ( VALUES {0} )[source]([Id],[State],[LastUpdatedBy],[ErrorMessage]) ON [target].[Id] = [source].[Id] WHEN MATCHED THEN UPDATE SET [target].[State] = [source].[State], [target].[LastUpdatedBy] =[source].[LastUpdatedBy], [target].[ErrorMessage] = [source].[ErrorMessage], [target].[LastUpdatedDateTime] = DATEDIFF(S,'1970-01-01',SYSUTCDATETIME()); "; using (var database = databaseFactory.GenerateDatabase()) { var values = string.Join(",", results.Select((ctx) => { return($"({ctx.Id},{(int)ctx.State},'Sharing.Agent.Synchronizer','{ctx.ErrorMessage}')"); })); database.Execute(string.Format(queryString, values), null, System.Data.CommandType.Text); } }
public void RewardOnSharing(string appId, string openId) { using (var database = databaseFactory.GenerateDatabase()) { var update = @"UPDATE [dbo].[WxUser] SET [Shared] = 1 WHERE Id = (SELECT WxUserId FROM[dbo].[WxUserIdentity] WHERE[AppId] = @appid AND[OpenID] = @openId); "; var updateParameters = new DynamicParameters(); updateParameters.Add("@appid", appId); updateParameters.Add("@openId", openId); database.Execute(update, updateParameters, System.Data.CommandType.Text); var queryString = "[dbo].[spRewardOnSharing]"; var parameters = new DynamicParameters(); parameters.Add("@appid", appId); parameters.Add("@openId", openId); parameters.Add("@rewardMoneyLimit", configuration.GetRewardSettings().Limit); database.Execute(queryString, parameters, System.Data.CommandType.StoredProcedure); } }