private void SaveCardExtendProcess(tblCardSubmit obj, string _newexpire, string userid) { var sb = new StringBuilder(); sb.AppendLine("INSERT INTO tblActiveCard(Code, [Date], CardNumber, CardNo, Plate, OldExpireDate, [Days], NewExpireDate, CardGroupID, CustomerGroupID, UserID, FeeLevel, CustomerID,IsDelete)"); sb.AppendLine("VALUES ("); sb.AppendLine(string.Format("'{0}'", obj.CustomerCode)); sb.AppendLine(", GETDATE()"); sb.AppendLine(string.Format(", '{0}'", obj.CardNumber)); sb.AppendLine(string.Format(", '{0}'", obj.CardNo)); sb.AppendLine(string.Format(", '{0}'", obj.Plate1 + ";" + obj.Plate2 + ";" + obj.Plate3)); sb.AppendLine(string.Format(", '{0}'", Convert.ToDateTime(obj.DtpDateExpired).ToString("yyyy/MM/dd"))); sb.AppendLine(string.Format(", DATEDIFF(DAY, '{0}', '{1}')", Convert.ToDateTime(obj.DtpDateExpired).ToString("yyyy/MM/dd"), Convert.ToDateTime(_newexpire).ToString("yyyy/MM/dd"))); sb.AppendLine(string.Format(", '{0}'", Convert.ToDateTime(_newexpire).ToString("yyyy/MM/dd"))); sb.AppendLine(string.Format(", '{0}'", obj.CardGroupID)); sb.AppendLine(string.Format(", '{0}'", obj.CustomerGroupID)); sb.AppendLine(string.Format(", '{0}'", userid)); sb.AppendLine(string.Format(", '{0}'", "0")); sb.AppendLine(string.Format(", '{0}'", obj.CustomerID)); sb.AppendLine(", 0"); sb.AppendLine(")"); //Update card sb.AppendLine("UPDATE tblCard"); sb.AppendLine(string.Format("SET ExpireDate = '{0}'", Convert.ToDateTime(_newexpire).ToString("yyyy/MM/dd"))); sb.AppendLine(string.Format("WHERE CardNumber = '{0}'", obj.CardNumber)); ExcuteSQL.Execute(sb.ToString()); }
private void SaveCardProcess(tblCardSubmit obj, string action, string userid) { var str = string.Format("insert into tblCardProcess(Date, CardNumber, Actions, CardGroupID, UserID, CustomerID) values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), obj.CardNumber, action, obj.CardGroupID, userid, obj.CustomerID); SqlExQuery <tblCardProcess> .ExcuteNone(str); }
private List <string> GetListActionType(tblCardSubmit obj) { //Đổi thẻ if (obj.CardNumber != obj.OldCardNumber) { obj.isChangeCard = true; } //Khóa thẻ, mở thẻ //Phát thẻ if (string.IsNullOrWhiteSpace(obj.OldCustomerCode) && !string.IsNullOrWhiteSpace(obj.CustomerCode)) { obj.isReleaseCard = true; obj.isChangeCustomer = false; } //Đổi khách hàng if (!string.IsNullOrWhiteSpace(obj.OldCustomerCode) && (!obj.OldCustomerCode.Equals(obj.CustomerCode) || !string.IsNullOrWhiteSpace(obj.CustomerCode)) && (obj.CustomerID != obj.OldCustomerID)) { obj.isChangeCustomer = true; obj.isReturnCard = false; } //Trả thẻ if (!string.IsNullOrWhiteSpace(obj.OldCustomerCode) && string.IsNullOrWhiteSpace(obj.CustomerCode)) { obj.isReturnCard = true; } //if (obj.OldDtpDateActive != obj.DtpDateActive) //{ // obj.isChangeActiveCard = true; //} //// var str = new List <string>(); //Xử lý với thẻ if (obj.isChangeCard) { //Cấp mới str.Add("ADD");//1 } else { //if (objMap.isModifiedCard) //{ // //Sửa thông tin thẻ // str += 8 + ","; //} } //Xử lý với khách hàng if (obj.isChangeCustomer) { //Cấp lại str.Add("CHANGE"); } else { //if (objMap.isModifiedCustomer) //{ // //Sửa thông tin khách hàng // str += 7 + ","; //} } //Xử lý với thông tin cơ bản //if (objMap.isModifiedBaseInfo) //{ // //Sửa thông tin cơ bản // str += 6 + ","; //} //Xử lý với ngày gia hạn //if (objMap.isModifiedExtendCard) //{ // //Gia hạn thẻ // str += 3 + ","; //} //Xử lý với phương tiện xe //if (objMap.isModifiedVehicle) //{ // //Thay đổi thông tin xe // str += 5 + ","; //} if (obj.isReturnCard) { //Trả thẻ str.Add("RETURN");//10 } //Phát thẻ if (obj.isReleaseCard) { str.Add("RELEASE");//11 } //Hoạt động thẻ //if (obj.isChangeActiveCard) //{ // str.Add("ACTIVE"); //} if (obj.OldCardInActive != obj.CardInActive) { if (obj.CardInActive) { str.Add("LOCK"); } else { str.Add("UNLOCK"); } } return(str); }
private void SetCard_Customer(tblCardSubmit cardsubmit, tblCustomerSubmit customersubmit, bool isNewCard, bool isNewCustomer) { var str = new StringBuilder(); //Thẻ if (isNewCard) { str.AppendLine("INSERT INTO [dbo].[tblCard]([CardNo], [CardNumber], [CustomerID], [CardGroupID], [ImportDate], [ExpireDate], [IsLock], [IsDelete], [Plate1], [VehicleName1], [Plate2], [VehicleName2], [Plate3], [VehicleName3], [ViettelId], [ViettelType])"); str.AppendLine("VALUES ("); str.AppendLine(string.Format("'{0}'", cardsubmit.CardNo)); str.AppendLine(string.Format(", '{0}'", cardsubmit.CardNumber)); str.AppendLine(string.Format(", '{0}'", cardsubmit.CustomerID)); str.AppendLine(string.Format(", '{0}'", cardsubmit.CardGroupID)); str.AppendLine(",GETDATE()"); str.AppendLine(string.Format(", '{0}'", Convert.ToDateTime(cardsubmit.DtpDateExpired).ToString("yyyy/MM/dd"))); str.AppendLine(string.Format(", '{0}'", cardsubmit.CardInActive ? 1 : 0)); str.AppendLine(", 0"); str.AppendLine(string.Format(", '{0}'", cardsubmit.Plate1)); str.AppendLine(string.Format(", '{0}'", cardsubmit.VehicleName1)); str.AppendLine(string.Format(", '{0}'", cardsubmit.Plate2)); str.AppendLine(string.Format(", '{0}'", cardsubmit.VehicleName2)); str.AppendLine(string.Format(", '{0}'", cardsubmit.Plate3)); str.AppendLine(string.Format(", '{0}'", cardsubmit.VehicleName3)); str.AppendLine(string.Format(", '{0}'", cardsubmit.ViettelId)); str.AppendLine(string.Format(", '{0}'", cardsubmit.ViettelType)); str.AppendLine(")"); } else { str.AppendLine("UPDATE [dbo].[tblCard] SET"); str.AppendLine(string.Format(" [CustomerID] = '{0}'", cardsubmit.CustomerID)); str.AppendLine(string.Format(",[IsLock] = '{0}'", cardsubmit.CardInActive ? 1 : 0)); if (!string.IsNullOrWhiteSpace(cardsubmit.CardNo)) { str.AppendLine(string.Format(",[CardNo] = '{0}'", cardsubmit.CardNo)); } if (!string.IsNullOrWhiteSpace(cardsubmit.CardGroupID)) { str.AppendLine(string.Format(",[CardGroupID] = '{0}'", cardsubmit.CardGroupID)); } if (!string.IsNullOrWhiteSpace(cardsubmit.DtpDateExpired)) { str.AppendLine(string.Format(",[ExpireDate] = '{0}'", Convert.ToDateTime(cardsubmit.DtpDateExpired).ToString("yyyy/MM/dd"))); } if (!string.IsNullOrWhiteSpace(cardsubmit.Plate1)) { str.AppendLine(string.Format(",[Plate1] = '{0}'", cardsubmit.Plate1)); } if (!string.IsNullOrWhiteSpace(cardsubmit.VehicleName1)) { str.AppendLine(string.Format(",[VehicleName1] = N'{0}'", cardsubmit.VehicleName1)); } if (!string.IsNullOrWhiteSpace(cardsubmit.Plate2)) { str.AppendLine(string.Format(",[Plate2] = '{0}'", cardsubmit.Plate2)); } if (!string.IsNullOrWhiteSpace(cardsubmit.VehicleName2)) { str.AppendLine(string.Format(",[VehicleName2] = N'{0}'", cardsubmit.VehicleName2)); } if (!string.IsNullOrWhiteSpace(cardsubmit.Plate3)) { str.AppendLine(string.Format(",[Plate3] = '{0}'", cardsubmit.Plate3)); } if (!string.IsNullOrWhiteSpace(cardsubmit.VehicleName3)) { str.AppendLine(string.Format(",[VehicleName3] = N'{0}'", cardsubmit.VehicleName3)); } if (!string.IsNullOrWhiteSpace(cardsubmit.ViettelId)) { str.AppendLine(string.Format(",[ViettelId] = '{0}'", cardsubmit.ViettelId)); } if (!string.IsNullOrWhiteSpace(cardsubmit.ViettelType)) { str.AppendLine(string.Format(",[ViettelType] = '{0}'", cardsubmit.ViettelType)); } str.AppendLine(string.Format("WHERE CardNumber = '{0}'", cardsubmit.CardNumber)); } //Khách hàng if (customersubmit != null) { if (!string.IsNullOrWhiteSpace(customersubmit.CustomerCode)) { if (isNewCustomer) { //var k = _tblCustomerService.GetAll().Count(); str.AppendLine("INSERT INTO [dbo].[tblCustomer]"); str.AppendLine("([CustomerID]"); str.AppendLine(", [CustomerName]"); str.AppendLine(", [CustomerCode]"); str.AppendLine(", [Address]"); str.AppendLine(", [Mobile]"); str.AppendLine(", [IDNumber]"); str.AppendLine(", [CustomerGroupID]"); str.AppendLine(", [EnableAccount]"); str.AppendLine(", [Inactive]"); str.AppendLine(", [UserIDofFinger], [Finger1], [Finger2], [DevPass], [AccessExpireDate])"); str.AppendLine(string.Format("VALUES('{0}', N'{1}','{2}', N'{3}', '{4}', '{5}', '{6}', 1 , 0, 0, '', '', '', '2099-12-31')", customersubmit.CustomerID, customersubmit.CustomerName, customersubmit.CustomerCode, customersubmit.Address, customersubmit.Mobile, customersubmit.IDNumber, customersubmit.CustomerGroupID)); } else { str.AppendLine("UPDATE [dbo].[tblCustomer]"); str.AppendLine(string.Format("SET [CustomerName] = N'{0}'", customersubmit.CustomerName)); str.AppendLine(string.Format(",[Address] = N'{0}'", customersubmit.Address)); str.AppendLine(string.Format(",[Mobile] = N'{0}'", customersubmit.Mobile)); str.AppendLine(string.Format(",[IDNumber] = N'{0}'", customersubmit.IDNumber)); str.AppendLine(string.Format(",[CustomerGroupID] = '{0}'", customersubmit.CustomerGroupID)); str.AppendLine(string.Format("WHERE CONVERT(varchar(50),[CustomerID]) = '{0}'", customersubmit.CustomerID)); } } } // ExcuteSQL.Execute(str.ToString()); }
public async Task <MessageReport> SyncCardData() { var result = new MessageReport(false, "error"); var isNewCard = false; var isNewCustomer = false; try { //Data from viettel var data = await DataFromViettel(); if (data.statusCode != 200) { result = new MessageReport(false, "Failed to get data from Viettel"); return(result); } foreach (var item in data.results) { try { //cardnumber empty => add viettel id default if (string.IsNullOrWhiteSpace(item.cardNumber)) { item.cardNumber = "CardNumber_" + item.id.ToString(); } //cardno empty => add viettel id default if (string.IsNullOrWhiteSpace(item.cardNo)) { item.cardNo = "CardNo_" + item.id.ToString(); } //Get data cardgroup var cardGroupId = GetCardGroupId(item.cardGroup); //Get data customergroup var customerGroupId = GetCustomerGroupId(item.groupUser); //Custom card var cardcustom = GetOrSetCardCustom(item.cardNumber); //Custom customer var customercustom = _API_CardViettelService.GetCustomCustomerByCode(item.userCode); //Thẻ if (cardcustom != null) { cardcustom.ViettelId = item.id.ToString(); cardcustom.CardNo = item.cardNo; cardcustom.CardInActive = item.status == 1 ? false : true; cardcustom.CardGroupID = cardGroupId; cardcustom.ViettelType = item.type; } else { // isNewCard = true; // cardcustom = new tblCardSubmit(); cardcustom.CardID = Guid.NewGuid().ToString(); cardcustom.ViettelId = item.id.ToString(); cardcustom.CardNo = item.cardNo; cardcustom.CardNumber = item.cardNumber; cardcustom.CardGroupID = cardGroupId; cardcustom.CardInActive = item.status == 1 ? false : true; cardcustom.DtpDateExpired = Convert.ToDateTime(item.endDate).ToString("dd/MM/yyyy HH:mm:ss"); cardcustom.ViettelType = item.type; } //Add vehicle plate cardcustom.Plate1 = item.numberPlate; cardcustom.VehicleName1 = item.numberPlateName; //Khách hàng if (customercustom != null) { customercustom.Address = item.address; customercustom.IDNumber = item.cmnd; customercustom.Mobile = item.phoneNumber; customercustom.CustomerName = item.userName; customercustom.CustomerGroupID = customerGroupId; } else { // isNewCustomer = true; // customercustom = new tblCustomerSubmit(); customercustom.CustomerID = Guid.NewGuid().ToString(); customercustom.CustomerCode = item.userCode; customercustom.Address = item.address; customercustom.IDNumber = item.cmnd; customercustom.Mobile = item.phoneNumber; customercustom.CustomerName = item.userName; customercustom.CustomerGroupID = customerGroupId; } //Gán khách hàng vào thẻ cardcustom.CustomerID = customercustom.CustomerID.ToString(); //Save SetCard_Customer(cardcustom, customercustom, isNewCard, isNewCustomer); var oldexpire = cardcustom.DtpDateExpired; var newexpire = Convert.ToDateTime(item.endDate).ToString("dd/MM/yyyy HH:mm:ss"); if (oldexpire != newexpire) { SaveCardExtendProcess(cardcustom, Convert.ToDateTime(item.endDate).ToString("dd/MM/yyyy HH:mm:ss"), "api"); } //Còn lại var listAction = GetListActionType(cardcustom); if (listAction.Any()) { foreach (var itemAc in listAction) { SaveCardProcess(cardcustom, itemAc, "api"); } } } catch { continue; } } result = new MessageReport(true, "Sync completed"); } catch (Exception ex) { result = new MessageReport(false, ex.Message); } return(result); }
public ActionResult Update(tblCardSubmit obj, HttpPostedFileBase FileUpload, string key, string cardgroups, string customergroups, string active, string fromdate, string todate, string isCheckByTime = "0", int page = 1) { var oldObj = _itblCardService.GetCustomById(Guid.Parse(obj.CardID)); if (oldObj == null) { return(View(obj)); } //valid card if ((string.IsNullOrWhiteSpace(obj.CardNo) || string.IsNullOrEmpty(obj.CardNo)) || string.IsNullOrEmpty(obj.CardGroupID)) { if ((string.IsNullOrWhiteSpace(obj.CardNo) || string.IsNullOrEmpty(obj.CardNo))) { ModelState.AddModelError("CardNo", "Please enter CardNo"); } if (string.IsNullOrEmpty(obj.CardGroupID)) { ModelState.AddModelError("CardGroupID", "Please enter CardGroupId"); } return(View(obj)); } //if (FileUpload != null) //{ // var extension = Path.GetExtension(FileUpload.FileName); // var fileName = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension)); // var url = ConfigurationManager.AppSettings["FileUploadAvatar"]; // oldObj.CustomerAvatar = string.Format("{0}{1}", url, fileName); //} //Gán giá trị var result = new MessageReport(); var map = _itblCardService.GetById(Guid.Parse(obj.CardID)); if (map != null) { var existed = _itblCardService.GetByCardNumber_Id(map.CardNumber, Guid.Parse(obj.CardID)); if (existed != null) { ModelState.AddModelError("CardNumber", "mã thẻ đã tồn tại"); return(View(obj)); } map.CardNumber = obj.CardNumber; } //thẻ map.CardNo = obj.CardNo; map.CardGroupID = obj.CardGroupID; map.Description = !string.IsNullOrWhiteSpace(obj.CardDescription) ? obj.CardDescription : ""; map.isAutoCapture = obj.IsAutoCapture; map.DVT = obj.DVT; //ngày map.DateRegister = Convert.ToDateTime(obj.DtpDateRegisted); map.DateRelease = Convert.ToDateTime(obj.DtpDateReleased); //khách hàng //obj.CustomerAvatar = oldObj.CustomerAvatar; map.CustomerID = GetOrSetCustomer(obj, FileUpload); result = _itblCardService.Update(map); if (result.isSuccess) { return(RedirectToAction("Index", new { })); } else { ModelState.AddModelError("", result.Message); return(View(obj)); } }
private string GetOrSetCustomer(tblCardSubmit obj, HttpPostedFileBase FileUpload) { if (FileUpload != null) { var extension = Path.GetExtension(FileUpload.FileName) ?? ""; var fileName = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension)); var url = ConfigurationManager.AppSettings["FileUploadAvatar"]; obj.CustomerAvatar = string.Format("{0}{1}", url, fileName); } var id = ""; if (!string.IsNullOrWhiteSpace(obj.CustomerID)) { var tblCus = _tblCustomerService.GetById(Guid.Parse(obj.CustomerID)); if (tblCus != null) { id = tblCus.CustomerID.ToString(); tblCus.CustomerCode = obj.CustomerCode; tblCus.CustomerName = obj.CustomerName; tblCus.CustomerGroupID = obj.CustomerGroupID; tblCus.Address = obj.CustomerAddress; tblCus.Avatar = obj.CustomerAvatar; tblCus.IDNumber = obj.CustomerIdentify; tblCus.Mobile = obj.CustomerMobile; tblCus.CompartmentId = obj.CompartmentId; _tblCustomerService.Update(tblCus); } else { tblCus = new tblCustomer() { CustomerID = Guid.NewGuid(), Address = obj.CustomerAddress, Avatar = obj.CustomerAddress, CustomerName = obj.CustomerName, CustomerGroupID = obj.CustomerGroupID, Description = "", Mobile = obj.CustomerMobile, IDNumber = obj.CustomerIdentify, AccessLevelID = "", CustomerCode = obj.CustomerCode, Finger1 = "", Finger2 = "", Inactive = false, SortOrder = 0, DevPass = "", CompartmentId = obj.CompartmentId, AccessExpireDate = Convert.ToDateTime("2099/12/31") }; _tblCustomerService.Create(tblCus); } } else { if (!string.IsNullOrWhiteSpace(obj.CustomerCode)) { var tblCustomerByCode = _tblCustomerService.GetByCode(obj.CustomerCode); if (tblCustomerByCode != null) { id = tblCustomerByCode.CustomerID.ToString(); } else { var tbl = new tblCustomer() { CustomerID = Guid.NewGuid(), Address = obj.CustomerAddress, Avatar = obj.CustomerAvatar, CustomerName = obj.CustomerName, CustomerGroupID = obj.CustomerGroupID, Description = "", Mobile = obj.CustomerMobile, IDNumber = obj.CustomerIdentify, AccessLevelID = "", CustomerCode = obj.CustomerCode, Finger1 = "", Finger2 = "", Inactive = false, SortOrder = 0, DevPass = "", CompartmentId = obj.CompartmentId, AccessExpireDate = Convert.ToDateTime("2099/12/31") }; var result = _tblCustomerService.Create(tbl); if (result.isSuccess) { id = tbl.CustomerID.ToString(); } } } } return(id); }
public ActionResult Create(tblCardSubmit tblCard, HttpPostedFileBase FileUpload, string key, string cardgroups, string customergroups, string active, string fromdate, string todate, string isCheckByTime = "0", bool SaveAndCountinue = false) { ViewBag.CardGroups = GetListCardGroup(); ViewBag.lcustomergroups = GetMenuList(); ViewBag.CardGroups = GetListCardGroup(); ViewBag.lcustomergroups = GetMenuList(); ViewBag.keyValue = key; ViewBag.cardgroupsValue = cardgroups; ViewBag.customergroupsValue = customergroups; ViewBag.activeValue = active; ViewBag.fromdateValue = fromdate; ViewBag.todateValue = todate; ViewBag.isCheckByTimeValue = isCheckByTime; if (!ModelState.IsValid) { return(View(tblCard)); } // valid thẻ if ((string.IsNullOrEmpty(tblCard.CardNo) || string.IsNullOrWhiteSpace(tblCard.CardNo)) || (string.IsNullOrWhiteSpace(tblCard.CardNumber) || string.IsNullOrEmpty(tblCard.CardNumber)) || (string.IsNullOrWhiteSpace(tblCard.CardNumber))) { if ((string.IsNullOrEmpty(tblCard.CardNo) || string.IsNullOrWhiteSpace(tblCard.CardNo))) { ModelState.AddModelError("", "Hãy nhập lại mã thẻ"); } if ((string.IsNullOrWhiteSpace(tblCard.CardNumber) || string.IsNullOrEmpty(tblCard.CardNumber))) { ModelState.AddModelError("", "Hãy nhập lại Số thẻ "); } if (string.IsNullOrWhiteSpace(tblCard.CardNumber)) { ModelState.AddModelError("", "NHập lại ID "); } return(View(tblCard)); } // check mã thẻ có tồn tại k var cardNumber = _itblCardService.GetByCardNumber(tblCard.CardNumber.Trim()); if (cardNumber != null) { ModelState.AddModelError("CardNumber", "mã thẻ đã tồn tại"); return(View(tblCard)); } // map var map = new tblCard() { CardID = Guid.NewGuid(), CardNo = tblCard.CardNo, CardNumber = tblCard.CardNumber.Trim(), CardGroupID = tblCard.CardGroupID, CustomerID = GetOrSetCustomer(tblCard, FileUpload), AccessLevelID = "", ChkRelease = false, ImportDate = DateTime.Now, DateRegister = Convert.ToDateTime(tblCard.DtpDateRegisted), DateRelease = Convert.ToDateTime(tblCard.DtpDateReleased), ExpireDate = Convert.ToDateTime(tblCard.DtpDateExpired), DateActive = Convert.ToDateTime(tblCard.DtpDateActive), Description = !string.IsNullOrWhiteSpace(tblCard.CardDescription) ? tblCard.CardDescription : "", IsDelete = false, IsLock = tblCard.CardInActive, Plate1 = tblCard.Plate1, Plate2 = tblCard.Plate2, Plate3 = tblCard.Plate3, VehicleName1 = tblCard.VehicleName1, VehicleName2 = tblCard.VehicleName2, VehicleName3 = tblCard.VehicleName3, DVT = tblCard.DVT, AccessExpireDate = Convert.ToDateTime("2099/12/31"), DateCancel = DateTime.Now, isAutoCapture = tblCard.IsAutoCapture }; //thực hiện thêm mới var result = _itblCardService.Create(map); if (result.isSuccess) { return(RedirectToAction("Index", new { key = key, cardgroups = cardgroups, customergroups = customergroups, fromdate = fromdate, todate = todate, active = active, isCheckByTime = isCheckByTime, selectedId = tblCard.CardID })); } else { ModelState.AddModelError("", result.Message); return(View(tblCard)); } }