本文整理汇总了C#中SES.Service.OrmliteConnection.ExecuteSql方法的典型用法代码示例。如果您正苦于以下问题:C# OrmliteConnection.ExecuteSql方法的具体用法?C# OrmliteConnection.ExecuteSql怎么用?C# OrmliteConnection.ExecuteSql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SES.Service.OrmliteConnection
的用法示例。
在下文中一共展示了OrmliteConnection.ExecuteSql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(FormCollection form)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(form["RoleName"]))
{
var item = new Auth_Role();
item.RoleName = form["RoleName"];
item.IsActive = form["IsActive"] != null ? Convert.ToBoolean(form["IsActive"]) : false;
item.Note = !string.IsNullOrEmpty(form["Note"]) ? form["Note"] : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
string.IsNullOrEmpty(form["RoleID"])) // Tạo mới
{
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_Role>(item);
long lastID = db.GetLastInsertId();
if (lastID > 0)
{
// Thêm Role vào Auth_Action
db.ExecuteSql("EXEC p_Auth_Role_GenerateAction_By_RoleID " + lastID + "," + currentUser.UserID);
}
return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
}
else if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
Convert.ToInt32(form["RoleID"]) > 0 &&
Convert.ToInt32(form["IsCopy"]) == 1) // Sao chép
{
item.RoleID = Convert.ToInt32(form["RoleID"]);
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_Role>(item);
long lastID = db.GetLastInsertId();
if (lastID > 0)
{
// Sao chép Action RoleID đã chọn vào RoleID vừa tạo
db.ExecuteSql("p_Auth_Role_CopyAction_By_RoleID " + item.RoleID + "," + lastID + "," + currentUser.UserID);
}
return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] &&
Convert.ToInt32(form["RoleID"]) > 0) // Cập nhật
{
item.RoleID = Convert.ToInt32(form["RoleID"]);
item.RowCreatedAt = DateTime.Parse(form["RowCreatedAt"]);
item.RowCreatedBy = form["RowCreatedBy"];
item.RowUpdatedAt = DateTime.Now;
item.RowUpdatedBy = currentUser.UserID;
if (item.RowCreatedBy != "system")
{
db.Update<Auth_Role>(item);
}
return Json(new { success = true, RoleID = item.RoleID });
}
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("HOAdminAuthRole - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例2: ResetPasswordUser
public ActionResult ResetPasswordUser(string userID)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(userID) && db.GetByIdOrDefault<Auth_User>(userID) != null)
{
string pass = SqlHelper.GetMd5Hash("123456");
db.ExecuteSql("UPDATE [Auth_User] SET Password = '"+ pass +"' WHERE [UserID] = '"+ userID +"'");
return Json(new { success = true });
}
return Json(new { success = false, message = "Dữ liệu trống." });
}
catch (Exception e)
{
log.Error("AD_User - ResetPasswordUser - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}