/// <summary> /// Send a message and wait until controller replies /// </summary> /// <param name="message">Message to be sent</param> /// <param name="timeout">Max time to wait</param> /// <returns>Controller's message</returns> public MID sendAndWaitForResponse(string message, TimeSpan timeout) { try { System.Threading.Thread.Sleep(500); MID midResponse = null; Console.WriteLine($"Sending message: {message}"); Message response = this.simpleTcpClient.WriteLineAndGetReply(message, timeout); Console.WriteLine((response != null) ? $"Response: {response.MessageString}" : "TIMEOUT!"); if (response != null) { this.communicationAlive(); midResponse = this.midIdentifier.IdentifyMid(response.MessageString); } return(midResponse); } catch (Exception ex) { Console.WriteLine($"Exception: {ex.Message}"); return(null); } }
public override void Read(BinaryReader br, int length) { var mid = new MID(); mid.Read(br); MID = mid; Str = Encoding.Default.GetString(br.ReadBytes(length - 12)).Trim('\0'); }
/// <summary> /// MMSI 데이터 페이로드 생성. 랜덤 9자리 숫자. /// </summary> /// <param name="mid">국가코드</param> /// <returns></returns> public int CreateMMSI(MID mid = MID.Korea) { string vMMSI = string.Empty; int rnValue = rnMMSI.Next(100000, 999999); vMMSI = ((int)mid).ToString() + rnValue.ToString(); return(vMMSI.ConvertToInt32()); }
/// <summary> /// /// </summary> private void InitForm() { if (this.UserId > -1) { this.txtuserid.Text = UserId.ToString(); } if (this.Status > -1) { this.ddlOrderStatus.SelectedValue = Status.ToString(); } if (this.ctype > -1) { ddlChannelType.SelectedValue = ctype.ToString(); } if (this.NotifyStatus > -1) { this.ddlNotifyStatus.SelectedValue = this.NotifyStatus.ToString(); } if (!string.IsNullOrEmpty(this.kano)) { this.txtCardNo.Text = this.kano; } if (!string.IsNullOrEmpty(this.stime)) { this.StimeBox.Text = this.stime; } if (!string.IsNullOrEmpty(this.etime)) { this.EtimeBox.Text = this.etime; } if (!string.IsNullOrEmpty(this.sysorderid)) { this.txtOrderId.Text = this.sysorderid; } if (!string.IsNullOrEmpty(this.userorderid)) { this.txtUserOrder.Text = this.userorderid; } if (!string.IsNullOrEmpty(this.supporderid)) { this.txtSuppOrder.Text = this.supporderid; } ddlmange.Items.Add("--请选择业务员--"); DataTable data = BLL.ManageFactory.GetList(" status =1").Tables[0]; foreach (DataRow dr in data.Rows) { ddlmange.Items.Add(new ListItem(dr["username"].ToString(), dr["id"].ToString())); } if (MID > -1) { this.ddlmange.SelectedValue = MID.ToString(); } }
public async Task <bool> ValidateAndUpdateMidAsync(MIDViewModel mid, int id) { var currentMid = await FindAsync(id); bool isValid = false; var branch = await branchRepo.GetFirstOrDefaultAsync(predicate : b => b.Id == mid.BranchId, include : b => b.Include(bb => bb.MIDs)); int midCount = branch.MIDs.Count; if (mid.currencyPhp.Value && mid.currencyUsd.Value) { if (midCount < 10) { isValid = true; MID midPhpModel = new MID(); MID midUsdModel = new MID(); if (currentMid.currencyPhp.HasValue) { if (currentMid.currencyPhp.Value) { mapper.Map <MIDViewModel, MID>(mid, currentMid); currentMid.currencyUsd = false; await Update(currentMid); mapper.Map <MIDViewModel, MID>(mid, midUsdModel); midUsdModel.Id = 0; midUsdModel.BranchId = currentMid.BranchId; midUsdModel.currencyPhp = false; await InsertAsync(midUsdModel); } else { mapper.Map <MIDViewModel, MID>(mid, currentMid); currentMid.currencyPhp = false; await Update(currentMid); mapper.Map <MIDViewModel, MID>(mid, midPhpModel); midPhpModel.Id = 0; midPhpModel.BranchId = currentMid.BranchId; midPhpModel.currencyUsd = false; await InsertAsync(midPhpModel); } } } } else { isValid = true; mapper.Map <MIDViewModel, MID>(mid, currentMid); await Update(currentMid); } return(isValid); }
public async Task <IActionResult> CreateMID([FromBody] MID mid) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool isValid = await midService.ValidateAndInsertMidAsync(mid); if (isValid) { await midService.SaveChangesAsync(); } else { return(Ok(isValid)); } return(Ok(mid)); }
public async Task Update(MID mid) { var branch = await branchRepo.GetFirstOrDefaultAsync(predicate : b => b.Id == mid.BranchId); // Branch.NewAffiliationId is the same with Request.Id mid.HistoryGroupId = Guid.NewGuid(); await historyRepo.InsertAsync(new History { date = DateTime.Now, action = "MID for Branch: " + branch.dbaName + " Updated", groupCode = role, user = user, RequestId = branch.NewAffiliationId, AuditLogGroupId = branch.AuditLogGroupId, HistoryGroupId = mid.HistoryGroupId }); midRepo.Update(mid); }
public async Task <bool> ValidateAndInsertMidAsync(MID mid) { bool isValid = false; var branch = await branchRepo.GetFirstOrDefaultAsync(predicate : b => b.Id == mid.BranchId, include : b => b.Include(bb => bb.MIDs)); int midCount = branch.MIDs.Count; if (mid.currencyPhp.HasValue && mid.currencyUsd.HasValue) { if (mid.currencyPhp.Value && mid.currencyUsd.Value) { if (midCount < 9) { isValid = true; MID midPhpModel = new MID(); mapper.Map <MID, MID>(mid, midPhpModel); midPhpModel.currencyUsd = false; midPhpModel.AuditLogGroupId = branch.AuditLogGroupId; MID midUsdModel = new MID(); mapper.Map <MID, MID>(mid, midUsdModel); midUsdModel.currencyPhp = false; midUsdModel.AuditLogGroupId = branch.AuditLogGroupId; await InsertAsync(midPhpModel); await InsertAsync(midUsdModel); } } } else { isValid = true; await InsertAsync(mid); } return(isValid); }