private bool checkInput(Control parent, TextBox except) { foreach (Control child in parent.Controls) { if (child.Controls.Count > 0) { return(checkInput(child, except)); } else { if (child is TextBox) { var txt = child as TextBox; if (txt != except) { var result = txt.TryPraseDecimal(); if (0 == result.IsSucceeded) { MsgBoxHelper.Error(result.Message); txt.SelectAll(); return(false); } } } } } return(true); }
void BeginStartServer(object sender, EventArgs e) { int port; if (!int.TryParse(txtPort.Text, out port)) { MsgBoxHelper.Error("포트 번호가 잘못 입력되었거나 입력되지 않았습니다."); txtPort.Focus(); txtPort.SelectAll(); return; } if (thisAddress == null) { // 로컬호스트 주소를 사용한다. thisAddress = IPAddress.Loopback; txtAddress.Text = thisAddress.ToString(); } else { thisAddress = IPAddress.Parse(txtAddress.Text); } // 서버에서 클라이언트의 연결 요청을 대기하기 위해 // 소켓을 열어둔다. IPEndPoint serverEP = new IPEndPoint(thisAddress, port); mainSock.Bind(serverEP); mainSock.Listen(10); AppendText(txtHistory, string.Format("서버 시작: @{0}", serverEP)); // 비동기적으로 클라이언트의 연결 요청을 받는다. mainSock.BeginAccept(AcceptCallback, null); }
void OnConnectToServer(object sender, EventArgs e) { if (mainSock.Connected) { MsgBoxHelper.Error("이미 연결되어 있습니다!"); return; } int port = 15000; //고정 nameID = txtID.Text; //ID AppendText(txtHistory, string.Format("서버: @{0}, port: 15000, ID: @{1}", txtAddress.Text, nameID)); try { mainSock.Connect(txtAddress.Text, port); } catch (Exception ex) { MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}", MessageBoxButtons.OK, ex.Message); return; } // 연결 완료되었다는 메세지를 띄워준다. AppendText(txtHistory, "서버와 연결되었습니다."); // 연결 완료, 서버에서 데이터가 올 수 있으므로 수신 대기한다. AsyncObject obj = new AsyncObject(4096); obj.WorkingSocket = mainSock; mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, DataReceived, obj); }
private void btnSave_Click(object sender, EventArgs e) { // update values _configContent.Connections = cbConnection.Items.Cast <Connection>().ToList(); _configContent.CurrentConnectionName = cbConnection.SelectedIndex > -1 ? cbConnection.SelectedItem.ToString() : ""; _configContent.CurrentDocTemplateName = cbDocTemplate.SelectedIndex > -1 ? cbDocTemplate.SelectedItem.ToString() : ""; var msg = new StringWriter(); if (_configContent.IsValid(ref msg)) { // decide need to refresh tables in main form or not IsCurrentConnectionChanged = !string.Equals(_configContent.CurrentConnection.Str, Config.GetInstance().Content.CurrentConnection.Str); try { // save to config Config.GetInstance().Content = _configContent; Config.GetInstance().SaveConfig(); // close this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MsgBoxHelper.Error("Failure: " + ex.Message); } } else { MsgBoxHelper.Warning(msg.ToString()); } }
private void btnRememberCheckedTables_Click(object sender, EventArgs e) { var checkedTables = GetCheckedTableNames(); if (checkedTables.Count > 0) { try { // save to config var connName = Config.GetInstance().Content.CurrentConnectionName; Config.GetInstance().Content.DocTablePackages[connName] = checkedTables; Config.GetInstance().SaveConfig(); MsgBoxHelper.Done(); } catch (Exception ex) { MsgBoxHelper.Error("Failure: " + ex.Message); } } else { MsgBoxHelper.Warning("Please select table!"); } }
private void btnRemoveDocTemplate_Click(object sender, EventArgs e) { if (cbDocTemplate.SelectedIndex > -1) { if (MsgBoxHelper.Confirm("Remove this template?") == DialogResult.OK) { try { // delete tempalte file var selectedFile = Path.Combine(_configContent.DocTemplateLocation, cbDocTemplate.SelectedItem.ToString()); File.Delete(selectedFile); // remove file name in list cbDocTemplate.Items.RemoveAt(cbDocTemplate.SelectedIndex); cbDocTemplate.Text = string.Empty; } catch (Exception ex) { MsgBoxHelper.Error("Failure: " + ex.Message); } } } else { MsgBoxHelper.Warning("Please choose a template!"); } }
private void btnGenerate_Click(object sender, EventArgs e) { var checkedTableNames = GetCheckedTableNames(); if (checkedTableNames.Count > 0) { try { // generate db document string templatePath = Config.GetInstance().Content.CurrentDocTemplatePath; string outputPath = Config.GetInstance().Content.OutputDocLocation + Guid.NewGuid().ToString() + ".xlsx"; _dbManager.GenerateDocument(checkedTableNames, templatePath, outputPath); // open it Process.Start(outputPath); } catch (Exception ex) { MsgBoxHelper.Error("Failure: " + ex.Message); } } else { MsgBoxHelper.Warning("Please select table!"); } }
void OnConnectToServer(object sender, EventArgs e) { if (mainSock.Connected) { MsgBoxHelper.Error("이미 연결되어 있습니다!"); return; } int port; if (!int.TryParse(txtPort.Text, out port)) { MsgBoxHelper.Error("포트 번호가 잘못 입력되었거나 입력되지 않았습니다."); txtPort.Focus(); txtPort.SelectAll(); return; } try { mainSock.Connect("172.16.52.226", port); } catch (Exception ex) { MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}", MessageBoxButtons.OK, ex.Message); return; } // 연결 완료되었다는 메세지를 띄워준다. AppendText(textBox1, "서버와 연결되었습니다."); // 연결 완료, 서버에서 데이터가 올 수 있으므로 수신 대기한다. AsyncObject obj = new AsyncObject(4096); obj.WorkingSocket = mainSock; mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, DataReceived, obj); }
private void btnLogin_Click(object sender, EventArgs e) { if (Control == null) { IsOK = false; this.Close(); return; } try { wrap.Validite(); } catch (Exception ex) { MsgBoxHelper.Error(ex.Message); return; } if (Control.Login(txtName.Text, txtPassword.Text)) { IsOK = true; this.Close(); return; } MsgBoxHelper.Error("登录失败,请重试!"); }
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { try { MsgBoxHelper.Error(e.Exception.Message); } catch (Exception ex) { MsgBoxHelper.Error(ex.Message); } }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { var ex = e.ExceptionObject as Exception; if (ex == null) { return; } MsgBoxHelper.Error(ex.Message); } catch (Exception ex) { MsgBoxHelper.Error(ex.Message); } }
private void calc(TextBox target, Func <decimal> calcAction) { try { if (!checkInput(this, target)) { return; } if (0m != G && 4m >= E) { MsgBoxHelper.Error($"【{txtE.Tag}】大于4小时才需要填写【{txtG.Tag}】"); return; } decimal result = calcAction(); initalColor(); target.SetResult(result.ToString()); } catch (Exception ex) { MsgBoxHelper.Error(ex.Message); } }
private void RegUser(object sender, RoutedEventArgs e) { Helpers.Authhelper authhelper = new Helpers.Authhelper(); if (Helpers.Validation.ValidationUser( Pass.Text, email.Text, date.SelectedDate.Value, FirstName.Text, LastName.Text)) { if (context.user.Where(i => i.Login == email.Text).Count() < 1) { context.user.Add( new Model.user { Login = email.Text, Password = Helpers.Encrypt.EncryptData(Pass.Text), FistName = FirstName.Text, LastName = LastName.Text, MiddleName = MiddleName.Text, DateOfBirth = date.SelectedDate }); context.SaveChanges(); MsgBoxHelper.Info("Пользователь добавлен"); NavigationService.GoBack(); } else { MsgBoxHelper.Error("Пользователь уже существует"); } } else { MsgBoxHelper.Warning("Не все поля заполнены"); } }