public tblCustomerSubmit GetCustomCustomerByCode(string code) { var obj = GetByCode(code); if (obj != null) { var t = new tblCustomerSubmit() { AccessLevelID = obj.AccessLevelID, Account = obj.Account, Address = obj.Address, Avatar = obj.Avatar, CompartmentId = obj.CompartmentId, CustomerCode = obj.CustomerCode, CustomerGroupID = obj.CustomerGroupID, CustomerID = obj.CustomerID.ToString(), CustomerName = obj.CustomerName, Description = obj.Description, DevPass = obj.DevPass, EnableAccount = obj.EnableAccount, Finger1 = obj.Finger1, Finger2 = obj.Finger2, IDNumber = obj.IDNumber, Inactive = obj.Inactive, Mobile = obj.Mobile, Password = obj.Password, SortOrder = obj.SortOrder, UserIDofFinger = obj.UserIDofFinger }; return(t); } return(null); }
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); }