本文整理汇总了C#中SES.Service.OrmliteConnection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# OrmliteConnection.Insert方法的具体用法?C# OrmliteConnection.Insert怎么用?C# OrmliteConnection.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SES.Service.OrmliteConnection
的用法示例。
在下文中一共展示了OrmliteConnection.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUserToGroup
public ActionResult AddUserToGroup(string id, string data)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
// Delete All Group of User
if (string.IsNullOrEmpty(id))
{
return Json(new { success = false, message = "Chọn người dùng trước khi thêm nhóm."});
}
db.DeleteById<Auth_UserInRole>(id);
// Add User Group
if (!string.IsNullOrEmpty(data))
{
string[] arr = data.Split(',');
foreach (string item in arr)
{
var detail = new Auth_UserInRole();
detail.UserID = id;
detail.RoleID = int.Parse(item);
detail.RowCreatedAt = DateTime.Now;
detail.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_UserInRole>(detail);
}
}
return Json(new { success = true });
}
catch (Exception e) { return Json(new { success = false, message = e.Message }); }
finally { db.Close(); }
}
示例2: AddTranporterToContract
public ActionResult AddTranporterToContract(string id, string data)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == id);
if (!string.IsNullOrEmpty(data))
{
string[] arr = data.Split(',');
foreach (string item in arr)
{
var detail = new DC_LG_Contract_Transporter();
detail.ContractID = id;
detail.TransporterID = int.Parse(item);
detail.Note = "";
detail.UpdatedAt = DateTime.Now;
detail.CreatedAt = DateTime.Now;
detail.CreatedBy = currentUser.UserID;
detail.UpdatedBy = currentUser.UserID;
db.Insert<DC_LG_Contract_Transporter>(detail);
}
}
return Json(new { success = true });
}
catch (Exception e) { return Json(new { success = false, message = e.Message }); }
finally { db.Close(); }
}
示例3: AddUserToGroup
public ActionResult AddUserToGroup(int id, string data)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
// Delete All User in Role
db.Delete<Auth_UserInRole>(p => p.RoleID == id);
// Add User Role
if (!string.IsNullOrEmpty(data))
{
string[] arr = data.Split(',');
foreach (string item in arr)
{
var detail = new Auth_UserInRole();
detail.UserID = item;
detail.RoleID = id;
detail.RowCreatedAt = DateTime.Now;
detail.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_UserInRole>(detail);
}
}
return Json(new { success = true });
}
catch (Exception e) { return Json(new { success = false, message = e.Message }); }
finally { db.Close(); }
}
示例4: 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(); }
}
示例5: 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(); }
}
示例6: Create
//
// GET: /DeliveryManage/Create
public ActionResult Create(DC_Reason item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.ReasonID) && item.ReasonType!="None")
{
var isExist = db.GetByIdOrDefault<DC_Reason>(item.ReasonID);
item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã lý do đã tồn tại!" });
item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
item.RowCreatedAt = DateTime.Now;
item.RowUpdatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<DC_Reason>(item);
return Json(new { success = true, ReasonID = item.ReasonID, RowCreatedBy = item.RowCreatedBy, RowCreatedAt = item.RowCreatedAt });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
item.RowCreatedAt = item.RowCreatedAt;
item.RowUpdatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Update<DC_Reason>(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("DeliveryUOMManage - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例7: 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." });
}
}
示例8: 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 });
}
示例9: Create
public ActionResult Create(SalesPerson item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.SalesPersonID) &&
!string.IsNullOrEmpty(item.SalesPersonName)
)
{
var isExist = db.SingleOrDefault<SalesPerson>("SalesPersonID={0}", item.SalesPersonID);
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
return Json(new { success = false, message = "Mã nhân viên đã tồn tại" });
item.SalesPersonName = !string.IsNullOrEmpty(item.SalesPersonName) ? item.SalesPersonName : "";
item.CompanyID = !string.IsNullOrEmpty(item.CompanyID) ? item.CompanyID : "";
//item.Gender = item.Gender;
item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
//item.DateOfBirth = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.CreatedAt = DateTime.Now;
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedBy = currentUser.UserID;
db.Insert<SalesPerson>(item);
return Json(new { success = true, SalesPersonID = item.SalesPersonID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.SalesPersonName = !string.IsNullOrEmpty(item.SalesPersonName) ? item.SalesPersonName : "";
item.CompanyID = !string.IsNullOrEmpty(item.CompanyID) ? item.CompanyID : "";
//item.Gender = item.Gender;
item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
//item.DateOfBirth = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.CreatedBy = isExist.CreatedBy;
item.CreatedAt = isExist.CreatedAt;
item.UpdatedAt = DateTime.Now;
item.UpdatedBy = currentUser.UserID;
db.Update<SalesPerson>(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("SalesPerson - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例10: Create
public ActionResult Create(Auth_User item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(item.UserID) &&
!string.IsNullOrEmpty(item.DisplayName) &&
!string.IsNullOrEmpty(item.FullName))
{
var isExist = db.GetByIdOrDefault<Auth_User>(item.UserID);
item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
{
if(isExist != null)
return Json(new { success = false, message = "Người dùng đã tồn tại." });
item.Password = SqlHelper.GetMd5Hash("123456");
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_User>(item);
return Json(new { success = true, UserID = item.UserID, RowCreatedAt = item.RowCreatedAt, RowCreatedBy = item.RowCreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.Password = isExist.Password;
item.RowUpdatedAt = DateTime.Now;
item.RowUpdatedBy = currentUser.UserID;
if (isExist.RowCreatedBy != "system")
{
db.Update<Auth_User>(item);
}
else
{
return Json(new { success = false, message = "Dữ liệu này không cho chỉnh sửa liên hệ admin để biết thêm chi tiết" });
}
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("AD_User - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例11: CreateUnit
public ActionResult CreateUnit(DC_AD_Unit item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
var isExist = db.SingleOrDefault<DC_AD_Unit>("SELECT UnitID, Id FROM dbo.DC_AD_Unit Where UnitID ='" + item.UnitID + "'");
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy ==null)
{
if (isExist != null)
{
return Json(new { success = false, message = "Đơn vị tính đã tồn tại." });
}
string id = "";
var checkID = db.SingleOrDefault<DC_AD_Unit>("SELECT UnitID, Id FROM dbo.DC_AD_Unit ORDER BY Id DESC");
if (checkID != null)
{
var nextNo = int.Parse(checkID.UnitID.Substring(3, checkID.UnitID.Length - 3)) + 1;
id = "UIT" + String.Format("{0:00000000}", nextNo);
}
else
{
id = "UIT00000001";
}
item.UnitID = id;
item.UnitName = !string.IsNullOrEmpty(item.UnitName) ? item.UnitName.Trim() : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "";
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.UpdatedBy = "";
item.Status = item.Status;
db.Insert<DC_AD_Unit>(item);
return Json(new { success = true, Code = item.UnitID, createdate = item.CreatedAt, createdby = item.CreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
var success = db.Execute(@"UPDATE DC_AD_Unit SET Status = @Status,
Note = @Note, UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, UnitName = @UnitName
WHERE UnitID = '" + item.UnitID + "'", new
{
Status = item.Status,
//WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "",
Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "",
UpdatedAt = DateTime.Now,
UpdatedBy = currentUser.UserID,
UnitName = !string.IsNullOrEmpty(item.UnitName) ? item.UnitName.Trim() : "",
}) == 1;
if (!success)
{
return Json(new { success = false, message = "Cập nhật không thành công." });
}
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
catch (Exception e)
{
log.Error(" ListPublication - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例12: CreateWH
public ActionResult CreateWH(WareHouse item)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
var isExist = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse Where WHID ='" + item.WHID + "'");
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
{
return Json(new { success = false, message = "Kho đã tồn tại." });
}
string id = "";
var checkID = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse 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";
}
item.WHID = id;
item.WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "";
item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : "";
item.WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : "";
item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "";
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.UpdatedBy = "";
item.Status = item.Status;
db.Insert<WareHouse>(item);
return Json(new { success = true, Code = item.WHID, createdate = item.CreatedAt, createdby = item.CreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
var success = db.Execute(@"UPDATE WareHouse SET Status = @Status, [email protected],[email protected],
Note = @Note, UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, [email protected]
WHERE WHID = '" + item.WHID + "'", new
{
Status = item.Status,
//WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "",
Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : "",
WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : "",
Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "",
UpdatedAt = DateTime.Now,
UpdatedBy = currentUser.UserID,
WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "",
}) == 1;
if (!success)
{
return Json(new { success = false, message = "Cập nhật không thành công." });
}
return Json(new { success = true });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
catch (Exception e)
{
log.Error(" WareHouse - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例13: CreateAction
public ActionResult CreateAction([DataSourceRequest]DataSourceRequest request, int roleid, string menuid, [Bind(Prefix = "models")]IEnumerable<Auth_Action> lst)
{
if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
{
IDbConnection db = new OrmliteConnection().openConn();
foreach (var item in lst)
{
if (item != null)
{
if (string.IsNullOrEmpty(item.Action))
{
ModelState.AddModelError("er", "Xin nhập quyền");
return Json(lst.ToDataSourceResult(request, ModelState));
}
var isExist = db.SingleOrDefault<Auth_Action>("RoleID = {0} AND MenuID = {1} AND Action = {2}", roleid, menuid, item.Action);
if (isExist != null)
{
ModelState.AddModelError("er", "Quyền đã tồn tại");
return Json(lst.ToDataSourceResult(request, ModelState));
}
try
{
item.RoleID = roleid;
item.MenuID = menuid;
item.Note = "";
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_Action>(item);
}
catch (Exception ex)
{
ModelState.AddModelError("er", ex.Message);
return Json(lst.ToDataSourceResult(request, ModelState));
}
}
}
db.Close();
return Json(lst.ToDataSourceResult(request));
}
else
{
ModelState.AddModelError("er", "Bạn không có quyền tạo mới");
return Json(lst.ToDataSourceResult(request, ModelState));
}
}
示例14: ImportData
//.........这里部分代码省略.........
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;
item.Name = Name;
item.Size = Name;
item.Price = int.Parse(Priece) / 1.1;
item.VATPrice = int.Parse(Priece);
item.Type = Type;
item.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
item.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
item.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
item.ShapeTemplate = Templete;
item.Status = Boolean.Parse(Status);
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
item.UpdatedAt = DateTime.Parse("1900-01-01");
item.UpdatedBy = "";
item.Status = Boolean.Parse(Status);
dbConn.Insert<Products>(item);
}
total++;
}
}
catch (Exception e)
{
return Json(new { success = false, message = e.Message });
}
}
return Json(new { success = true, total = total, totalError = rownumber - 2, link = linkerror });
}
}
else
{
return Json(new { success = false, message = "Không phải là file Excel. *.xlsx" });
}
}
else
{
return Json(new { success = false, message = "Không có file hoặc file không phải là Excel" });
}
}
catch (Exception ex)
{
return Json(new { success = false, message = ex.Message });
}
}
示例15: 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();
}
}