public void CheckValues(Engineers a) { if (string.IsNullOrWhiteSpace(a.Email)) { throw new AppException("Email is required to finish inserting this record"); } }
public Engineers Save(Engineers engineer) { _db.Entry(engineer).State = EntityState.Added; _db.Engineers.Add(engineer); _db.SaveChanges(); return(engineer); }
public Engineers GetByKey(Engineers ec) { CheckValues(ec); var targetEngineer = _context.Engineers.SingleOrDefault(x => x.Email == ec.Email); if (targetEngineer == null) { throw new AppException($"Engineer with email:'{ec.Email} DNE."); } return(targetEngineer); }
private void EngineerLogin(TmParameter parameter) { TmSoulerDB Engineer = null; int rolerId = TmParameterTool.GetJsonValue <int>(parameter, parameter.ElevenCode.ToString()); bool yes = false; int count = 0; while (!yes) { if (Engineers.Count > 0) { yes = Engineers.TryGetValue(rolerId, out Engineer); } if (yes) { TmParameter response = TmParameterTool.ToJsonParameter <TmSoulerDB>(TenCode.Engineer, ElevenCode.GetRoler, ElevenCode.GetRoler.ToString(), Engineer); response.Keys.Add(parameter.Keys[0]); TmTcpSocket.Instance.Send(response); TmSoulerDB tem; TmObjects.Engineers.TryGetValue(Engineer.Id, out tem); if (tem != null) { TmObjects.Engineers.Remove(Engineer.Id); } TmObjects.Engineers.Add(Engineer.Id, Engineer); //将engineer 集中管理 放在 全局变量字典中,之前几行是检查有没有注册,如有先删除,再重新注册(因为数据更新了)。 if (TmTcpSocket.Instance.TPeers[parameter.Keys[0]] != null) { TmTcpSocket.Instance.TPeers[parameter.Keys[0]].GetComponent <TmSession>().Engineer = Engineer; //给TmTcpSession赋值Engineer-SoulerDB //TmTcpSocket.Instance.TPeers[parameter.Keys[0]].GetComponent<TmSession>().Engineers = GetEngineersByMyself(Engineer, TmObjects.Engineers); //给TmTcpSession赋值Engineer-SoulerDB TmTcpSocket.Instance.TPeers[parameter.Keys[0]].GetComponent <TmSession>().Engineers = TmObjects.Engineers; //给TmTcpSession赋值Engineer-SoulerDB TmTcpSocket.Instance.TPeers[parameter.Keys[0]].GetComponent <TmSession>().IsLogin = true; //给TmTcpSession赋值Engineer-SoulerDB } GetInventorysByRolerId(parameter); GetSkillsByRolerId(parameter); } else { TmMysqlHandler.Instance.GetComponent <TmEngineerMysql>().OnTransferParameter(this, parameter); Console.WriteLine(TmTimerTool.CurrentTime() + " Engineers:" + Engineers.Count); count += 1; } if (count > 3) { yes = true; } } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { //添加 if (string.IsNullOrEmpty(SelectedID)) { Engineers.Add(new SE { ID = txtID.Text.Trim(), JobName = txtJobName.Text.Trim(), Age = int.Parse(txtAge.Text.Trim()), Gender = rdoMale.Checked }); } //修改 else { SE selectedSe = Engineers .FirstOrDefault(c => c.ID == SelectedID); //selectedSe.ID = txtID.Text.Trim(); selectedSe.JobName = txtJobName.Text.Trim(); selectedSe.Age = int.Parse(txtAge.Text.Trim()); selectedSe.Gender = rdoMale.Checked; } if (RefreshMainForm != null) { RefreshMainForm(); } if (Handler != null) { Handler(); } Close(); } }
public async Task <List <Engineer> > GetEngineers() { var engineers = (await Engineers.FindAsync(e => e.Id != null).Result.ToListAsync()); return(engineers); }
/// <summary> /// 验证用户输入 /// </summary> /// <returns></returns> private bool CheckInput() { if (string.IsNullOrEmpty(txtID.Text.Trim())) { MessageBox.Show("员工工号不能为空"); txtID.Focus(); return(false); } if (string.IsNullOrEmpty(txtJobName.Text.Trim())) { MessageBox.Show("员工姓名不能为空"); txtJobName.Focus(); return(false); } if (string.IsNullOrEmpty(txtAge.Text.Trim())) { MessageBox.Show("员工年龄不能为空"); txtAge.Focus(); return(false); } //bool isExists = false; //foreach (var item in Engineers) //{ // if (item.ID == txtID.Text.Trim()) // { // isExists = true; // break; // } //} //if (isExists) //{ // MessageBox.Show("员工工号不能重复"); // txtID.Focus(); // return false; //} if (string.IsNullOrEmpty(SelectedID) && Engineers.Any(c => c.ID == txtID.Text.Trim())) { MessageBox.Show("员工工号不能重复"); txtID.Focus(); return(false); } int age = 0; if (!int.TryParse(txtAge.Text.Trim(), out age)) { MessageBox.Show("年龄必须为数字"); txtAge.Focus(); return(false); } if (!(age >= 16 && age <= 80)) { MessageBox.Show("年龄必须在16-80岁之间"); txtAge.Focus(); return(false); } return(true); }
public ActionResult Save(Engineers engineer) { var result = _repo.Save(engineer); return(Json(result, JsonRequestBehavior.AllowGet)); }