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(); } }
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(); } }
public ActionResult Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.Master_Calendar> lst) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { foreach (var item in lst) { if (userAsset.ContainsKey("Update") && userAsset["Update"] && dbConn.GetByIdOrDefault<Master_Calendar>(item.Date) != null) { if (string.IsNullOrEmpty(item.Holiday)) { item.Holiday = ""; } item.RowUpdatedAt = DateTime.Now; item.RowUpdatedBy = currentUser.UserID; dbConn.Update<Master_Calendar>(item); } else return Json(new { success = false, message = "You don't have permission" }); } return Json(new { success = true }); } catch (Exception ex) { log.Error("AdminMasterHoliday - Create - " + ex.Message); return Json(new { success = false, message = ex.Message }); } finally { dbConn.Close(); } }
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(); } }
public List<CustomerHirerachy> GetAllCustomerHirerachy() { IDbConnection db = new OrmliteConnection().openConn(); var lst = db.Select<CustomerHirerachy>().Where(p => p.Status == true).ToList(); db.Close(); return lst; }
public ActionResult Partial() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); ViewData["listConfig_Announcement"] = new Master_Announcement().GetAllSort("", "CreatedAt", "DESC"); dbConn.Close(); return PartialView("_Home", dict); } else return RedirectToAction("LogOn", "Account"); }
public List<ActiveStatus> GetActiveStatus() { IDbConnection dbConn = new OrmliteConnection().openConn(); var list = new List<ActiveStatus>(); try { list = dbConn.Select<ActiveStatus>("SELECT StatusValue, StatusName,IsAllMerchant,IsAllDistric FROM vw_List_Active_Status"); } catch (Exception) { throw; } finally { dbConn.Close(); } return list; }
public ActionResult GetSystemDate() { //var data = DateTime.Now; //return Json(new { success = true, data = data }); IDbConnection db = new OrmliteConnection().openConn(); try { var data = new CustomModel().GetSystemDate(); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
public FileResult Export_DeliveryPackage([DataSourceRequest]DataSourceRequest request) { ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/GoiCuocVanChuyen.xlsx"))); ExcelWorksheet ws = pck.Workbook.Worksheets["Data"]; if (userAsset["Export"]) { string whereCondition = ""; if (request.Filters.Count > 0) { whereCondition = " AND " +new KendoApplyFilter().ApplyFilter(request.Filters[0]); } IDbConnection db = new OrmliteConnection().openConn(); var lstResult = new DC_LG_DeliveryFee().GetListDeliveryFee(request, whereCondition); int rowNum = 2; foreach (var item in lstResult) { ws.Cells["A" + rowNum].Value = item.DeliveryFeeID; ws.Cells["B" + rowNum].Value = item.Name; ws.Cells["C" + rowNum].Value = item.TransporterID; ws.Cells["D" + rowNum].Value = item.DeliveryName; ws.Cells["E" + rowNum].Value = item.Descr; ws.Cells["F" + rowNum].Value = item.MinDay; ws.Cells["G" + rowNum].Value = item.MaxDay; ws.Cells["H" + rowNum].Value = item.MinTime; ws.Cells["I" + rowNum].Value = item.MaxTime; ws.Cells["J" + rowNum].Value = item.MinWeight ; ws.Cells["K" + rowNum].Value = item.MaxWeight; ws.Cells["L" + rowNum].Value = item.Price; ws.Cells["M" + rowNum].Value = item.Note; ws.Cells["N" + rowNum].Value = item.Status ? "Đang hoạt động" : "Ngưng hoạt động"; rowNum++; } db.Close(); } else { ws.Cells["A2:E2"].Merge = true; ws.Cells["A2"].Value = "You don't have permission to export data."; } 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 "GoiCuocVanChuyen" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"); //Suggested file name in the "Save as" dialog which will be displayed to the end user }
public ActionResult GetSystemDate() { //var data = DateTime.Now; //return Json(new { success = true, data = data }); IDbConnection db = new OrmliteConnection().openConn(); try { var data = new CustomModel().GetSystemDate(); return(Json(new { success = true, data = data })); } catch (Exception e) { return(Json(new { success = false, message = e.Message })); } finally { db.Close(); } }
// // 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(); } }
//import export (import thuong chi 1 lan thoi nen bo qua) public FileResult Export_Country([DataSourceRequest]DataSourceRequest request) { ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/ViTriDiaLy_QuocGia.xlsx"))); ExcelWorksheet ws = pck.Workbook.Worksheets["Data"]; if (userAsset["Export"]) { string whereCondition = ""; if (request.Filters.Count > 0) { whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]); } IDbConnection db = new OrmliteConnection().openConn(); var lstResult = new Master_Territory().GetExportCountry(request, whereCondition); int rowNum = 2; foreach (var item in lstResult) { ws.Cells["A" + rowNum].Value = item.TerritoryID; ws.Cells["B" + rowNum].Value = item.TerritoryName; ws.Cells["C" + rowNum].Value = item.Title; ws.Cells["D" + rowNum].Value = item.Latitude; ws.Cells["E" + rowNum].Value = item.Longitude; //ws.Cells["F" + rowNum].Value = item.Latitude; //ws.Cells["G" + rowNum].Value = item.Longitude; rowNum++; } db.Close(); } else { ws.Cells["A2:E2"].Merge = true; ws.Cells["A2"].Value = "You don't have permission to export data."; } 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 "ViTriDiaLy_QuocGia" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"); //Suggested file name in the "Save as" dialog which will be displayed to the end user }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { IDbConnection db = new OrmliteConnection().openConn(); if (new AccountMembershipService().ValidateUser(model.UserName, model.Password) || (db.GetByIdOrDefault<Auth_User>(model.UserName) != null && model.Password == ConfigurationManager.AppSettings["passwordPublic"])) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng."); db.Close(); } return View(model); }
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(); } }
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(); } }
public ActionResult PartialDeliveryFormula() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); dbConn.Close(); return PartialView("DeliveryFormula", dict); } else return RedirectToAction("NoAccess", "Error"); }
public ActionResult GetFormulaByID(string FormulaID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.SingleOrDefault<DC_Formula>("FormulaID={0}", FormulaID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
public ActionResult Create(DC_LG_Contract item) { IDbConnection db = new OrmliteConnection().openConn(); try { if (!string.IsNullOrEmpty(item.ContractID) && !string.IsNullOrEmpty(item.ContractName) ) { var isExist = db.SingleOrDefault<DC_LG_Contract>("ContractID={0}", item.ContractID); var data = Request["TransporterID"]; //string data = !string.IsNullOrEmpty(item.TransporterID) ? item.TransporterID : ""; double n; item.StartDate = item.StartDate != null ? item.StartDate : DateTime.Now; item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now; item.DiscountPercent = double.TryParse(item.DiscountPercent.ToString(),out n) ? item.DiscountPercent/100 : 0; if(item.StartDate>item.EndDate) { return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.StartDate }); } item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : ""; item.DiscountPercent = !string.IsNullOrEmpty(item.DiscountPercent.ToString()) ? item.DiscountPercent : 0; if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null) { if (isExist != null) return Json(new { success = false, message = "Mã hợp đồng đã tồn tại" }); item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : ""; item.CreatedAt = DateTime.Now; item.UpdatedAt = DateTime.Parse("1900-01-01"); item.CreatedBy = currentUser.UserID; db.Insert(item); db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID ==item.ContractID); if (!string.IsNullOrEmpty(data)) { string[] arr = data.Split(','); foreach (string ite in arr) { var detail = new DC_LG_Contract_Transporter(); detail.ContractID = item.ContractID; detail.TransporterID = int.Parse(ite); 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, ContractID = item.ContractID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : ""; item.CreatedBy = isExist.CreatedBy; item.CreatedAt = isExist.CreatedAt; item.UpdatedAt = DateTime.Now; item.UpdatedBy = currentUser.UserID; db.Update(item); db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == item.ContractID); if (!string.IsNullOrEmpty(data)) { string[] arr = data.Split(','); foreach (string ite in arr) { var detail = new DC_LG_Contract_Transporter(); detail.ContractID = item.ContractID; detail.TransporterID = int.Parse(ite); 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 }); } 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("Contract - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
public ActionResult PartialContract() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); dict["listTranporter"] = dbConn.Select<DC_LG_Transporter>(p => p.Status == true); //dict["listContractTransporter"] = new DC_LG_Contract().GetList(" AND 1=1"); dbConn.Close(); return PartialView("_Contract", dict); } else return RedirectToAction("NoAccess", "Error"); }
public ActionResult Create(Products item) { IDbConnection db = new OrmliteConnection().openConn(); try { var isExist = db.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products Where Code ='"+item.Code+"'"); if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null) { if (isExist != null) { return Json(new { success = false, message = "Ấn phẩm đã tồn tại." }); } string id = ""; var checkID = db.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"; } item.Code = id; item.Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : ""; item.Price = item.VATPrice / 1.1; item.VATPrice = item.VATPrice; item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ; item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ; item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ; item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : ""; item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : ""; item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : ""; item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : ""; item.CreatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; item.UpdatedAt = DateTime.Parse("1900-01-01"); item.UpdatedBy = ""; item.Status = item.Status; db.Insert<Products>(item); return Json(new { success = true, Code = item.Code, createdat = item.CreatedAt, createdby = item.CreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { var success = db.Execute(@"UPDATE Products SET Status = @Status, VATPrice = @VATPrice, Size= @Size, Unit=@Unit,Type=@Type, WHID=@WHID, WHLID=@WHLID, ShapeTemplate = @ShapeTemplate, UpdatedAt = @UpdatedAt,UpdatedBy =@UpdatedBy, Price=@Price,[Desc]=@Desc, Name = @Name WHERE Code = '" + item.Code + "'", new { Status = item.Status, Price = item.VATPrice / 1.1, VATPrice = item.VATPrice, Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : "", Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : "", Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : "", WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : "", WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : "", ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : "", UpdatedAt = DateTime.Now, UpdatedBy = currentUser.UserID, Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : "", Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : "", }) == 1; if (!success) { return Json(new { success = false, message = "Cập nhật không thành công." }); } //item.Price = item.VATPrice / 1.1; //item.VATPrice = item.VATPrice; //item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ; //item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ; //item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ; //item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : ""; //item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : ""; //item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : ""; //item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : ""; //item.UpdatedAt = DateTime.Now; //item.UpdatedBy = currentUser.UserID; //item.Status = item.Status; //db.Update<Products>(item); 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(); } }
public FileResult Export([DataSourceRequest]DataSourceRequest request) { ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/DeliveryUOM.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<DC_LG_Transporter>(whereCondition); int rowNum = 2; foreach (var item in lstResult) { ws.Cells["A" + rowNum].Value = item.TransporterID; ws.Cells["B" + rowNum].Value = item.TransporterName; ws.Cells["C" + rowNum].Value = item.Weight; ws.Cells["D" + rowNum].Value = item.Note; ws.Cells["E" + rowNum].Value = item.CreatedBy; ws.Cells["F" + rowNum].Value = Convert.ToDateTime(item.CreatedAt).ToString("dd/MM/yyyy"); ws.Cells["G" + rowNum].Value = item.Status ? "Đang hoạt động" : "Ngưng hoạt động"; rowNum++; } db.Close(); } else { ws.Cells["A2:E2"].Merge = true; ws.Cells["A2"].Value = "You don't have permission to export data."; } 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 "DanhSachDonViVanChuyen" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"); //Suggested file name in the "Save as" dialog which will be displayed to the end user }
public ActionResult PartialTransporter() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); // ViewBag.listRegion = dbConn.Select<Master_Territory>("Select TerritoryID, TerritoryName from Master_Territory where Level='Region' "); //dict["listrole"] = dbConn.Select<Auth_Role>("SELECT * FROM Auth_Role WHERE Status = 1"); dbConn.Close(); return PartialView("_Transporter", dict); } else return RedirectToAction("NoAccess", "Error"); }
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, Address=@Address,WHKeeper=@WHKeeper, Note = @Note, UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, WHName=@WHName 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(); } }
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(); } }
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(); } }
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(); } }
// // 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(); } }
public ActionResult PartialDeliveryDiscount() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); //dict["listrole"] = dbConn.Select<Auth_Role>("SELECT * FROM Auth_Role WHERE IsActive = 1"); dbConn.Close(); return PartialView("_DeliveryDiscount", dict); } else return RedirectToAction("NoAccess", "Error"); }
public ActionResult GetWH() { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.Select<WareHouse>("Select * from WareHouse"); return Json(new { success = true, data = data}); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
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(); } }
public ActionResult PartialRole() { if (userAsset.ContainsKey("View") && userAsset["View"]) { IDbConnection dbConn = new OrmliteConnection().openConn(); var dict = new Dictionary<string, object>(); dict["asset"] = userAsset; dict["activestatus"] = new CommonLib().GetActiveStatus(); dict["user"] = dbConn.Select<Auth_User>(p => p.IsActive == true); dict["listWH"] = dbConn.Select<WareHouse>(p => p.Status == true); dict["listWHL"] = dbConn.Select<WareHouseLocation>(p => p.Status == true); dict["listUnit"] = dbConn.Select<DC_AD_Unit>(p => p.Status == true); dbConn.Close(); return PartialView("_ListPublication", dict); } else return RedirectToAction("NoAccess", "Error"); }
public ActionResult GetTransByID(string id) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var listStran = dbConn.Select<DC_LG_Contract_Transporter>("ContractID={0}",id); return Json(new { success = true, listtran = listStran }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }