public static bool GenScriptAction(List <ExcelRow> listExcelRows) { var valueNull = 0; var libActionRepository = new LibActionRepository(); var id = 0; using (StreamWriter stream = File.AppendText(PathFileExport)) { foreach (var item in listExcelRows) { if (!string.IsNullOrEmpty(item.IdAction) && !string.IsNullOrEmpty(item.ActionName) && !string.IsNullOrEmpty(item.ActionNumber) && !string.IsNullOrEmpty(item.ExcuteType)) { id = Convert.ToInt32(item.IdAction); var data = libActionRepository.GetById(id); if (data == null) { if (!ListIdActionAdd.Contains(id)) { ListIdActionAdd.Add(id); stream.WriteLine( "INSERT INTO `action`(`Id`,`Name`,`ActionNumber`,`ExecuteType`,`RouteName`,`Description`,`DocumentTypeKey`,`OperationAction`," + "`CreatedById`,`LastUserId`,`LastTime`,`CreatedOn`,`LastModified`) " + "VALUES ({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');", item.IdAction, item.ActionName, item.ActionNumber, item.ExcuteType, item.RouteName, "", !string.IsNullOrEmpty(item.DocumentTypeKey) ? item.DocumentTypeKey : valueNull.ToString(), !string.IsNullOrEmpty(item.OperationAction) ? item.OperationAction : valueNull.ToString(), CreateById, LastUserId, LastTime, CreatedOn, LastModified); } } else { if (!ListIdActionUpdate.Contains(id)) { ListIdActionUpdate.Add(id); stream.WriteLine( "UPDATE `action` SET " + "`Name` = '{0}'," + "`ActionNumber` = '{1}'," + "`ExecuteType` = {2}," + "`Description` = '{3}', " + "`DocumentTypeKey` = '{4}', " + "`OperationAction` = '{5}' " + "WHERE `Id` = {6};", item.ActionName, item.ActionNumber, item.ExcuteType, "", !string.IsNullOrEmpty(item.DocumentTypeKey) ? item.DocumentTypeKey : valueNull.ToString(), !string.IsNullOrEmpty(item.OperationAction) ? item.OperationAction : valueNull.ToString(), id); } } } } stream.WriteLine(); return(true); } }
public static bool UpdateActionRouteNameActionProperty() { var libActionRepository = new LibActionRepository(); using (StreamWriter stream = File.AppendText(PathFileExport)) { var listAction = libActionRepository.GetAll(); foreach (var item in listAction) { stream.WriteLine( "UPDATE `action` SET " + "`RouteName` = '{0}'," + "`ActionProperty` = '{1}'" + "WHERE `Id` = {2};", item.RouteName, item.ActionProperty, item.Id); } stream.WriteLine(); return(true); } }