public int Insert(SqlConnection conn, DianpingShopConfig shopConfig, SqlTransaction transaction = null) { const string sql = @"INSERT INTO DianpingShopConfig (DianpingId, DianpingName, DianpingShopName, TuhuShopId, GroupStatus) VALUES (@DianpingId, @DianpingName, @DianpingShopName, @TuhuShopId, @GroupStatus)"; return(conn.Execute(sql, shopConfig, commandType: CommandType.Text, transaction: transaction)); }
private Tuple <string, List <DianpingShopConfig> > ConvertSheetToShopConfig(ISheet sheet) { var result = new List <DianpingShopConfig>(); 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 dianpingId = getStringValue(row.GetCell(cellIndex++)); var dianpingName = getStringValue(row.GetCell(cellIndex++)); var dianpingShopName = getStringValue(row.GetCell(cellIndex++)); var idStr = getStringValue(row.GetCell(cellIndex++)); int tuhuShopId = 0; Int32.TryParse(idStr, out tuhuShopId); var groupStatus = getStringValue(row.GetCell(cellIndex)); var item = new DianpingShopConfig() { DianpingId = dianpingId, DianpingName = dianpingName, DianpingShopName = dianpingShopName, TuhuShopId = tuhuShopId, GroupStatus = string.Equals(groupStatus, "已配置") ? 1 : 0 }; if (!string.IsNullOrEmpty(item.DianpingId) && !string.IsNullOrEmpty(item.DianpingName) && !string.IsNullOrEmpty(item.DianpingShopName) && item.TuhuShopId > 0 && !string.IsNullOrEmpty(dianpingManager.GetTuhuShopName(item.TuhuShopId))) { result.Add(item); } else { message = $"第{rowIndex + 1}行数据错误"; break; } } } else { message = "文件与模板不一致"; } return(Tuple.Create(message, result)); }
public int Update(SqlConnection conn, DianpingShopConfig shopConfig) { const string sql = @"UPDATE DianpingShopConfig SET DianpingName = @DianpingName, DianpingShopName = @DianpingShopName, TuhuShopId = @TuhuShopId, GroupStatus = @GroupStatus, LastUpdateDateTime = getdate() WHERE DianpingId = @DianpingId"; return(conn.Execute(sql, shopConfig, commandType: CommandType.Text)); }
public int InsertShopConfig(DianpingShopConfig shopConfig, string user) { int result = 0; if (shopConfig != null) { dbScopeManager.CreateTransaction(conn => { int rows = 0; var current = dalShopConfig.SelectDianpingShopConfig(conn, shopConfig.DianpingId, shopConfig.TuhuShopId); if (current != null && current.Any()) { result = -1; } else { rows = dalShopConfig.Insert(conn, shopConfig); result = rows == 1 ? 1 : 0; } }); } if (result == 1) { var log = new { ObjectId = shopConfig.DianpingId, ObjectType = "InsertShopConfig", BeforeValue = "", AfterValue = JsonConvert.SerializeObject(shopConfig), Remark = "", Creator = user }; LoggerManager.InsertLog("CommonConfigLog", log); } return(result); }