本文整理汇总了C#中SES.Service.OrmliteConnection.OpenTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# OrmliteConnection.OpenTransaction方法的具体用法?C# OrmliteConnection.OpenTransaction怎么用?C# OrmliteConnection.OpenTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SES.Service.OrmliteConnection
的用法示例。
在下文中一共展示了OrmliteConnection.OpenTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportData
//public FileResult Export([DataSourceRequest]DataSourceRequest request)
//{
// ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/DanhMucAnPham.xlsx")));
// ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
// if (userAsset["Export"])
// {
// string whereCondition = "";
// if (request.Filters.Count > 0)
// {
// whereCondition = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
// }
// IDbConnection db = new OrmliteConnection().openConn();
// var lstResult = db.Select<Products>(whereCondition).ToList();
// int rowNum = 2;
// foreach (var item in lstResult)
// {
// ws.Cells["A" + rowNum].Value = item.Code;
// ws.Cells["B" + rowNum].Value = item.Name;
// ws.Cells["C" + rowNum].Value = item.Size;
// ws.Cells["D" + rowNum].Value = item.VATPrice;
// ws.Cells["E" + rowNum].Value = item.Type;
// ws.Cells["F" + rowNum].Value = item.Unit;
// ws.Cells["G" + rowNum].Value = item.WHID;
// ws.Cells["H" + rowNum].Value = item.WHLID;
// ws.Cells["I" + rowNum].Value = item.ShapeTemplate;
// if (item.Status == true)
// {
// ws.Cells["J" + rowNum].Value = "Đang hoạt động";
// }
// else
// {
// ws.Cells["J" + rowNum].Value = "Ngưng hoạt động";
// }
// ws.Cells["K" + rowNum].Value = item.CreatedBy;
// ws.Cells["L" + rowNum].Value = item.CreatedAt;
// ws.Cells["M" + rowNum].Value = item.UpdatedBy;
// if (item.UpdatedAt != DateTime.Parse("1900-01-01"))
// {
// ws.Cells["N" + rowNum].Value = item.UpdatedAt;
// }
// else
// {
// ws.Cells["N" + rowNum].Value = "";
// }
// rowNum++;
// }
// db.Close();
// }
// else
// {
// ws.Cells["A2:E2"].Merge = true;
// ws.Cells["A2"].Value = "Bạn không có quyền";
// }
// MemoryStream output = new MemoryStream();
// pck.SaveAs(output);
// return File(output.ToArray(), //The binary data of the XLS file
// "application/vnd.ms-excel", //MIME type of Excel files
// "DanhMucAnPham_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"); //Suggested file name in the "Save as" dialog which will be displayed to the end user
//}
public ActionResult ImportData()
{
try
{
if (Request.Files["FileUpload"] != null && Request.Files["FileUpload"].ContentLength > 0)
{
string fileExtension =
System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName);
if (fileExtension == ".xlsx" || fileExtension == ".xls")
{
IDbConnection dbConn = new OrmliteConnection().openConn();
using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
{
string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
string fileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + Request.Files["FileUpload"].FileName);
string errorFileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName);
string linkerror = "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName;
if (System.IO.File.Exists(fileLocation))
System.IO.File.Delete(fileLocation);
Request.Files["FileUpload"].SaveAs(fileLocation);
var rownumber = 2;
var total = 0;
FileInfo fileInfo = new FileInfo(fileLocation);
var excelPkg = new ExcelPackage(fileInfo);
//FileInfo template = new FileInfo(Server.MapPath(errorFileLocation));
//template.CopyTo(errorFileLocation);
//FileInfo _fileInfo = new FileInfo(errorFileLocation);
//var _excelPkg = new ExcelPackage(_fileInfo);
ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets["Data"];
//ExcelWorksheet eSheet = _excelPkg.Workbook.Worksheets["Data"];
ExcelPackage pck = new ExcelPackage(new FileInfo(errorFileLocation));
ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
int totalRows = oSheet.Dimension.End.Row;
for (int i = 2; i <= totalRows; i++)
{
string ID = oSheet.Cells[i, 1].Value != null ? oSheet.Cells[i, 1].Value.ToString() : "";
string Name = oSheet.Cells[i, 2].Value != null ? oSheet.Cells[i, 2].Value.ToString() : "";
//.........这里部分代码省略.........