本文整理汇总了C#中CsvReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.Dispose方法的具体用法?C# CsvReader.Dispose怎么用?C# CsvReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getDataTableOfLogFile
public DataTable getDataTableOfLogFile(string txtFilePath, string fileName)
{
try
{
Logger.logdata(logforimportmtalog, string.Format("getDataTableOfLogFile(..) has been started at {0}", DateTime.Now.ToString()));
CsvReader csv = new CsvReader(new StreamReader(txtFilePath + "\\" + fileName), true);
DataTable csvDataTable = new DataTable();
string[] headers = csv.GetFieldHeaders();
for (int i = 0; i < headers.Length; i++)
{
csvDataTable.Columns.Add(headers[i], typeof(string));
}
int fieldCount = csv.FieldCount;
while (csv.ReadNextRecord())
{
DataRow row = csvDataTable.NewRow();
for (int i = 0; i < fieldCount; i++)
{
row[i] = csv[i];
}
csvDataTable.Rows.Add(row);
}
Logger.logdata(logforimportmtalog, string.Format("getDataTableOfLogFile(..) method has been ended at {0}", DateTime.Now.ToString()));
csv.Dispose();
return csvDataTable;
}
catch (Exception ex)
{
Logger.logError(logforimportmtalog, ex);
throw ex;
}
}
示例2: Load
public List<ShapeData> Load(string FilePath)
{
List<ShapeData> balls = new List<ShapeData>();
CsvReader csv = new CsvReader(File.OpenText(FilePath));
balls = csv.GetRecords<ShapeData>().ToList();
csv.Dispose();
return balls;
}
示例3: Load
public List<BouncingBallClass> Load(string FilePath)
{
List<BouncingBallClass> balls = new List<BouncingBallClass>();
CsvReader csv = new CsvReader(File.OpenText(FilePath));
balls = csv.GetRecords<BouncingBallClass>().ToList();
csv.Dispose();
return balls;
}
示例4: ProcessCsvHelper
public static OperationStatus ProcessCsvHelper(string filePath, IDSMContext DataContext)
{
string Feedback = string.Empty;
StreamReader srCSV = new StreamReader(filePath);
CsvReader csvReader = new CsvReader(srCSV);
// NOTE:
// 'ID' error on CSV import is either is coming from this line, or the for each loop below.
// Temporarily fixed by adding an ID column to CSV
List<Player> FootballPlayerList = new List<Player>();
try
{
FootballPlayerList = new List<Player>(csvReader.GetRecords<Player>());
}
catch (Exception ex)
{
return OperationStatus.CreateFromException("Error reading from CSV.", ex);
}
try
{
foreach (Player m in FootballPlayerList)
{
DataContext.Players.Add(m);
}
DataContext.SaveChanges();
}
catch (Exception ex)
{
return OperationStatus.CreateFromException("Error saving players to DB from CSV.", ex);
}
srCSV.Dispose();
csvReader.Dispose();
return new OperationStatus { Status = true };
}
示例5: AuUpload
//.........这里部分代码省略.........
CsvReader csvRead = null;
try
{
string[] array = fileUpload.FileName.Split('.');
string ext = string.Empty;
if (array.Length > 0)
{
ext = array[array.Length - 1];
}
if (ext.Length == 0) return;
ext = ext.ToUpper();
if (!"csv".Equals(ext.ToLower()))
{
mvImportMaster.AddError("CSVファイルを選択してください・・・");
return;
}
if (File.Exists(Server.MapPath("./") + fileUpload.FileName))
{
File.Delete(Server.MapPath("./") + fileUpload.FileName);
}
fileUpload.SaveAs(Server.MapPath("./") + fileUpload.FileName);
csvRead = new CsvReader(Server.MapPath("./") + fileUpload.FileName, true, '\t');
csvRead.IsCheckQuote = true;
string sql = "DELETE FROM RbtDownloadImportAuTmp WHERE SessionId='" + Session.SessionID + "'";
DbHelper.ExecuteNonQuery(sql);
DataTable dt = new DataTable();
DataTable dtTmp = new DataTable();
dt.Load(csvRead);
string[] header = csvRead.GetFieldHeaders();
//string[] header = temp[0].Split("\t"):
if (dt.Rows.Count > 0)
{
//フォーマットチェック
for (int i = 0; i < Constants.ImportRbtDownloadAuHeader.Length; i++)
{
if (!Constants.ImportRbtDownloadAuHeader[i].Equals(header[i]))
{
mvImportMaster.AddError("CSVファイルのヘッダー部分が間違っています・・・");
return;
}
}
dt.Columns.Add("SessionId", Type.GetType("System.String"));
dt.Columns.Add("Updated", Type.GetType("System.String"));
dt.Columns.Add("Updator", Type.GetType("System.String"));
dt.Columns.Add("Created", Type.GetType("System.String"));
dt.Columns.Add("Creator", Type.GetType("System.String"));
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["SessionId"] = Session.SessionID;
dt.Rows[i]["Updated"] = DateTime.Now.ToString("yyyyMMddHHmmss");
dt.Rows[i]["Updator"] = Page.User.Identity.Name;
dt.Rows[i]["Created"] = DateTime.Now.ToString("yyyyMMddHHmmss");
dt.Rows[i]["Creator"] = Page.User.Identity.Name;
}
using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
{
copy.DestinationTableName = "RbtDownloadImportAuTmp";
copy.BatchSize = 3000;
copy.BulkCopyTimeout = 99999;
for (int i = 0; i < Constants.ImportRbtDownloadAuHeader.Length; i++)
{
copy.ColumnMappings.Add(i, Constants.ImportRbtDownloadAuDbRef[i]);
}
copy.ColumnMappings.Add(dt.Columns.Count - 5, "SessionId");
copy.ColumnMappings.Add(dt.Columns.Count - 4, "Updated");
copy.ColumnMappings.Add(dt.Columns.Count - 3, "Updator");
copy.ColumnMappings.Add(dt.Columns.Count - 2, "Created");
copy.ColumnMappings.Add(dt.Columns.Count - 1, "Creator");
copy.WriteToServer(dt);
}
}
Session["FolderPath"] = fileUpload.FileName;
Response.Redirect("ListRbtDownloadImportAu.aspx", false);
}
catch (Exception ex)
{
mvImportMaster.AddError("エラーが発生しました: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
}
示例6: loadTrivia
bool loadTrivia()
{
var config = app.Settings.Configs[configTrivia];
var fileName = config.Get(keyDatabase, fileDatabase);
if ( !File.Exists(fileName) )
{
Log.Warn(tag, "Could not load database; '{0}' is missing", fileName);
return false;
}
var file = new StreamReader(fileName);
var reader = new CsvReader(file);
var fileEntries = reader.GetRecords<TriviaEntry>();
var list = new List<TriviaEntry>();
foreach ( var entry in fileEntries )
{
if ( entry.Question.Trim() == "" || entry.Answer.Trim() == "" )
continue;
if ( entry.Wrong.Trim() == "" )
entry.Wrong = null;
list.Add(entry);
}
entries = shuffleEntries(list);
reader.Dispose();
file .Dispose();
Log.Debug(tag, "Loaded trivia database '{0}', {1} entries", fileName, entries.Length);
return true;
}
示例7: btnUpload_Click
//.........这里部分代码省略.........
copy.DestinationTableName = "SongImport";
copy.BatchSize = 3000;
copy.BulkCopyTimeout = 99999;
for (int i = 0; i < Constants.ImportFullDataHeader.Length; i++)
{
copy.ColumnMappings.Add(i, Constants.ImportFullDataDbRef[i]);
}
copy.ColumnMappings.Add(dt.Columns.Count - 8, "SessionId");
copy.ColumnMappings.Add(dt.Columns.Count - 7, "ImportType");
copy.ColumnMappings.Add(dt.Columns.Count - 6, "Status");
copy.ColumnMappings.Add(dt.Columns.Count - 5, "DelFlag");
copy.ColumnMappings.Add(dt.Columns.Count - 4, "Updated");
copy.ColumnMappings.Add(dt.Columns.Count - 3, "Updator");
copy.ColumnMappings.Add(dt.Columns.Count - 2, "Created");
copy.ColumnMappings.Add(dt.Columns.Count - 1, "Creator");
copy.WriteToServer(dt);
}
}
DbHelper.ExecuteNonQuery("Update SongImport set SongImport.CopyrightOrg = S.CopyrightOrg, SongImport.CopyrightContractId = S.CopyrightContractId, ContractorId = S.ContractorId From SongImport, Song S Where SongImport.SongId = S.SongId and SessionId = '" + Session.SessionID + "' and SongImport.ImportType = '" + importType + "'");
//DbHelper.ExecuteNonQuery("Update SongImport set SongImport.CopyrightOrg = Song.CopyrightOrg From SongImport, Song Where SongImport.SongId = Song.SongId and SongImport.ImportType = '" + importType + "' ");
//DbHelper.ExecuteNonQuery("Update SongImport set ContractorId = S.ContractorId From SongImport, Song S where SessionId = '" + Session.SessionID + "' and SongImport.ImportType = '" + importType + "' and S.SongId = SongImport.SongId ");
sql = "Select * from SongImport where SessionId = '" + Session.SessionID + "' and ImportType = '" + importType + "'";
SqlDatabase db = new SqlDatabase();
DataSet ds = new DataSet();
DataSet dsTmp = new DataSet();
SqlCommand cm = db.CreateCommand(sql);
SqlDataAdapter da = new SqlDataAdapter(cm);
da.Fill(ds);
dt = ds.Tables[0];
ArrayList sqlUpdate = new ArrayList();
foreach (DataRow row in dt.Rows)
{
string contractorId = row["ContractorId"].ToString();
string hbunRitsu = "";
if (!"".Equals(contractorId))
{
ContractorData data = new ContractorData();
ITransaction tran = factory.GetLoadObject(data, contractorId);
Execute(tran);
if (!HasError)
{
//編集の場合、DBに既存データを取得して設定する。
data = (ContractorData)tran.Result;
hbunRitsu = data.HbunRitsu;
}
}
string price = row["Price"].ToString();
string rate = hbunRitsu;
string priceNoTax = "";
string buyUnique = "";
string copyrightFeeUnique = "";
string KDDICommissionUnique = "";
string profitUnique = "";
if (!"".Equals(price) && !"".Equals(rate))
{
priceNoTax = Func.GetPriceNoTax(price);
buyUnique = Func.GetBuyUnique(priceNoTax, rate);
copyrightFeeUnique = Func.GetCopyrightFeeUnique(row["CopyrightContractId"].ToString(), priceNoTax, "1");
KDDICommissionUnique = Func.GetKDDICommissionUnique(priceNoTax);
profitUnique = Func.GetProfitUnique(priceNoTax, buyUnique, copyrightFeeUnique, KDDICommissionUnique);
}
string songId = row["SongId"].ToString();
sqlUpdate.Add("Update SongImport set hbunRitsu = '" + hbunRitsu + "', PriceNoTax = '" + priceNoTax + "', BuyUnique = '" + buyUnique + "', CopyrightFeeUnique = '" + copyrightFeeUnique + "', KDDICommissionUnique = '" + KDDICommissionUnique + "', ProfitUnique = '" + profitUnique + "'where SongId = '" + songId + "' and SessionId = '" + Session.SessionID + "' and SongImport.ImportType = '" + importType + "'");
}
for (int i = 0; i < sqlUpdate.Count; i++)
{
DbHelper.ExecuteNonQuery((string)sqlUpdate[i]);
}
DbHelper.ExecuteNonQuery("Update SongImport set SongImport.Status = 1 From SongImport, SongMedia SM Where SongImport.SongId = SM.SongMediaId and SM.TypeId = '1' and SessionId = '" + Session.SessionID + "' and SongImport.ImportType = '" + importType + "'");
db.Close();
///////////
Session["FolderPath"] = fileUpload.FileName;
Response.Redirect("FullUpdateListMasterImport.aspx", false);
}
catch (Exception ex)
{
mvImportMaster.AddError("エラーが発生しました: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
}
示例8: btnImport_Click
//.........这里部分代码省略.........
return;
}
if (File.Exists(Server.MapPath("./") + File1.PostedFile.FileName))
{
File.Delete(Server.MapPath("./") + File1.PostedFile.FileName);
}
File1.PostedFile.SaveAs(Server.MapPath("./") + File1.PostedFile.FileName);
csvRead = new CsvReader(Server.MapPath("./") + File1.PostedFile.FileName, true, ',');
csvRead.IsCheckQuote = true;
DataTable dt = new DataTable();
dt.Load(csvRead);
DataTable staffSchedule = new DataTable();
staffSchedule.Columns.Add("BuildingId", Type.GetType("System.String"));
staffSchedule.Columns.Add("StaffId", Type.GetType("System.String"));
staffSchedule.Columns.Add("WorkingPlaceId", Type.GetType("System.String"));
staffSchedule.Columns.Add("WorkingHourId", Type.GetType("System.String"));
staffSchedule.Columns.Add("JobTypeId", Type.GetType("System.String"));
staffSchedule.Columns.Add("WorkingDate", Type.GetType("System.String"));
staffSchedule.Columns.Add("MonthYear", Type.GetType("System.String"));
staffSchedule.Columns.Add("Comment", Type.GetType("System.String"));
staffSchedule.Columns.Add("Created", Type.GetType("System.String"));
staffSchedule.Columns.Add("CreatedBy", Type.GetType("System.String"));
staffSchedule.Columns.Add("Modified", Type.GetType("System.String"));
staffSchedule.Columns.Add("ModifiedBy", Type.GetType("System.String"));
staffSchedule.Columns.Add("DelFlag", Type.GetType("System.String"));
if (dt.Rows.Count > 0)
{
for (int i = 1; i < dt.Rows.Count; i++)
{
string staffId = Func.ParseString(dt.Rows[i][1]);
string[] dayOfMonth = new string[31];
for (int j = 0; j < 31; j++)
{
dayOfMonth[j] = Func.ParseString(dt.Rows[i][j + 3]);
if (!String.IsNullOrEmpty(staffId) && !String.IsNullOrEmpty(dayOfMonth[j]))
{
DataRow newRow = staffSchedule.NewRow();
newRow["BuildingId"] = Func.ParseString(Session["__BUILDINGID__"]);
newRow["StaffId"] = staffId;
newRow["WorkingPlaceId"] = "";
newRow["WorkingHourId"] = dayOfMonth[j];
newRow["JobTypeId"] = hidJobType.Value;
newRow["WorkingDate"] = "" + drpYear.SelectedValue + drpMonth.SelectedValue + Func.ParseString((j + 1)).PadLeft(2, '0');
newRow["MonthYear"] = drpYear.SelectedValue + drpMonth.SelectedValue;
newRow["Comment"] = "";
newRow["Created"] = DateTime.Now.ToString("yyyyMMddHHmmss");
newRow["CreatedBy"] = Page.User.Identity.Name;
newRow["Modified"] = DateTime.Now.ToString("yyyyMMddHHmmss");
newRow["ModifiedBy"] = Page.User.Identity.Name;
newRow["DelFlag"] = "0";
staffSchedule.Rows.Add(newRow);
}
}
Console.Write("");
}
}
using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
{
copy.DestinationTableName = "dbo.BD_WorkingSheduleInfo";
copy.BatchSize = 3000;
copy.BulkCopyTimeout = 99999;
copy.ColumnMappings.Add(0, "BuildingId");
copy.ColumnMappings.Add(1, "StaffId");
copy.ColumnMappings.Add(2, "WorkingPlaceId");
copy.ColumnMappings.Add(3, "WorkingHourId");
copy.ColumnMappings.Add(4, "JobTypeId");
copy.ColumnMappings.Add(5, "WorkingDate");
copy.ColumnMappings.Add(6, "MonthYear");
copy.ColumnMappings.Add(7, "Comment");
copy.ColumnMappings.Add(8, "Created");
copy.ColumnMappings.Add(9, "CreatedBy");
copy.ColumnMappings.Add(10, "Modified");
copy.ColumnMappings.Add(11, "ModifiedBy");
copy.ColumnMappings.Add(12, "DelFlag");
copy.WriteToServer(staffSchedule);
}
//Response.Redirect("ListOtherFeeImport.aspx", false);
ShowData();
}
catch (Exception ex)
{
mvMessage.AddError("Lỗi phát sinh: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
}
示例9: SplitCsvLine
private string[] SplitCsvLine(string line)
{
CsvReader csv = new CsvReader(new StringReader(line),
false,
this.config.delimiterChar,
this.config.quoteChar,
this.config.escapeChar, // is '\0' when not checked in config dlg
this.config.commentChar,
false);
csv.ReadNextRecord();
int fieldCount = csv.FieldCount;
string[] fields = new string[fieldCount];
for (int i = 0; i < fieldCount; ++i)
{
fields[i] = csv[i];
}
csv.Dispose();
return fields;
}
示例10: TestCRUDOperations
private static void TestCRUDOperations(DynamoDBContext context)
{
List<MonthlyTotal> Import = new List<MonthlyTotal>();
string oneTimeFile = @"C: \Users\wildbillcat\Downloads\unknown_20160206082017.csv";
int i = 0;
using (CsvReader csv = new CsvReader(System.IO.File.OpenText(oneTimeFile)))
{
CsvReader Header = new CsvReader(System.IO.File.OpenText(oneTimeFile));
Header.Read();
string parsedate = Header.FieldHeaders[2].Substring(21, 10);
Header.Dispose();
DateTime ImportDate = Convert.ToDateTime(parsedate);
while (csv.Read())
{
//MonthlyTotal SKUDocument = context.Load<MonthlyTotal>(SKUNumber, ImportDate, new DynamoDBOperationConfig { ConsistentRead = true });
//if(SKUDocument == null)
//{
// //SKU isnt in Datebase, will have to create it.
// SKUDocument = new MonthlyTotal()
// {
// SKUId = SKUNumber,
// Month = ImportDate,
// Total = csv.GetField<double>(2)
// };
//}
MonthlyTotal SKUDocument = new MonthlyTotal()
{
SKUId = csv.GetField<int>(0),
Month = ImportDate,
Total = csv.GetField<double>(2)
};
//context.Save(SKUDocument);
Import.Add(SKUDocument);
i++;
if(i > 1000)
{
i = 0;
Console.Write("SKU :");
Console.WriteLine(SKUDocument.SKUId);
}
}
}
var importBatch = context.CreateBatchWrite<MonthlyTotal>();
importBatch.AddPutItems(Import);
importBatch.Execute();
Console.WriteLine("Wrote to NoSQL DB");
Console.WriteLine();
}
示例11: btnUpload_Click
//.........这里部分代码省略.........
db = new SqlDatabase();
ds = new DataSet();
dsTmp = new DataSet();
string sqlGetArtist = "SELECT distinct Song.ArtistId, Album.AlbumId, Album.Title FROM Album INNER JOIN Song ON Album.AlbumId = Song.AlbumId WHERE (Album.Title = '" + albumTitle + "') OR (Album.TitleReadingFull = '" + albumTitleReadingFull + "')";
cm = db.CreateCommand(sqlGetArtist);
da = new SqlDataAdapter(cm);
da.Fill(dsTmp);
dtTmp = dsTmp.Tables[0];
foreach (DataRow rowTmp in dtTmp.Rows)
{
string artistIdTmp = rowTmp["ArtistId"].ToString().ToUpper();
string albumIdTmp = rowTmp["AlbumId"].ToString().ToUpper();
if (artistId.Equals(artistIdTmp))
{
albumId = albumIdTmp;
}
}
if ("".Equals(albumId) || albumId == null)
{
if ("".Equals(autoKeyAlbum) || autoKeyAlbum == null)
{
albumId = CreateKey(albumData, albumData.ObjectType.Prefix + "0");
}
else
{
string prefix = albumData.ObjectType.Prefix;
int length = albumData.KeyAttributeData.MaxLength;
string tmp = autoKeyAlbum.Replace(prefix, "");
int i = Func.ParseInt(tmp) + 1;
albumId = prefix + Func.ParseString(i).PadLeft(length - prefix.Length, '0');
}
autoKeyAlbum = albumId;
}
}
}
albumKeyMap.Add(albumTitle + "_" + albumTitleReadingFull + "_" + albumCdId, albumId);
}
else
{
albumId = (string)albumKeyMap[albumTitle + "_" + albumTitleReadingFull + "_" + albumCdId];
}
}
string price = row["Price"].ToString();
string rate = hbunRitsu;
string priceNoTax = "";
string buyUnique = "";
string copyrightFeeUnique = "";
string KDDICommissionUnique = "";
string profitUnique = "";
if (!"".Equals(price) && !"".Equals(rate))
{
priceNoTax = Func.GetPriceNoTax(price);
buyUnique = Func.GetBuyUnique(priceNoTax, rate);
copyrightFeeUnique = Func.GetCopyrightFeeUnique(row["CopyrightContractId"].ToString(), priceNoTax, "1");
KDDICommissionUnique = Func.GetKDDICommissionUnique(priceNoTax);
profitUnique = Func.GetProfitUnique(priceNoTax, buyUnique, copyrightFeeUnique, KDDICommissionUnique);
}
string songId = row["SongId"].ToString();
updSql.AppendLine("Update SongImport set AlbumId = '" + albumId + "', hbunRitsu = '" + hbunRitsu + "', uta_rate = '" + uta_rate + "', video_rate = '" + video_rate + "' , PriceNoTax = '" + priceNoTax + "', BuyUnique = '" + buyUnique + "', CopyrightFeeUnique = '" + copyrightFeeUnique + "', KDDICommissionUnique = '" + KDDICommissionUnique + "', ProfitUnique = '" + profitUnique + "'where SongId = '" + songId + "' and SessionId = '" + Session.SessionID + "' and ImportType = '" + importType + "'");
ArrayList sqlAddSongMedia = GetSqlAddSongMediaKey(row,uta_rate,video_rate);
for (int i = 0; i < sqlAddSongMedia.Count; i++)
{
updSql.AppendLine(sqlAddSongMedia[i].ToString());
}
}
DbHelper.ExecuteNonQuery(updSql.ToString());
//うた既存 => status=1
DbHelper.ExecuteNonQuery("Update SongMediaTemp set Status = 1 where SessionId = '" + Session.SessionID + "' and SongMediaId in (Select SongMediaId from SongMedia where TypeId = '2') and ImportType = '" + importType + "'");
//ビデオ既存 => status=1
DbHelper.ExecuteNonQuery("Update SongMediaTemp set Status = 1 where SessionId = '" + Session.SessionID + "' and SongMediaId in (Select SongMediaId from SongMedia where TypeId = '3') and ImportType = '" + importType + "'");
db.Close();
///////////
Session["FolderPath"] = fileUpload.FileName;
Response.Redirect("NewListMasterImport.aspx", false);
}
catch (Exception ex)
{
mvImportMaster.AddError("エラーが発生しました: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
}
示例12: btnUpload_Click
//.........这里部分代码省略.........
string Creator = Page.User.Identity.Name;
sql = "Select * from SongMediaRbtTmp where SessionId = '" + Session.SessionID + "'";
SqlDatabase db = new SqlDatabase();
DataSet ds = new DataSet();
DataSet dsTmp = new DataSet();
SqlCommand cm = db.CreateCommand(sql);
SqlDataAdapter da = new SqlDataAdapter(cm);
da.Fill(ds);
dt = ds.Tables[0];
ArrayList insertList = new ArrayList();
//record
foreach (DataRow row in dt.Rows)
{
string contractorId = row["ContractorId"].ToString();
string rbt_rate = "";
if (!"".Equals(contractorId))
{
ContractorData data = new ContractorData();
ITransaction tran = factory.GetLoadObject(data, contractorId);
Execute(tran);
if (!HasError)
{
//編集の場合、DBに既存データを取得して設定する。
data = (ContractorData)tran.Result;
rbt_rate = data.rbt_rate;
}
}
string songId = row["SongId"].ToString();
string PRText = row["PRText"].ToString();
string Flag = row["Flag"].ToString();
string haishinDate = "";
string copyrightContractId = row["CopyrightContractId"].ToString();
string priceNoTax = "";
string buyUnique = "";
string copyrightFeeUnique = "";
string KDDICommissionUnique = "";
string profitUnique = "";
string title = "";
string isrcNo = "";
//string fileName = "";
string songMediaId = "";
string price = "";
price = row["Price"].ToString();
songMediaId = row["SongMediaId"].ToString();
title = row["Title"].ToString().Replace("'", "''");
isrcNo = row["IsrcNo"].ToString();
//fileName = row["UtaFileName" + Constants.SongMediaExt[i]].ToString();
haishinDate = row["HaishinDate"].ToString();
string rate = "".Equals(rbt_rate) ? "0" : rbt_rate;
if (!"".Equals(price) && !"".Equals(rbt_rate))
{
priceNoTax = Func.GetPriceNoTax(price);
buyUnique = Func.GetBuyUnique(priceNoTax, rbt_rate);
copyrightFeeUnique = Func.GetCopyrightFeeUnique(copyrightContractId, priceNoTax, "4");
KDDICommissionUnique = Func.GetKDDICommissionUnique(priceNoTax);
profitUnique = Func.GetProfitUnique(priceNoTax, buyUnique, copyrightFeeUnique, KDDICommissionUnique);
}
if ("".Equals(rbt_rate))
{
rbt_rate = "0";
}
if (!"".Equals(title) || !"".Equals(isrcNo))
{
insertList.Add("Insert into SongMedia (SongMediaId, SongId, Title, TypeId, ISRCNo, rate , Price,PRText,Flag, HaishinDate,PriceNoTax, BuyUnique, CopyrightFeeUnique, KDDICommissionUnique, ProfitUnique,DelFlag,Updated , Updator, Created, Creator) " +
"values('" + songMediaId + "', '" + songId + "','" + title + "','4', '" + isrcNo + "','" + rbt_rate + "','" + price + "','" + PRText + "','" + Flag + "','" + haishinDate + "', '" + priceNoTax + "','" + buyUnique + "','" + copyrightFeeUnique + "','" + KDDICommissionUnique + "','" + profitUnique + "', '0','" + Updated + "', '" + Updator + "', '" + Created + "', '" + Creator + "')");
}
}
for (int i = 0; i < insertList.Count; i++)
{
DbHelper.ExecuteNonQuery((string)insertList[i]);
}
db.Close();
///////////
DbHelper.ExecuteNonQuery("Delete from SongMediaRbtTmp where SessionId = '"+ Session.SessionID +"'");
Response.Redirect("ImportFinish.aspx", false);
}
catch (Exception ex)
{
mvImportMaster.AddError("エラーが発生しました: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
}
示例13: btnUpload_Click
//.........这里部分代码省略.........
dt.Rows[i]["ImportType"] = importType;
dt.Rows[i]["DelFlag"] = "0";
dt.Rows[i]["Updated"] = DateTime.Now.ToString("yyyyMMddHHmmss");
dt.Rows[i]["Updator"] = Page.User.Identity.Name;
dt.Rows[i]["Created"] = DateTime.Now.ToString("yyyyMMddHHmmss");
dt.Rows[i]["Creator"] = Page.User.Identity.Name;
}
using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
{
copy.DestinationTableName = "SongImport";
copy.BatchSize = 3000;
copy.BulkCopyTimeout = 99999;
for (int i = 0; i < Constants.ImportUtaDataHeader.Length; i++)
{
copy.ColumnMappings.Add(i, Constants.ImportUtaDataDbRef[i]);
}
copy.ColumnMappings.Add(dt.Columns.Count - 8, "SessionId");
copy.ColumnMappings.Add(dt.Columns.Count - 7, "ImportType");
copy.ColumnMappings.Add(dt.Columns.Count - 6, "Status");
copy.ColumnMappings.Add(dt.Columns.Count - 5, "DelFlag");
copy.ColumnMappings.Add(dt.Columns.Count - 4, "Updated");
copy.ColumnMappings.Add(dt.Columns.Count - 3, "Updator");
copy.ColumnMappings.Add(dt.Columns.Count - 2, "Created");
copy.ColumnMappings.Add(dt.Columns.Count - 1, "Creator");
copy.WriteToServer(dt);
}
}
//DbHelper.ExecuteNonQuery("Update SongImport set Status = 1 where SessionId = '" + Session.SessionID + "' and ImportType = '"+ importType +"' and SongId in (Select SongMediaId from SongMedia where TypeId = '1')");
//DbHelper.ExecuteNonQuery("Update SongImport set SongImport.CopyrightOrg = Song.CopyrightOrg From SongImport, Song Where SongImport.SongId = Song.SongId");
DbHelper.ExecuteNonQuery("Update SongImport set Status = 1, SongImport.CopyrightOrg = S.CopyrightOrg, SongImport.CopyrightContractId = S.CopyrightContractId , SongTitle = S.Title, SongTitleReading = S.TitleReading, ArtistId = S.ArtistId, " +
" GenreId = S.GenreId, AlbumId = S.AlbumId, LabelId=S.LabelId, ContractorId = S.ContractorId, IVT = S.IVT, IVTType = S.IVTType, "+
" JasracWorksCode = S.JasracWorksCode, IsrcNo=S.IsrcNo From SongImport, Song S where SessionId = '" + Session.SessionID + "' "+
" and SongImport.ImportType = '" + importType + "' and S.SongId = SongImport.SongId ");
sql = "Select * from SongImport where SessionId = '" + Session.SessionID + "' and ImportType = '" + importType + "'";
SqlDatabase db = new SqlDatabase();
DataSet ds = new DataSet();
DataSet dsTmp = new DataSet();
SqlCommand cm = db.CreateCommand(sql);
SqlDataAdapter da = new SqlDataAdapter(cm);
da.Fill(ds);
dt = ds.Tables[0];
ArrayList sqlUpdate = new ArrayList();
dt = ds.Tables[0];
foreach (DataRow row in dt.Rows)
{
string contractorId = row["ContractorId"].ToString();
string uta_rate = "";
if (!"".Equals(contractorId))
{
ContractorData data = new ContractorData();
ITransaction tran = factory.GetLoadObject(data, contractorId);
Execute(tran);
if (!HasError)
{
//編集の場合、DBに既存データを取得して設定する。
data = (ContractorData)tran.Result;
uta_rate = data.uta_rate;
}
}
ArrayList sqlAddSongMedia = GetSqlAddSongMediaKey(row,uta_rate);
for (int i = 0; i < sqlAddSongMedia.Count; i++)
{
sqlUpdate.Add(sqlAddSongMedia[i]);
}
}
for (int i = 0; i < sqlUpdate.Count; i++)
{
DbHelper.ExecuteNonQuery((string)sqlUpdate[i]);
}
//うた既存 => status=1
DbHelper.ExecuteNonQuery("Update SongMediaTemp set SongMediaTemp.Status = 1 From SongMediaTemp, SongMedia SM Where SongMediaTemp.SongMediaId = SM.SongMediaId and SM.TypeId = '2' and SessionId = '" + Session.SessionID + "' and ImportType = '" + importType + "'");
db.Close();
///////////
Session["FolderPath"] = fileUpload.FileName;
Response.Redirect("UtaUpdateListMasterImport.aspx", false);
}
catch (Exception ex)
{
mvImportMaster.AddError("エラーが発生しました: " + ex.Message);
}
finally
{
if (csvRead != null)
{
csvRead.Dispose();
}
}
示例14: ProcessRow
private void ProcessRow(bool onlyPostProcess)
{
if (!File.Exists(_fullPath)) return;
using (var csv = new CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
{
csv.Configuration.Delimiter = Separators.GetCharSeparator();
csv.Configuration.HasHeaderRecord = _hasHeadrs;
while (csv.Read())
{
if (!CommonStatistic.IsRun)
{
csv.Dispose();
FileHelpers.DeleteFile(_fullPath);
return;
}
try
{
var productInStrings = PrepareRow(csv);
if (productInStrings == null) continue;
if (!onlyPostProcess)
ImportProduct.UpdateInsertProduct(productInStrings);
else
ImportProduct.PostProcess(productInStrings);
}
catch (Exception ex)
{
MsgErr(ex.Message + " at csv");
Debug.LogError(ex);
}
}
}
}
示例15: ProcessDataFile
//.........这里部分代码省略.........
vm.UpdatedDate = DateTime.Now;
cvm.CopyPropertiesFrom(vm);
var constituent = Mapper.Map<ConstituentViewModel, Constituent>(cvm);
db.Constituents.AddOrUpdate(constituent);
}
status.ConstituentsUpdated = db.SaveChanges();
// Add new Constituents missing from database
// Bulk copy new Constituent records
if (newConstituentList.Count > 0)
{
foreach (var vm in newConstituentList)
{
vm.CreatedBy = "system";
vm.UpdatedBy = "system";
vm.CreatedDate = DateTime.Now;
vm.UpdatedDate = DateTime.Now;
}
var missingTbl = newConstituentList.ToDataTable();
using (var sbc = new SqlBulkCopy(db.Database.Connection.ConnectionString))
{
sbc.DestinationTableName = db.GetTableName<Constituent>();
sbc.BatchSize = 10000;
sbc.BulkCopyTimeout = 0;
foreach (var col in missingTbl.Columns)
{
sbc.ColumnMappings.Add(col.ToString(), col.ToString());
}
try
{
await sbc.WriteToServerAsync(missingTbl);
status.ConstituentsCreated = sbc.RowsCopiedCount();
}
catch (Exception e)
{
status.Message = e.Message;
}
}
}
// Update constituents because of new bulk copy constituents
//TODO: Change Created and Updated user to logged in user
dbConstituents = db.Constituents.ProjectTo<ConstituentViewModel>().ToList();
// Build dictionary to map database key to csv records LookupId
var dic = new Dictionary<int, string>();
dbConstituents.ForEach(x => dic.Add(x.Id, x.LookupId));
// Update parent key for each tax record
//csvTaxRecords.ForEach(x => x.ConstituentId = dic.FirstOrDefault(d => d.Value == x.LookupId).Key);
csvTaxRecords.ForEach((s) =>
{
s.ConstituentId = dic.FirstOrDefault(d => d.Value == s.LookupId).Key;
s.CreatedBy = "system";
s.UpdatedBy = "system";
s.CreatedDate = DateTime.Now;
s.UpdatedDate = DateTime.Now;
});
// Bulk insert new tax records
using (var sbc = new SqlBulkCopy(db.Database.Connection.ConnectionString))
{
sbc.DestinationTableName = db.GetTableName<TaxItem>();
sbc.BatchSize = 10000;
sbc.BulkCopyTimeout = 0;
var dt = Mapper.Map<List<CsvTaxRecordViewModel>, List<TaxItem>>(csvTaxRecords).ToDataTable();
foreach (var col in dt.Columns)
{
sbc.ColumnMappings.Add(col.ToString(), col.ToString());
}
try
{
await sbc.WriteToServerAsync(dt);
status.RecordsLoaded = sbc.RowsCopiedCount();
}
catch (Exception ex)
{
status.Message = ex.Message;
}
}
status.RecordsInFile = csvTaxRecords.Count;
status.Success = true;
if (csvTaxRecords.Count != csv.Row - 2)
{
status.Message = "Error in file header mappings. Check file headers and try again.";
status.Success = false;
}
else
{
status.Success = true;
status.Message = "Successfully loaded tax records.";
}
status.TotalTime = DateTime.Now.Subtract(startTime).ToString(@"hh\:mm\:ss");
csv.Dispose();
return status;
}