public int Insert(SqlConnection conn, DianpingGroupConfig groupConfig, SqlTransaction transaction = null) { const string sql = @"INSERT INTO DianpingGroupConfig (DianpingGroupId, DianpingBrand, DianpingTuanName, TuhuProductId, TuhuProductStatus) VALUES (@DianpingGroupId, @DianpingBrand, @DianpingTuanName, @TuhuProductId, @TuhuProductStatus)"; return(conn.Execute(sql, groupConfig, commandType: CommandType.Text, transaction: transaction)); }
public int Update(SqlConnection conn, DianpingGroupConfig groupConfig) { const string sql = @"UPDATE DianpingGroupConfig SET DianpingBrand = @DianpingBrand, DianpingTuanName = @DianpingTuanName, TuhuProductId = @TuhuProductId, TuhuProductStatus = @TuhuProductStatus, LastUpdateDateTime = getdate() WHERE DianpingGroupId = @DianpingGroupId"; return(conn.Execute(sql, groupConfig, commandType: CommandType.Text)); }
private Tuple <string, List <DianpingGroupConfig> > ConvertSheetToGroupConfig(ISheet sheet) { var result = new List <DianpingGroupConfig>(); var message = string.Empty; var titleRow = sheet.GetRow(sheet.FirstRowNum); var index = titleRow.FirstCellNum; if (string.Equals(titleRow.GetCell(index++)?.StringCellValue, "点评团购ID") && string.Equals(titleRow.GetCell(index++)?.StringCellValue, "点评品牌名称") && string.Equals(titleRow.GetCell(index++)?.StringCellValue, "点评团购名称") && string.Equals(titleRow.GetCell(index++)?.StringCellValue, "途虎服务产品ID") && string.Equals(titleRow.GetCell(index++)?.StringCellValue, "途虎服务状态")) { for (var rowIndex = sheet.FirstRowNum + 1; rowIndex <= sheet.LastRowNum; rowIndex++) { var row = sheet.GetRow(rowIndex); if (row == null) { continue; } var cellIndex = row.FirstCellNum; var item = new DianpingGroupConfig() { DianpingGroupId = getStringValue(row.GetCell(cellIndex++)), DianpingBrand = getStringValue(row.GetCell(cellIndex++)), DianpingTuanName = getStringValue(row.GetCell(cellIndex++)), TuhuProductId = getStringValue(row.GetCell(cellIndex++)), TuhuProductStatus = string.Equals(getStringValue(row.GetCell(cellIndex)), "已上架") ? 1 : 0 }; if (!string.IsNullOrEmpty(item.DianpingGroupId) && !string.IsNullOrEmpty(item.DianpingBrand) && !string.IsNullOrEmpty(item.DianpingTuanName) && !string.IsNullOrEmpty(item.TuhuProductId) && !string.IsNullOrEmpty(dianpingManager.GetTuhuProductName(item.TuhuProductId))) { result.Add(item); } else { message = $"第{rowIndex + 1}行数据错误"; break; } } } else { message = "文件与模板不一致"; } return(Tuple.Create(message, result)); }
public int InsertGroupConfig(DianpingGroupConfig groupConfig, string user) { int result = 0; if (groupConfig != null) { dbScopeManager.CreateTransaction(conn => { int rows = 0; var current = dalGroupConfig.SelectDianpingGroupConfig(conn, groupConfig.DianpingGroupId); if (current != null) { result = -1; } else { rows = dalGroupConfig.Insert(conn, groupConfig); result = rows == 1 ? 1 : 0; } }); } if (result == 1) { var log = new { ObjectId = groupConfig.DianpingGroupId, ObjectType = "InsertGroupConfig", BeforeValue = "", AfterValue = JsonConvert.SerializeObject(groupConfig), Remark = "", Creator = user }; LoggerManager.InsertLog("CommonConfigLog", log); } return(result); }
public bool UpsertGroupConfig(DianpingGroupConfig groupConfig) { bool result = false; if (groupConfig != null) { dbScopeManager.CreateTransaction(conn => { int rows = 0; var current = dalGroupConfig.SelectDianpingGroupConfig(conn, groupConfig.DianpingGroupId); if (current != null) { rows = dalGroupConfig.Update(conn, groupConfig); } else { rows = dalGroupConfig.Insert(conn, groupConfig); } result = rows > 0; }); } return(result); }