本文整理汇总了C#中SES.Service.OrmliteConnection.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# OrmliteConnection.SingleOrDefault方法的具体用法?C# OrmliteConnection.SingleOrDefault怎么用?C# OrmliteConnection.SingleOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SES.Service.OrmliteConnection
的用法示例。
在下文中一共展示了OrmliteConnection.SingleOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(DC_LG_Discountion item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.DiscountionID) &&
!string.IsNullOrEmpty(item.DiscountionName)
)
{
var isExist = db.SingleOrDefault<DC_LG_Discountion>("DiscountionID={0}", item.DiscountionID);
item.FromDate = item.FromDate != null ? item.FromDate : DateTime.Now;
item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
if (item.FromDate > item.EndDate)
{
return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.FromDate });
}
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.DiscountionType = !string.IsNullOrEmpty(item.DiscountionType) ? item.DiscountionType : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã chương trình chiết khấu đã tồn tại" });
item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
item.CreatedAt = DateTime.Now;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
db.Insert(item);
return Json(new { success = true, DiscountionID = item.DiscountionID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
item.CreatedAt = item.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
}
}
catch (Exception e)
{
log.Error("DeliveryDiscountion - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例2: Create
//
// GET: /DeliveryManage/Create
public ActionResult Create(DC_LG_Transporter item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (//!string.IsNullOrEmpty(item.TransporterID) &&
!string.IsNullOrEmpty(item.TransporterName)
)
{
int n;
var isExist = db.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}",item.TransporterID);
item.Weight = int.TryParse(item.Weight.ToString(),out n) ? item.Weight : 0;
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if(isExist != null)
return Json(new { success = false, message = "Mã đơn vị vận chuyển đã tồn tại!" });
item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
item.CreatedAt = DateTime.Now;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Insert(item);
return Json(new { success = true, TransporterID = item.TransporterID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
item.CreatedAt = item.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập giá trị" });
}
}
catch (Exception e)
{
log.Error("Transporter - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例3: GetDiscountionCode
public ActionResult GetDiscountionCode(string DiscountionID)
{
IDbConnection dbConn = new OrmliteConnection().openConn();
try
{
var data = dbConn.SingleOrDefault<DC_LG_Discountion>("DiscountionID={0}", DiscountionID);
return Json(new { success = true, data = data });
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
finally { dbConn.Close(); }
}
示例4: UpdateDetail
public ActionResult UpdateDetail([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<SODetail> list)
{
var dbConn = new OrmliteConnection().openConn();
if (userAsset.ContainsKey("Update") && userAsset["Update"])
{
if (list != null)//&& ModelState.IsValid)
{
foreach (var item in list)
{
if (dbConn.Select<SOHeader>(s => s.SONumber == item.SONumber && s.Status != "Mới").Count() > 0)
{
return Json(new { success = false, message = "Đơn hàng đã xác nhận nên không được xóa." });
}
else if (item.Qty > 0)
{
var isExist = dbConn.SingleOrDefault<SODetail>("SONumber = {0} AND ItemCode = {1}", item.SONumber, item.ItemCode);
if (isExist != null)
{
try
{
isExist.Qty = item.Qty;
isExist.TotalAmt = item.Qty * item.Price;
isExist.UpdatedAt = DateTime.Now;
isExist.UpdatedBy = currentUser.UserID;
dbConn.Update<SODetail>(isExist);
//dbConn.Update<SODetail>(set: "Qty = '" + item.Qty + "', TotalAmt = '" + item.Qty * item.Price + "',UpdatedAt = '" + DateTime.Now + "', UpdatedBy ='" + currentUser.UserID + "'", where: "SONumber = '" + item.SONumber + "' AND ItemCode ='" + item.ItemCode + "'");
dbConn.Update<SOHeader>(set: "UpdatedBy='" + currentUser.UserID + "',TotalQty ='" + dbConn.Select<SODetail>(s => s.SONumber == item.SONumber).Sum(s => s.Qty) + "', TotalAmt = '" + dbConn.Select<SODetail>(s => s.SONumber == item.SONumber).Sum(s => s.TotalAmt) + "'", where: "SONumber ='" + item.SONumber + "'");
var success = dbConn.Execute(@"UPDATE SOHeader Set UpdatedAt = @UpdatedAt WHERE SONumber = '" + item.SONumber + "'",
new
{
UpdatedAt = DateTime.Now,
}) == 1;
}
catch (Exception ex)
{
ModelState.AddModelError("error", ex.Message);
return Json(list.ToDataSourceResult(request, ModelState));
}
}
}
else
{
ModelState.AddModelError("error", "Đơn hàng được tạo khi số lượng > 0");
return Json(list.ToDataSourceResult(request, ModelState));
}
}
}
dbConn.Close();
return Json(new { sussess = true });
}
else
{
dbConn.Close();
ModelState.AddModelError("error", "Bạn không có quyền cập nhật.");
return Json(list.ToDataSourceResult(request, ModelState));
}
}
示例5: ImportData
//.........这里部分代码省略.........
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() : "";
string Size = oSheet.Cells[i, 3].Value != null ? oSheet.Cells[i, 3].Value.ToString() : "";
string Priece = oSheet.Cells[i, 4].Value != null ? oSheet.Cells[i, 4].Value.ToString() : "0";
string Type = oSheet.Cells[i, 5].Value != null ? oSheet.Cells[i, 5].Value.ToString() : "";
string Unit = oSheet.Cells[i, 6].Value != null ? oSheet.Cells[i, 6].Value.ToString() : "";
string[] UnitID = Unit.Split('/');
string WH = oSheet.Cells[i, 7].Value != null ? oSheet.Cells[i, 7].Value.ToString() : "";
string[] WHID = WH.Split('/');
string WHL = oSheet.Cells[i, 8].Value != null ? oSheet.Cells[i, 8].Value.ToString() : "";
string[] WHLID = WHL.Split('/');
string Templete = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "";
//string Status = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "Ngưng hoạt động";
string Status = "false";
if (oSheet.Cells[i, 10].Value != null)
{
if (oSheet.Cells[i, 10].Value.ToString() == "Đang hoạt động")
{
Status = "true";
}
}
try
{
if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Size) || string.IsNullOrEmpty(Priece))
{
ws.Cells["A" + 2].Value = Name;
ws.Cells[rownumber, 14].Value = "Vui lòng nhập (*).";
rownumber++;
}
else
{
var checkexists = dbConn.SingleOrDefault<Products>("SELECT * FROM Products WHERE Code = '" + ID + "'");
if (checkexists != null)
{
checkexists.Code = ID;
checkexists.Name = Name;
checkexists.Size = Name;
checkexists.Price = int.Parse(Priece)/1.1;
checkexists.VATPrice = int.Parse(Priece);
checkexists.Type = Type;
checkexists.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
checkexists.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
checkexists.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
checkexists.ShapeTemplate = Templete;
checkexists.Status = Boolean.Parse(Status);
checkexists.UpdatedAt = DateTime.Now;
checkexists.UpdatedBy = currentUser.UserID;
dbConn.Update<Products>(checkexists);
}
else
{
string id = "";
var checkID = dbConn.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products ORDER BY Id DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.Code.Substring(2, checkID.Code.Length - 2)) + 1;
id = "AD" + String.Format("{0:00000000}", nextNo);
}
else
{
id = "AD00000001";
}
var item = new Products();
item.Code = ID;
示例6: GetDeliveryByCode
public ActionResult GetDeliveryByCode(string TransporterID)
{
IDbConnection dbConn = new OrmliteConnection().openConn();
try
{
var data = dbConn.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}", TransporterID);
return Json(new { success = true, data = data });
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
finally { dbConn.Close(); }
}
示例7: ImportWH
public ActionResult ImportWH()
{
IDbConnection dbConn = new OrmliteConnection().openConn();
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")
{
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() : "";
string Address = oSheet.Cells[i, 3].Value != null ? oSheet.Cells[i, 3].Value.ToString() : "";
string Keeper = oSheet.Cells[i, 4].Value != null ? oSheet.Cells[i, 4].Value.ToString() : "";
string Note = oSheet.Cells[i, 5].Value != null ? oSheet.Cells[i, 5].Value.ToString() : "";
string Status = "false";
if (oSheet.Cells[i, 6].Value != null)
{
if (oSheet.Cells[i, 6].Value.ToString() == "Đang hoạt động")
{
Status = "true";
}
}
try
{
if (string.IsNullOrEmpty(Name))
{
ws.Cells["A" + 2].Value = Name;
ws.Cells[rownumber, 14].Value = "Vui lòng nhập (*).";
rownumber++;
}
else
{
var checkexists = dbConn.SingleOrDefault<WareHouse>("SELECT * FROM DC_AD_WH WHERE WHID = '" + ID + "'");
if (checkexists != null)
{
checkexists.WHID = ID;
checkexists.WHName = Name;
checkexists.Note = Note;
checkexists.Address = !string.IsNullOrEmpty(Address) ? Address : "";
checkexists.WHKeeper = Keeper;
checkexists.Status = Boolean.Parse(Status);
checkexists.UpdatedAt = DateTime.Now;
checkexists.UpdatedBy = currentUser.UserID;
dbConn.Update<WareHouse>(checkexists);
}
else
{
string id = "";
var checkID = dbConn.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.DC_AD_WH ORDER BY Id DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.WHID.Substring(2, checkID.WHID.Length - 2)) + 1;
id = "WH" + String.Format("{0:00000000}", nextNo);
}
else
{
id = "WH00000001";
}
var item = new WareHouse();
item.WHID = id;
item.WHName = !string.IsNullOrEmpty(Name) ? Name.Trim() : "";
item.Note = !string.IsNullOrEmpty(Note) ? Note.Trim() : "";
item.Address = !string.IsNullOrEmpty(Address) ? Address : "";
item.WHKeeper = Keeper;
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.UpdatedBy = "";
item.Status = Boolean.Parse(Status);
dbConn.Insert<WareHouse>(item);
//.........这里部分代码省略.........
示例8: Create
public ActionResult Create(DC_Formula item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.FormulaName) && !string.IsNullOrEmpty(item.Formula))
{
var isExist = db.SingleOrDefault<DC_Formula>("FormulaID={0}", item.FormulaID);
item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã công thức đã tồn tại!" });
string id = "";
var checkID = db.SingleOrDefault<DC_Formula>("SELECT FormulaID,ID FROM DC_Formula ORDER BY ID DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.FormulaID.Substring(2, checkID.FormulaID.Length - 2)) + 1;
id = "FM" + String.Format("{0:000000}", nextNo);
}
else
{
id = "FM000001";
}
item.FormulaID = id;
item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.UpdatedBy = "";
db.Insert(item);
return Json(new { success = true, FormulaID = item.FormulaID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";
item.Status = item.Status;
item.CreatedAt = item.CreatedAt;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Now;
item.UpdatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
}
}
catch (Exception e)
{
log.Error("Formula" + item.FormulaID + " - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例9: Create
public ActionResult Create(Company item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.CompanyID) &&
!string.IsNullOrEmpty(item.CompanyName)
)
{
var isExist = db.SingleOrDefault<Company>("CompanyID={0}", item.CompanyID);
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã công ty đã tồn tại" });
item.CompanyName = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
item.ShortName = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
item.EnglishName = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
item.SubDomain = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
item.MobilePhone = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
item.Website = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
item.Descr = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
item.CreatedAt = DateTime.Now;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Insert<Company>(item);
return Json(new { success = true, CompanyID = item.CompanyID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.CompanyName = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
item.ShortName = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
item.EnglishName = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
item.SubDomain = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
item.MobilePhone = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
item.Website = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
item.Descr = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
item.CreatedBy = isExist.CreatedBy;
item.CreatedAt = isExist.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.UpdatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
}
}
catch (Exception e)
{
log.Error("Company - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例10: Initialize
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
if (this.User.Identity.IsAuthenticated)
{
IDbConnection dbConn = new OrmliteConnection().openConn();
lstAssetDefault = InitAssetDefault();
currentUser = dbConn.GetByIdOrDefault<Auth_User>(User.Identity.Name);
currentUserRole = dbConn.SqlList<Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name });
string controllerName = this.GetType().Name;
controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller"));
var lstAsset = new List<Auth_Action>();
// Get MenuID from controller name
string menuID = dbConn.SingleOrDefault<Auth_Menu>("ControllerName = {0}", controllerName).MenuID;
foreach (var g in currentUserRole)
{
// Get List Asset
var temp = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID);
if (temp.Count > 0)
lstAsset.AddRange(temp);
}
if(lstAsset.Count == 0)
{
var item = new Auth_Action();
item.MenuID = menuID;
item.Note = "";
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = "System";
if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"])
{
item.RoleID = 1;
item.IsAllowed = true;
foreach(var asset in lstAssetDefault)
{
item.Action = asset;
dbConn.Insert<Auth_Action>(item);
}
}
else
{
item.RoleID = currentUserRole.FirstOrDefault().RoleID;
item.IsAllowed = false;
foreach (var asset in lstAssetDefault)
{
item.Action = asset;
dbConn.Insert<Auth_Action>(item);
}
}
}
else
{
foreach (var g in currentUserRole)
{
// Asset
var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList();
foreach(var item in lst)
{
if (!userAsset.ContainsKey(item.Action))
userAsset.Add(item.Action, item.IsAllowed);
else if(item.IsAllowed)
{
userAsset.Remove(item.Action);
userAsset.Add(item.Action, item.IsAllowed);
}
}
}
}
// Get Asset View Menu
foreach (var g in currentUserRole)
{
var lstView = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View");
//var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID);
foreach (var i in lstView)
{
if (!dictView.ContainsKey("menu_" + i.MenuID))
{
if(i.IsAllowed)
{
dictView.Add("menu_" + i.MenuID, true);
}
}
}
}
ViewData["menuView"] = dictView;
dbConn.Close();
}
}
示例11: Create
public ActionResult Create(DC_AD_Printer item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.PrinterName)
)
{
var isExist = db.SingleOrDefault<DC_AD_Printer>("PrinterID={0}", item.PrinterID);
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.DfltAddress = !string.IsNullOrEmpty(item.DfltAddress) ? item.DfltAddress : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.WHAddress = !string.IsNullOrEmpty(item.WHAddress) ? item.WHAddress : "";
item.ShippingAddress = !string.IsNullOrEmpty(item.ShippingAddress) ? item.ShippingAddress : "";
item.ContactPhone = !string.IsNullOrEmpty(item.ContactPhone) ? item.ContactPhone : "";
item.ContactName = !string.IsNullOrEmpty(item.ContactName) ? item.ContactName : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã máy in đã tồn tại" });
string id = "";
var checkID = db.SingleOrDefault<DC_AD_Printer>("SELECT PrinterID, Id FROM dbo.DC_AD_Printer ORDER BY Id DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.PrinterID.Substring(2, checkID.PrinterID.Length - 2)) + 1;
id = "PR" + String.Format("{0:00000000}", nextNo);
}
else
{
id = "PR00000001";
}
item.PrinterID = id;
item.PrinterName = !string.IsNullOrEmpty(item.PrinterName) ? item.PrinterName : "";
item.CreatedAt = DateTime.Now;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Insert(item);
return Json(new { success = true, PrinterID = item.PrinterID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.PrinterName = !string.IsNullOrEmpty(item.PrinterName) ? item.PrinterName : "";
item.CreatedAt = item.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
}
}
catch (Exception e)
{
log.Error("Printer - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例12: GetPrinterbycode
public ActionResult GetPrinterbycode(string PrinterID)
{
IDbConnection dbConn = new OrmliteConnection().openConn();
try
{
var data = dbConn.SingleOrDefault<DC_AD_Printer>("PrinterID={0}", PrinterID);
return Json(new { success = true, data = data });
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
finally { dbConn.Close(); }
}
示例13: Create
public ActionResult Create(Customer item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.CustomerName)
)
{
var isExist = db.SingleOrDefault<Customer>("CustomerID={0}", item.CustomerID);
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
item.Shoptype = !string.IsNullOrEmpty(item.Shoptype) ? item.Shoptype : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
item.Agent = !string.IsNullOrEmpty(item.Agent) ? item.Agent : "";
item.Birthday = !string.IsNullOrEmpty(item.Birthday) ? item.Birthday : "";
item.Gender = !string.IsNullOrEmpty(item.Gender) ? item.Gender : "";
item.LevelHirerachy1 = !string.IsNullOrEmpty(item.LevelHirerachy1) ? item.LevelHirerachy1 : "";
item.LevelHirerachy2 = !string.IsNullOrEmpty(item.LevelHirerachy2) ? item.LevelHirerachy2 : "";
item.LevelHirerachy3 = !string.IsNullOrEmpty(item.LevelHirerachy3) ? item.LevelHirerachy3 : "";
item.LevelHirerachy4 = !string.IsNullOrEmpty(item.LevelHirerachy4) ? item.LevelHirerachy4 : "";
item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc : "";
item.ProvinceID = !string.IsNullOrEmpty(item.ProvinceID) ? item.ProvinceID : "";
item.DistrictID = !string.IsNullOrEmpty(item.DistrictID) ? item.DistrictID : "";
if (item.ProvinceID=="")
item.DistrictID = "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã khách hàng đã tồn tại" });
string id = "";
var checkID = db.SingleOrDefault<Customer>("SELECT CustomerID, Id FROM dbo.Customer ORDER BY Id DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.CustomerID.Substring(2, checkID.CustomerID.Length - 2)) + 1;
id = "C" + String.Format("{0:00000000}", nextNo);
}
else
{
id = "C00000001";
}
item.CustomerID = id;
item.CustomerName = !string.IsNullOrEmpty(item.CustomerName) ? item.CustomerName : "";
item.CreatedAt = DateTime.Now;
item.UpdatedBy = "";
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.CreatedBy = currentUser.UserID;
db.Insert(item);
return Json(new { success = true, CustomerID = item.CustomerID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.CustomerName = !string.IsNullOrEmpty(item.CustomerName) ? item.CustomerName : "";
item.CreatedAt = item.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = isExist.CreatedBy;
item.UpdatedBy = currentUser.UserID;
db.Update(item);
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
}
}
catch (Exception e)
{
log.Error("Customerion - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例14: PickingOut
public ActionResult PickingOut(string data, string WHID, string WHLID)
{
var dbConn = new OrmliteConnection().openConn();
try
{
string[] separators = { "@@" };
var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
string TransactionID = "";
string datetimeSO = DateTime.Now.ToString("yyMMdd");
var existSO = dbConn.SingleOrDefault<DC_AD_Transaction>("SELECT id, TransactionID FROM DC_AD_Transaction ORDER BY Id DESC");
var detail = new DC_AD_Transaction();
if (existSO != null)
{
var nextNo = Int32.Parse(existSO.TransactionID.Substring(8, 5)) + 1;
TransactionID = "TS" + datetimeSO + String.Format("{0:00000}", nextNo);
}
else
{
TransactionID = "TS" + datetimeSO + "00001";
}
foreach (var item in listdata)
{
if (dbConn.Select<DC_AD_Picking_Header>(s => s.Status != "Mới" && s.PickingNumber == item).Count() > 0)
{
return Json(new { success = false, message = item + " đã được nhập kho rồi." });
}
foreach (var po in dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item).ToList())
{
detail.TransactionID = TransactionID;
detail.TransactionType = "Out";
detail.TransactionDate = DateTime.Now;
detail.RefID = item;
detail.ItemCode = !string.IsNullOrEmpty(po.ItemCode) ? po.ItemCode : "";
detail.ItemName = !string.IsNullOrEmpty(po.ItemName) ? po.ItemName : "";
detail.UnitID = !string.IsNullOrEmpty(po.UnitID) ? po.UnitID : "";
detail.UnitName = !string.IsNullOrEmpty(po.UnitName) ? po.UnitName : "";
detail.Qty = po.Qty != null ? po.Qty : 0;
detail.Price = po.Price != null ? po.Price : 0;
detail.TotalAmt = po.TotalAmt != null ? po.TotalAmt : 0;
detail.WHID = !string.IsNullOrEmpty(WHID) ? WHID : "";
detail.WHLID = !string.IsNullOrEmpty(WHLID) ? WHLID : "";
detail.Note = !string.IsNullOrEmpty(po.Note) ? po.Note : "";
detail.Status = "Đang giao hàng";
detail.CreatedBy = currentUser.UserID;
detail.CreatedAt = DateTime.Now;
detail.UpdatedBy = "";
detail.UpdatedAt = DateTime.Parse("1900-01-01");
detail.PrinterID = dbConn.Select<DC_AD_Picking_Header>(s => s.PickingNumber == item).FirstOrDefault().PrinterID;
detail.PrinterName = dbConn.Select<DC_AD_Picking_Header>(s => s.PickingNumber == item).FirstOrDefault().PrinterName;
dbConn.Insert<DC_AD_Transaction>(detail);
dbConn.Update<SOHeader>(set: "Status = N'Đang giao hàng'", where: "SONumber = '" + po.SONumber + "'");
}
dbConn.Update<DC_AD_Picking_Header>(set: "Status = N'Đang giao hàng'", where: "PickingNumber = '" + item + "'");
}
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
return Json(new { success = true });
}
示例15: CreateHeader
public ActionResult CreateHeader(SOHeader item)
{
var dbConn = new OrmliteConnection().openConn();
if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
{
try
{
string SONumber = Request["SONumber"];
var header = new SOHeader();
var detail = new SODetail();
if (string.IsNullOrEmpty(SONumber))
{
string datetimeSO = DateTime.Now.ToString("yyMMdd");
var existSO = dbConn.SingleOrDefault<SOHeader>("SELECT id, SONumber FROM SOHeader ORDER BY Id DESC");
if (existSO != null)
{
var nextNo = Int32.Parse(existSO.SONumber.Substring(8, 5)) + 1;
SONumber = "SO" + datetimeSO + String.Format("{0:00000}", nextNo);
}
else
{
SONumber = "SO" + datetimeSO + "00001";
}
}
if (string.IsNullOrEmpty(Request["VendorID"]))
{
return Json(new { message = "Nhà cung cấp không tồn tai." });
}
if (!string.IsNullOrEmpty(Request["SODate"]))
{
DateTime fromDateValue;
if (!DateTime.TryParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
{
return Json(new { message = "Ngày tạo không đúng." });
}
}
header.SONumber = SONumber;
header.SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now;
header.VendorID = !string.IsNullOrEmpty(Request["VendorID"]) ? Request["VendorID"] : "";
header.Note = !string.IsNullOrEmpty(Request["Note"]) ? Request["Note"] : "";
header.TotalQty = 0;
header.WHID = "";
header.Status = "Mới";
header.WHLID = "";
header.TotalAmt = 0;
header.CreatedBy = currentUser.UserID;
header.CreatedAt = DateTime.Now;
header.UpdatedBy = "";
header.UpdatedAt = DateTime.Now;
//header.UpdatedAt = DateTime.Parse("1900-01-01");
dbConn.Insert<SOHeader>(header);
dbConn.Close();
return Json(new { success = true, SONumber = SONumber });
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
}
else
{
dbConn.Close();
return Json(new { success = false, message = "Không có quyền tạo." });
}
}