public MessageReport DeleteById(string id, ref tblCardGroup obj) { var re = new MessageReport(); re.Message = "Error"; re.isSuccess = false; try { obj = GetById(Guid.Parse(id)); if (obj != null) { _tblCardGroupRepository.Delete(n => n.CardGroupID.ToString() == id); Save(); re.Message = FunctionHelper.GetLocalizeDictionary("Home", "notification")["DeleteSuccess"]; re.isSuccess = true; } else { re.Message = FunctionHelper.GetLocalizeDictionary("Home", "notification")["record_does_not_exist"]; re.isSuccess = false; } } catch (Exception ex) { re.Message = ex.Message; re.isSuccess = false; } return(re); }
public ActionResult Create(tblCardGroup obj, bool SaveAndCountinue = false) { //Danh sách sử dụng ViewBag.Url = url; //Kiểm tra if (!ModelState.IsValid) { return(View(obj)); } if (string.IsNullOrEmpty(obj.CardGroupName)) { ModelState.AddModelError("CardGroupName", "Vui lòng nhập tên nhóm thẻ"); return(View(obj)); } var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName); if (cgroup != null) { ModelState.AddModelError("CardGroupName", "Nhóm thẻ đã tồn tại"); return(View(obj)); } //Gán giá trị obj.CardGroupID = Guid.NewGuid(); obj.DayTimeFrom = ""; obj.DayTimeTo = ""; obj.TimePeriods = ""; obj.Costs = ""; //Thực hiện thêm mới var result = _tblCardGroupService.Create(obj); if (result.isSuccess) { WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CardGroupID.ToString(), obj.CardGroupName, "tblCardGroup", ConstField.AccessControlCode, ActionConfigO.Create); if (SaveAndCountinue) { TempData["Success"] = result.Message; return(RedirectToAction("Create")); } if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", result.Message); return(View(obj)); } }
public JsonResult Delete(string id) { var obj = new tblCardGroup(); var result = _tblCardGroupService.DeleteById(id, ref obj); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Create() { ViewBag.Url = url; var obj = new tblCardGroup(); return(View(obj)); }
public PartialViewResult FormulationBlock(string value = "") { var _obj = new tblCardGroup(); if (TempData["obj"] != null) { _obj = (tblCardGroup)TempData["obj"]; } return(PartialView(_obj)); }
public JsonResult Delete(string id) { var obj = new tblCardGroup(); var result = _tblCardGroupService.DeleteById(id, ref obj); if (result.isSuccess) { WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CardGroupID.ToString(), obj.CardGroupName, "tblCardGroup", ConstField.AccessControlCode, ActionConfigO.Delete); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Create() { ViewBag.CardTypes = GetCardType(); ViewBag.VehicleGroups = GetVehicleGroup(); ViewBag.Formulation = GetFormulation(); ViewBag.Url = url; var obj = new tblCardGroup(); obj.DayTimeFrom = "00:00"; obj.DayTimeTo = "00:00"; obj.CardType = 0; obj.VehicleGroupID = ""; obj.Description = ""; obj.EnableFree = false; obj.Inactive = false; obj.IsCheckPlate = false; obj.IsHaveMoneyExcessTime = false; obj.IsHaveMoneyExpiredDate = false; obj.LaneIDs = ""; return(View(obj)); }
public MessageReport Create(tblCardGroup obj) { var re = new MessageReport(); re.Message = "Error"; re.isSuccess = false; try { _tblCardGroupRepository.Add(obj); Save(); re.Message = FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"]; re.isSuccess = true; } catch (Exception ex) { re.Message = ex.Message; re.isSuccess = false; } return(re); }
public ActionResult Update(tblCardGroup obj, string id, string listLanes = "", string selectValueBlockTime = "", string txtEachFee = "") { var DictionaryAction = FunctionHelper.GetLocalizeDictionary("Home", "notification"); ViewBag.CardTypes = GetCardType(); ViewBag.VehicleGroups = GetVehicleGroup(); ViewBag.Formulation = GetFormulation(); //ViewBag.PN = pageNumber; //ViewBag.Group = groupId; //Kiểm tra var oldObj = _tblCardGroupService.GetById(Guid.Parse(id)); if (oldObj == null) { ViewBag.Error = DictionaryAction["record_does_not_exist"]; return(View(obj)); } if (!ModelState.IsValid) { return(View(oldObj)); } if (string.IsNullOrEmpty(obj.CardGroupName)) { ModelState.AddModelError("CardGroupName", DictionaryAction["enter_CardGrp_name"]); return(View(oldObj)); } if (string.IsNullOrEmpty(listLanes)) { ModelState.AddModelError("LaneIDs", DictionaryAction["CardGrp_lane"]); return(View(oldObj)); } var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName); if (cgroup != null && !cgroup.CardGroupID.Equals(Guid.Parse(id))) { ModelState.AddModelError("CardGroupName", DictionaryAction["CardGrp_already_exists"]); return(View(oldObj)); } //Gán giá trị oldObj.CardType = obj.CardType; oldObj.FreeTime = obj.FreeTime; oldObj.DayTimeFrom = obj.DayTimeFrom; oldObj.DayTimeTo = obj.DayTimeTo; oldObj.Description = obj.Description; oldObj.EachFee = obj.EachFee; oldObj.EnableFree = obj.EnableFree; oldObj.Formulation = obj.Formulation; oldObj.Inactive = obj.Inactive; oldObj.IsCheckPlate = obj.IsCheckPlate; oldObj.IsHaveMoneyExcessTime = obj.IsHaveMoneyExcessTime; oldObj.IsHaveMoneyExpiredDate = obj.IsHaveMoneyExpiredDate; oldObj.CardGroupName = obj.CardGroupName; oldObj.SortOrder = obj.SortOrder; oldObj.VehicleGroupID = obj.VehicleGroupID; oldObj.LaneIDs = listLanes; oldObj.EachFee = obj.EachFee; if (!string.IsNullOrWhiteSpace(obj.TimePeriods)) { oldObj.TimePeriods = obj.TimePeriods; } if (!string.IsNullOrWhiteSpace(obj.Costs)) { oldObj.Costs = obj.Costs; } #region Block and time if (!string.IsNullOrWhiteSpace(selectValueBlockTime)) { var arr = selectValueBlockTime.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Any()) { for (int i = 0; i < arr.Length; i++) { var objBT = arr[i].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (objBT.Any()) { var block = !string.IsNullOrEmpty(objBT[0].ToString()) ? Convert.ToInt32(objBT[0].ToString().Replace(".", "")) : 0; var time = !string.IsNullOrEmpty(objBT[1].ToString()) ? Convert.ToInt32(objBT[1].ToString()) : 0; switch (i) { case 0: oldObj.Block0 = block; oldObj.Time0 = time; break; case 1: oldObj.Block1 = block; oldObj.Time1 = time; break; case 2: oldObj.Block2 = block; oldObj.Time2 = time; break; case 3: oldObj.Block3 = block; oldObj.Time3 = time; break; case 4: oldObj.Block4 = block; oldObj.Time4 = time; break; case 5: oldObj.Block5 = block; oldObj.Time5 = time; break; } } } } } #endregion if (!string.IsNullOrWhiteSpace(txtEachFee)) { txtEachFee = txtEachFee.Replace(".", ""); oldObj.EachFee = Convert.ToInt32(txtEachFee); } //Thực hiện cập nhật var result = _tblCardGroupService.Update(oldObj); if (result.isSuccess) { // UpdateCardCustomer(oldObj._id.ToString(), oldObj); objId = oldObj.CardGroupID.ToString(); if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", result.Message); return(View(obj)); } }
public ActionResult Create(tblCardGroup obj, string listLanes = "", string selectValueBlockTime = "", string txtEachFee = "", bool SaveAndCountinue = false) { var DictionaryAction = FunctionHelper.GetLocalizeDictionary("Home", "notification"); //Danh sách sử dụng ViewBag.CardTypes = GetCardType(); ViewBag.VehicleGroups = GetVehicleGroup(); ViewBag.Formulation = GetFormulation(); ViewBag.Url = url; //Kiểm tra if (!ModelState.IsValid) { return(View(obj)); } if (string.IsNullOrEmpty(obj.CardGroupName)) { ModelState.AddModelError("CardGroupName", DictionaryAction["enter_CardGrp_name"]); return(View(obj)); } if (string.IsNullOrEmpty(listLanes)) { ModelState.AddModelError("LaneIDs", DictionaryAction["CardGrp_lane"]); return(View(obj)); } var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName); if (cgroup != null) { ModelState.AddModelError("CardGroupName", DictionaryAction["CardGrp_already_exists"]); return(View(obj)); } //Gán giá trị obj.CardGroupID = Guid.NewGuid(); obj.LaneIDs = listLanes; if (!string.IsNullOrWhiteSpace(txtEachFee)) { txtEachFee = txtEachFee.Replace(".", ""); obj.EachFee = Convert.ToInt32(txtEachFee); } if (string.IsNullOrEmpty(obj.TimePeriods)) { obj.TimePeriods = "00:00-00:00-00:00"; } if (string.IsNullOrEmpty(obj.Costs)) { obj.Costs = "0"; } #region Block and time if (!string.IsNullOrWhiteSpace(selectValueBlockTime)) { var arr = selectValueBlockTime.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Any()) { for (int i = 0; i < arr.Length; i++) { var objBT = arr[i].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (objBT.Any()) { var block = !string.IsNullOrEmpty(objBT[0].ToString()) ? Convert.ToInt32(objBT[0].ToString().Replace(".", "")) : 0; var time = !string.IsNullOrEmpty(objBT[1].ToString()) ? Convert.ToInt32(objBT[1].ToString()) : 0; switch (i) { case 0: obj.Block0 = block; obj.Time0 = time; break; case 1: obj.Block1 = block; obj.Time1 = time; break; case 2: obj.Block2 = block; obj.Time2 = time; break; case 3: obj.Block3 = block; obj.Time3 = time; break; case 4: obj.Block4 = block; obj.Time4 = time; break; case 5: obj.Block5 = block; obj.Time5 = time; break; } } } } } #endregion //Thực hiện thêm mới var result = _tblCardGroupService.Create(obj); if (result.isSuccess) { if (SaveAndCountinue) { TempData["Success"] = result.Message; return(RedirectToAction("Create")); } if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", result.Message); return(View(obj)); } }
public ActionResult ReportEvent(string KeyWord = "", string status = "", string controllerid = "", string cardgroup = "", string fromdate = "", string todate = "", int page = 1, string chkExport = "0", string datefrompicker = "") { var totalItem = 0; var pageSize = 20; var user = GetCurrentUser.GetUser(); string CustomerID = ""; if (!string.IsNullOrWhiteSpace(fromdate) && !string.IsNullOrWhiteSpace(todate)) { datefrompicker = fromdate + "-" + todate; } #region Excel //Excel if (chkExport.Equals("1")) { ////Query lấy dữ liệu var listExcel = _ReportService.GetReportEventExcel(KeyWord, status, controllerid, fromdate, todate, cardgroup); if (listExcel != null && listExcel.Rows.Count > 0) { foreach (DataRow dr in listExcel.Rows) { var customer = new tblCustomer(); var cg = new tblCardGroup(); if (!string.IsNullOrEmpty(dr["CardNumber"].ToString())) { var card = _tblCardService.GetByCardNumber(dr["CardNumber"].ToString()); if (card != null) { if (!string.IsNullOrEmpty(card.CustomerID)) { customer = _tblCustomerService.GetById(Guid.Parse(card.CustomerID)); } } } if (!string.IsNullOrEmpty(dr["CardGroupID"].ToString())) { cg = _tblCardGroupService.GetById(Guid.Parse(dr["CardGroupID"].ToString())); } if (!string.IsNullOrEmpty(dr["ControllerID"].ToString())) { var controller = _tblAccessControllerService.GetById(Guid.Parse(dr["ControllerID"].ToString())); var door = _tblAccessDoorService.GetByController_Readerindex(dr["ControllerID"].ToString(), dr["ReaderIndex"].ToString()); dr["ControllerName"] = controller != null ? controller.ControllerName : ""; dr["DoorName"] = door != null ? door.DoorName : ""; } dr["CustomerName"] = customer != null ? customer.CustomerName : ""; dr["CardGroupName"] = cg != null ? cg.CardGroupName : ""; dr["Address"] = customer != null ? customer.Address : ""; } } listExcel.Columns.Remove("RowNumber"); listExcel.Columns.Remove("ControllerID"); listExcel.Columns.Remove("ReaderIndex"); listExcel.Columns.Remove("CardGroupID"); //Xuất file theo format ReportEventFormatCell(listExcel, "Sự_kiện_quẹt_thẻ", "Sheet1", "", "Sự kiện quẹt thẻ", datefrompicker); return(RedirectToAction("ReportEvent")); } #endregion #region Giao diện var list = _ReportService.GetReportEvent(KeyWord, status, controllerid, fromdate, todate, page, pageSize, ref totalItem, cardgroup); var gridModel = PageModelCustom <ReportEvent_Access> .GetPage(list, page, pageSize, totalItem); ViewBag.CardGroups = GetCardGroupListMonth().ToList(); ViewBag.CardGroupDT = GetCardGroupListMonth().ToDataTableNullable(); ViewBag.CardGroupId = cardgroup; ViewBag.Controllers = GetControllerList().ToList(); ViewBag.ControllerDT = GetControllerList().ToDataTableNullable(); ViewBag.ControllerID = controllerid; ViewBag.Status = status; ViewBag.StatusDDL = FunctionHelper.StatusEventAccess(); ViewBag.Doors = GetDoor(); ViewBag.DateFromPickerValue = datefrompicker; ViewBag.KeyWord = KeyWord; ViewBag.fromdateValue = fromdate; ViewBag.todateValue = !string.IsNullOrWhiteSpace(todate) ? Convert.ToDateTime(todate).ToString("dd/MM/yyyy HH:mm:59") : DateTime.Now.ToString("dd/MM/yyyy 23:59:59"); return(View(gridModel)); #endregion }
public ActionResult Update(tblCardGroup obj) { //Kiểm tra var oldObj = _tblCardGroupService.GetById(obj.CardGroupID); if (oldObj == null) { ViewBag.Error = "Bản ghi không tồn tại"; return(View(obj)); } if (!ModelState.IsValid) { return(View(oldObj)); } if (string.IsNullOrEmpty(obj.CardGroupName)) { ModelState.AddModelError("CardGroupName", "Vui lòng nhập tên nhóm thẻ"); return(View(oldObj)); } var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName); if (cgroup != null && !cgroup.CardGroupID.Equals(obj.CardGroupID)) { ModelState.AddModelError("CardGroupName", "Nhóm thẻ đã tồn tại"); return(View(oldObj)); } //Gán giá trị oldObj.Description = obj.Description; oldObj.Inactive = obj.Inactive; oldObj.CardGroupName = obj.CardGroupName; oldObj.SortOrder = obj.SortOrder; if (!string.IsNullOrWhiteSpace(obj.TimePeriods)) { oldObj.TimePeriods = obj.TimePeriods; } if (!string.IsNullOrWhiteSpace(obj.Costs)) { oldObj.Costs = obj.Costs; } //Thực hiện cập nhật var result = _tblCardGroupService.Update(oldObj); if (result.isSuccess) { objId = oldObj.CardGroupID.ToString(); WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CardGroupID.ToString(), obj.CardGroupName, "tblCardGroup", ConstField.AccessControlCode, ActionConfigO.Update); if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", result.Message); return(View(obj)); } }
public void ExchangeData(MongoClient conn) { var conString = "mongodb://" + txtLogin1.Text.Trim() + ":" + txtPassword1.Text.Trim() + "@" + txtServer1.Text.Trim() + ":" + txtPort.Text.Trim(); _client = new MongoClient(conString); _db = _client.GetDatabase(txtDatabase1.Text.Trim()); var path2 = "[" + txtServer2.Text.Trim() + "].[" + txtDatabase2.Text.Trim() + "]"; // string con1 = "Data Source=125.212.226.137;Initial Catalog=MPARKING-TH2;User Id=adminLogin;Password=kztek123456;"; string con2 = "Data Source=125.212.226.137;Initial Catalog=MPARKING-TH;User Id=adminLogin;Password=kztek123456;"; try { var query = new StringBuilder(); // Chuyển dữ liệu từ trong bảng // Lấy dữ liệu từ sqlDb #region Nhóm thẻ var lst = new List <tblCardGroup>(); query.AppendLine(string.Format("select * from {0}.dbo.[tblCardGroup]", path2)); var obj = DBConnect.GetTable(query.ToString(), con2, false); foreach (DataRow item in obj.Rows) { var obj1 = new tblCardGroup(); obj1.CardGroupID = ObjectId.GenerateNewId().ToString(); obj1.Id = obj1.CardGroupID; obj1.CardGroupCode = item["CardGroupCode"].ToString(); obj1.CardGroupName = item["CardGroupName"].ToString(); obj1.Description = item["Description"].ToString(); obj1.CardType = Convert.ToInt32(item["CardType"].ToString()); obj1.LaneIDs = item["LaneIDs"].ToString(); obj1.DayTimeFrom = item["DayTimeFrom"].ToString(); obj1.DayTimeTo = item["DayTimeTo"].ToString(); obj1.Formulation = Convert.ToInt32(item["Formulation"].ToString()); obj1.EachFee = Convert.ToInt32(item["EachFee"].ToString()); obj1.Block0 = Convert.ToInt32(item["Block0"].ToString()); obj1.Time0 = Convert.ToInt32(item["Time0"].ToString()); obj1.Block1 = Convert.ToInt32(item["Block1"].ToString()); obj1.Time1 = Convert.ToInt32(item["Time1"].ToString()); obj1.Block2 = Convert.ToInt32(item["Block2"].ToString()); obj1.Time2 = Convert.ToInt32(item["Time2"].ToString()); obj1.Block3 = Convert.ToInt32(item["Block3"].ToString()); obj1.Time3 = Convert.ToInt32(item["Time3"].ToString()); obj1.Block4 = Convert.ToInt32(item["Block4"].ToString()); obj1.Time4 = Convert.ToInt32(item["Time4"].ToString()); obj1.Block5 = Convert.ToInt32(item["Block5"].ToString()); obj1.Time5 = Convert.ToInt32(item["Time5"].ToString()); obj1.TimePeriods = (item["TimePeriods"].ToString()); obj1.Costs = (item["Costs"].ToString()); obj1.Inactive = string.IsNullOrWhiteSpace(item["Inactive"].ToString().Trim()) ? false : true; obj1.SortOrder = Convert.ToInt32(item["SortOrder"].ToString()); obj1.IsHaveMoneyExcessTime = string.IsNullOrWhiteSpace(item["IsHaveMoneyExcessTime"].ToString().Trim()) ? false : true; obj1.EnableFree = string.IsNullOrWhiteSpace(item["EnableFree"].ToString().Trim()) ? false : true; obj1.FreeTime = Convert.ToInt32(item["FreeTime"].ToString()); obj1.IsCheckPlate = string.IsNullOrWhiteSpace(item["IsCheckPlate"].ToString().Trim()) ? true : false; obj1.IsHaveMoneyExpiredDate = string.IsNullOrWhiteSpace(item["IsHaveMoneyExpiredDate"].ToString().Trim()) ? false : true; lst.Add(obj1); } var collection = _db.GetCollection <BsonDocument>("tblCardGroup"); foreach (var item in lst) { collection.InsertOneAsync(item.ToBsonDocument()); } #endregion #region Khách hàng var lstCus = new List <tblCustomer>(); var str = new StringBuilder(); str.AppendLine(string.Format("select * from {0}.dbo.[tblCustomer]", path2)); var objCus = DBConnect.GetTable(str.ToString(), con2, false); foreach (DataRow item1 in objCus.Rows) { var obj1 = new tblCustomer(); obj1.CustomerID = ObjectId.GenerateNewId().ToString(); obj1.Id = obj1.CustomerID; obj1.CustomerCode = item1["CustomerCode"].ToString(); obj1.CustomerName = item1["CustomerName"].ToString(); obj1.Description = item1["Description"].ToString(); obj1.Address = item1["Address"].ToString(); obj1.IDNumber = item1["IDNumber"].ToString(); obj1.Mobile = item1["Mobile"].ToString(); obj1.CustomerGroupID = item1["CustomerGroupID"].ToString(); obj1.Description = item1["Description"].ToString(); obj1.EnableAccount = string.IsNullOrWhiteSpace(item1["EnableAccount"].ToString().Trim()) ? false : true; obj1.Account = item1["Account"].ToString(); obj1.Password = item1["Password"].ToString(); obj1.Avatar = item1["Avatar"].ToString(); obj1.Inactive = string.IsNullOrWhiteSpace(item1["Inactive"].ToString().Trim()) ? false : true; obj1.SortOrder = Convert.ToInt32(item1["SortOrder"].ToString()); obj1.CompartmentId = item1["CompartmentId"].ToString(); obj1.AccessLevelID = item1["AccessLevelID"].ToString(); obj1.Finger1 = item1["Finger1"].ToString(); obj1.Finger2 = item1["Finger2"].ToString(); obj1.UserIDofFinger = Convert.ToInt32(item1["UserIDofFinger"].ToString()); obj1.AccessExpireDate = Convert.ToDateTime(item1["AccessExpireDate"].ToString()); obj1.DevPass = item1["DevPass"].ToString(); obj1.ContractStartDate = null; obj1.ContractEndDate = null; obj1.AddressUnsign = item1["AddressUnsign"].ToString(); // obj1.MS_PersonGroupId = item1["MS_PersonGroupId"].ToString(); // obj1.UserFaceId = Convert.ToInt32(item1["UserFaceId"].ToString()); lstCus.Add(obj1); } var collectionCus = _db.GetCollection <BsonDocument>("tblCustomer"); foreach (var item1 in lstCus) { collectionCus.InsertOneAsync(item1.ToBsonDocument()); } #endregion MessageBox.Show("Chuyển đổi dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }