/// <summary>指定された文字列が郵便 区 番号 形式であるか。</summary> /// <param name="input">入力文字列</param> /// <returns> /// true:郵便 区 番号 形式である。 /// false:郵便 区 番号 形式でない。 /// </returns> public static bool IsJpZipCode5(string input) { // 先頭xxx末尾(xは10進数) // 先頭xxx-xx末尾(xは10進数) // 先頭xxx末尾(xは10進数) // 先頭xxxxx末尾(xは10進数) return(FormatChecker.IsJpZipCode5_Hyphen(input) | FormatChecker.IsJpZipCode5_NoHyphen(input)); }
public ActionResult UploadTest(UploadTestViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var context = new Entities()) { if (context.TestSets.FirstOrDefault(x => x.Name.ToLower() == model.TestName) != null) { ModelState.AddModelError("TestName", "This test set name is already taken."); return(View(model)); } byte[] array; var contentType = model.file.ContentType; var expectedResults = new StringBuilder(); using (MemoryStream ms = new MemoryStream()) { model.file.InputStream.CopyTo(ms); array = ms.GetBuffer(); ms.Seek(0, SeekOrigin.Begin); var formatChecker = new FormatChecker(); expectedResults = formatChecker.GetExpectedValuesFromTestSet(ms); } var fileSize = model.file.ContentLength / 1024; var testSet = new TestSets { CreatorId = context.Users.FirstOrDefault <Users> (x => x.UserName.ToLower() == User.Identity.Name.ToLower()).Id, TotalRuns = 0, DateOfCreation = DateTime.Now, Description = model.Description, Data = array, Name = model.TestName, Size = fileSize, ExpectedResults = expectedResults.ToString().TrimStart().TrimEnd() }; context.TestSets.Add(testSet); context.SaveChanges(); } return(RedirectToAction("TestSets", "Testing")); }
public void ShouldParseProperlyFormattedFiles() { //More examples available at: http://elmo.sbs.arizona.edu/sandiway/sudoku/examples.html var files = new[] { @".\Resources\Ok\input_sudoku.txt", @".\Resources\Ok\input_killer_sudoku.txt", @".\Resources\Ok\input_diabolical.txt" }; Func <string, bool> func = s => { var checker = new FormatChecker(new FileParser(s), 9); return(checker.IsValid()); }; AssertFunctionResultIsTrue(files, func); }
public void CorrectBracketsTest() { string testExpr1 = "(1+1)"; string testExpr2 = "[( 2 * 23 ) + (72 / 2)]"; string testExpr3 = "{ () [] [(())] }{}"; bool res1 = FormatChecker.IsBracketBalanced(testExpr1); bool res2 = FormatChecker.IsBracketBalanced(testExpr2); bool res3 = FormatChecker.IsBracketBalanced(testExpr3); Assert.True(res1); Assert.True(res2); Assert.True(res3); }
public void WrongBracketsTest() { string testExpr1 = "(1+1"; string testExpr2 = "[ ( ] )"; string testExpr3 = "{} () ]"; bool res1 = FormatChecker.IsBracketBalanced(testExpr1); bool res2 = FormatChecker.IsBracketBalanced(testExpr2); bool res3 = FormatChecker.IsBracketBalanced(testExpr3); Assert.False(res1); Assert.False(res2); Assert.False(res3); }
static void programLoader(int programToLoad) { switch (programToLoad) { case (0): MenuTest menuTest = new MenuTest(); menuTest.LoadMenu(); break; case (1): FormatChecker formatChecker = new FormatChecker(); formatChecker.FormatCheck(); break; case (2): PrimeToHundred primeToHundred = new PrimeToHundred(); primeToHundred.PrimToHundred(); break; case (3): EliteNumCheck eliteNumCheck = new EliteNumCheck(); eliteNumCheck.ElitePrime(); break; case (4): AnimalEngine animalEngine = new AnimalEngine(); animalEngine.EngineStart(); break; case (5): CarHandler carHandler = new CarHandler(); carHandler.HandleCars(); break; case (6): CombatSystem combatSystem = new CombatSystem(new Katana()); combatSystem.CombatEngine(); break; default: break; } }
private bool isInputCorrect() { bool correct = true; Regex titleFormat = new Regex("^[ a-zA-Z0-9,.():]+$"); if (string.IsNullOrWhiteSpace(engTitleTextBox.Text) || !titleFormat.IsMatch(engTitleTextBox.Text)) { engTitleHintLabel.ForeColor = Color.Red; correct = false; } else { engTitleHintLabel.ForeColor = SystemColors.ControlText; } if (string.IsNullOrWhiteSpace(tradChiTitleTextBox.Text) || !FormatChecker.includeChineseChar(tradChiTitleTextBox.Text)) { tradChiTitleHintLabel.ForeColor = Color.Red; correct = false; } else { tradChiTitleHintLabel.ForeColor = SystemColors.ControlText; } int discountRate; if (string.IsNullOrWhiteSpace(discountRateTextBox.Text) || !int.TryParse(discountRateTextBox.Text, out discountRate) || int.Parse(discountRateTextBox.Text) < 5 || int.Parse(discountRateTextBox.Text) > 90) { discountRateHintLabel.ForeColor = Color.Red; correct = false; } else { discountRateHintLabel.ForeColor = SystemColors.ControlText; } return(correct); }
private bool isInputCorrect() { bool correct = true; Regex illegalWord = new Regex("^[-_!@#^&*'+=]$"); Regex englishWord = new Regex("^[ a-zA-Z0-9,.():]+$"); if (illegalWord.IsMatch(engContentTextBox.Text) || illegalWord.IsMatch(tradChiContentTextBox.Text)) { illegalWordHintLabel.ForeColor = Color.Red; correct = false; } else { illegalWordHintLabel.ForeColor = SystemColors.ControlText; } if (!englishWord.IsMatch(engContentTextBox.Text)) { engContentErrorLabel.Visible = true; correct = false; } else { engContentErrorLabel.Visible = false; } if (!FormatChecker.includeChineseChar(tradChiContentTextBox.Text)) { tradChiContentErrorLabel.Visible = true; correct = false; } else { tradChiContentErrorLabel.Visible = false; } return(correct); }
private void addButton_Click(object sender, EventArgs e) { bool passwordStrong = true; if (string.IsNullOrWhiteSpace(passwordTextBox.Text) || !FormatChecker.checkPasswdFormat(passwordTextBox.Text)) { passwordHintLabel.ForeColor = Color.Red; passwordStrong = false; } else { passwordHintLabel.ForeColor = SystemColors.ControlText; } if (isInputCorrect() && passwordStrong) { Employee emp = new Employee(); emp.setEmployeeID(idTextBox.Text); emp.setEmployeeSurname(surnameTextBox.Text); emp.setEmployeeGivenName(givenNameTextBox.Text); emp.setEmail(emailTextBox.Text); emp.setPassword(Security.getHash(passwordTextBox.Text, "SHA512", null)); if (backendStaffRadioButton.Checked) { emp.setPosition("Staff"); } else if (backendManagerRadioButton.Checked) { emp.setPosition("Manager"); } else if (webMasterRadioButton.Checked) { emp.setPosition("Web Master"); } int i = eda.insert(emp, conn); if (i > 0) { staffListDataGridView.Rows.Add(false, emp.getEmployeeID(), emp.getEmployeeSurname().ToUpper() + " " + emp.getEmployeeGivenName(), emp.getEmail(), ((emp.getPosition().Equals("Staff")) ? rs.GetString("staffText") : ((emp.getPosition().Equals("Manager")) ? rs.GetString("managerText") : rs.GetString("webMasterText")))); staffListDataGridView.ClearSelection(); foreach (DataGridViewRow row in staffListDataGridView.Rows) { if (idTextBox.Text.Equals(row.Cells["staffIdColumn"].Value.ToString())) { row.Selected = true; staffListDataGridView.FirstDisplayedScrollingRowIndex = row.Index; } } deleteButton.Enabled = true; deselectAllButton.Enabled = true; selectAllButton.Enabled = true; addButton.Enabled = false; updateButton.Enabled = true; staffIdHintLabel.Visible = false; MessageBox.Show(rs.GetString("addSuccessMsg")); } else { MessageBox.Show(rs.GetString("failToAddMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 指定された文字列が郵便 番号 /// (日本, ハイフン無し)形式であるか。 /// </summary> /// <param name="input">入力文字列</param> /// <returns> /// true:郵便(区)番号(日本, ハイフン無し)形式である。 /// false:郵便(区)番号(日本, ハイフン無し)形式でない。 /// </returns> public static bool IsJpZipCode_NoHyphen(string input) { // 郵便(区)番号(日本, ハイフン無し)形式 return(FormatChecker.IsJpZipCode7_NoHyphen(input) | FormatChecker.IsJpZipCode5_NoHyphen(input)); }
public LengthChecker(FormatChecker successor) : base(successor) { }
private bool isInputCorrect() { bool correct = true; if (!webMasterRadioButton.Checked && !backendManagerRadioButton.Checked && !backendStaffRadioButton.Checked) { positionErrorLabel.Visible = true; correct = false; } else { positionErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(surnameTextBox.Text) || !nameFormat.IsMatch(surnameTextBox.Text)) { surnameErrorLabel.Visible = true; correct = false; } else { surnameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(givenNameTextBox.Text) || !nameFormat.IsMatch(givenNameTextBox.Text)) { givenNameErrorLabel.Visible = true; correct = false; } else { givenNameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(emailTextBox.Text) || !FormatChecker.isValidEmail(emailTextBox.Text)) { emailErrorLabel.Text = rs.GetString("inputValidEmail"); emailErrorLabel.Visible = true; correct = false; } else { bool emailExist = false; List <Employee> employees = eda.getAllEmployees(conn); List <Employee> deletedEmployee = eda.getAllDeletedEmployees(conn); if (!emailExist) { foreach (Employee emp in employees) { if (!string.IsNullOrWhiteSpace(emp.getEmail()) && emp.getEmail().Equals(emailTextBox.Text)) { if (!string.IsNullOrWhiteSpace(emp.getEmployeeID()) && !emp.getEmployeeID().Equals(idTextBox.Text)) { emailExist = true; break; } } } } if (!emailExist) { foreach (Employee emp in deletedEmployee) { if (!string.IsNullOrWhiteSpace(emp.getEmail()) && emp.getEmail().Equals(emailTextBox.Text)) { if (!string.IsNullOrWhiteSpace(emp.getEmployeeID()) && !emp.getEmployeeID().Equals(idTextBox.Text)) { emailExist = true; break; } } } } if (emailExist) { emailErrorLabel.Text = rs.GetString("emailExists"); emailErrorLabel.Visible = true; correct = false; } else { emailErrorLabel.Text = " "; emailErrorLabel.Visible = false; } } return(correct); }
private void ReadContextCallback(IAsyncResult ar) { TransportClass2 oTransportClass2 = ar.AsyncState as TransportClass2; try { ErrorTypes eError = oTransportClass2.m_oAsyncContextReadOperation.ReadContextEnd(ar); if (ErrorTypes.NoError == eError) { HttpPostedFile oCurrentFile = ((HttpPostedFile)oTransportClass2.m_oFiles[(string)oTransportClass2.m_oFilesEnumerator.Current]); oCurrentFile.InputStream.Position = 0; Stream oImageStream = oCurrentFile.InputStream; byte[] aBuffer = oTransportClass2.m_oAsyncContextReadOperation.m_aOutput.ToArray(); int nImageFormat = FormatChecker.GetFileFormat(aBuffer); string sSupportedFormats = ConfigurationSettings.AppSettings["limits.image.types.upload"] ?? "jpg"; if (0 != (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE & nImageFormat) && -1 != sSupportedFormats.IndexOf(FileFormats.ToString(nImageFormat))) { if (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_GIF == nImageFormat || FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_ICO == nImageFormat) { byte[] aNewBuffer; if (Utils.ConvertGifIcoToPng(aBuffer, nImageFormat, out aNewBuffer)) { nImageFormat = FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_PNG; aBuffer = aNewBuffer; oImageStream = new MemoryStream(aBuffer); } } string sImageHash = null; using (MemoryStream ms = new MemoryStream(aBuffer)) sImageHash = Utils.getMD5HexString(ms); string sFileName; if (oTransportClass2.m_oMediaXmlMapHash.TryGetValue(sImageHash, out sFileName)) { ImageUrlProcess(oTransportClass2, Constants.mc_sResourceServiceUrlRel + Path.Combine(oTransportClass2.m_sKey, @"media\" + sFileName).Replace('\\', '/')); } else { string sSearchName = "image"; List <int> aIndexes = new List <int>(); foreach (KeyValuePair <string, string> kvp in oTransportClass2.m_oMediaXmlMapFilename) { string sFilename = Path.GetFileNameWithoutExtension(kvp.Key); if (0 == sFilename.IndexOf(sSearchName)) { int nCurIndex; if (int.TryParse(sFilename.Substring(sSearchName.Length), out nCurIndex)) { aIndexes.Add(nCurIndex); } } } int nMaxIndex = -1; for (int i = 0, length = aIndexes.Count; i < length; ++i) { int nCurIndex = aIndexes[i]; if (nMaxIndex < nCurIndex) { nMaxIndex = nCurIndex; } } int nNewIndex = 1; if (nMaxIndex >= nNewIndex) { nNewIndex = nMaxIndex + 1; } string sNewName = sSearchName + nNewIndex + "." + FileFormats.ToString(nImageFormat); string sNewPath = Path.Combine(oTransportClass2.m_sKey, @"media\" + sNewName).Replace('\\', '/'); Storage oStorage = new Storage(); TransportClass3 oTransportClass3 = new TransportClass3(oTransportClass2, sNewName, sImageHash, sNewPath, oStorage); oTransportClass3.m_oStorage.WriteFileBegin(sNewPath, oImageStream, WriteUploadedFileCallback, oTransportClass3); } } else { WriteToResponse(oTransportClass2, ErrorTypes.UploadExtension, null, oTransportClass2.m_aInputParams); } } else { WriteToResponse(oTransportClass2, eError, null, oTransportClass2.m_aInputParams); } } catch (Exception e) { _log.Error("Exeption: ", e); WriteToResponse(oTransportClass2, ErrorTypes.Upload, null, oTransportClass2.m_aInputParams); } }
static void Main(string[] args) { string input = @"D:\logs\doc.onlyoffice.com\sync\files"; string output = @"D:\logs\doc.onlyoffice.com\6.0.0\errorsorted"; DateTime start = DateTime.Now; Dictionary <long, long> hash = new Dictionary <long, long>(); if (Directory.Exists(output)) { initCache(hash, output); } Directory.CreateDirectory(output); string[] dirs = Directory.GetDirectories(input); for (int i = 0; i < dirs.Length; ++i) { string[] dirs2 = Directory.GetDirectories(dirs[i]); for (int j = 0; j < dirs2.Length; ++j) { string curDir = dirs2[j]; if (!curDir.EndsWith("browser")) { string source = Path.Combine(curDir, "source"); bool bError = true; if (Directory.Exists(source)) { string[] files = Directory.GetFiles(source); if (files.Length > 0) { bError = false; string file = files[0]; long size = new System.IO.FileInfo(file).Length; long outVal; if (!hash.TryGetValue(size, out outVal)) { hash[size] = 1; int format = FormatChecker.GetFileFormat(file); string formatStr = FormatChecker.FileFormats.ToString(format); if (string.IsNullOrEmpty(formatStr)) { formatStr = "unknown"; } string formatDir = Path.Combine(output, formatStr); Directory.CreateDirectory(formatDir); Copy(curDir, Path.Combine(formatDir, Path.GetFileName(curDir))); } } } if (bError) { string error = Path.Combine(output, "error"); Directory.CreateDirectory(error); Copy(curDir, Path.Combine(error, Path.GetFileName(curDir))); } } } } TimeSpan time = DateTime.Now - start; }
public static (bool success, string validationError) Validate(string content) { FileAsObject o = new FileAsObject(); using (StringReader reader = new StringReader(content)) { bool blockOne = true; string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("#")) { continue; } if (line.Equals("")) { blockOne = false; continue; } if (blockOne) { o.Attach(new NodeLine(line)); } else { o.Attach(new ConnectionLine(line)); } } } FormatChecker formatChecker = new FormatChecker(content); LineChecker lineChecker = new LineChecker(); if (InternalCircuitNamesForTests != null) { lineChecker.SetInternalCircuitNamesForTests(InternalCircuitNamesForTests); } LoopChecker loopChecker = new LoopChecker(content); HangingConnectionChecker hangingConnectionChecker = new HangingConnectionChecker(content); (bool success, string validationError)res; if (!(res = o.Accept(formatChecker)).success) { return(res); } if (!(res = o.Accept(lineChecker)).success) { return(res); } if (!(res = o.Accept(hangingConnectionChecker)).success) { return(res); } if (!(res = o.Accept(loopChecker)).success) { return(res); } return( success : true, validationError : "" ); }
public HeadChecker(FormatChecker successor) : base(successor) { }
/// <summary>指定された文字列がIP電話番号(日本)であるか。</summary> /// <param name="input">入力文字列</param> /// <returns> /// true:IP電話番号(日本)形式である。 /// false:IP電話番号(日本)形式でない。 /// </returns> /// <remarks> /// <総務省> /// 電話番号に関するQ&A /// http://www.soumu.go.jp/main_sosiki/joho_tsusin/top/tel_number/q_and_a-2001aug.html /// 電気通信番号指定状況 /// http://www.soumu.go.jp/main_sosiki/joho_tsusin/top/tel_number/number_shitei.html /// 電気通信サービスFAQ(よくある質問)-6.電話番号について /// http://www.soumu.go.jp/main_sosiki/joho_tsusin/d_faq/6Telephonenumber.htm /// ※ IP電話は050から始まる11桁。 /// </remarks> public static bool IsJpIpPhoneNumber(string input) { // IP電話番号(日本)形式 return(FormatChecker.IsJpIpPhoneNumber_Hyphen(input) | FormatChecker.IsJpIpPhoneNumber_NoHyphen(input)); }
protected FormatChecker(FormatChecker successor) { _successor = successor; }
/// <summary>指定された文字列が郵便(区)番号 形式であるか。</summary> /// <param name="input">入力文字列</param> /// <returns> /// true:郵便(区)番号 形式である。 /// false:郵便(区)番号 形式でない。 /// </returns> public static bool IsJpZipCode(string input) { // 郵便(区)番号 形式 return(FormatChecker.IsJpZipCode_Hyphen(input) | FormatChecker.IsJpZipCode_NoHyphen(input)); }
private void addButton_Click(object sender, EventArgs e) { bool passwordStrong = true; if (string.IsNullOrWhiteSpace(passwordTextBox.Text) || !FormatChecker.checkPasswdFormat(passwordTextBox.Text)) { passwordHintLabel.ForeColor = Color.Red; passwordStrong = false; } else { passwordHintLabel.ForeColor = SystemColors.ControlText; } if (isInputCorrect() && passwordStrong) { Supplier sup = new Supplier(); sup.setSupplierID(idTextBox.Text); sup.setSupplierName(supplierNameTextBox.Text); sup.setContectNo(supplierContactNoTextBox.Text); sup.setEmail(emailTextBox.Text); sup.setAddress(supplierAddressTextBox.Text); sup.setPassword(Security.getHash(passwordTextBox.Text, "SHA512", null)); if (perfumeRadioButton.Checked) { sup.setProductCategory("Perfume"); } else if (packageRadioButton.Checked) { sup.setProductCategory("Package"); } else if (bottleRadioButton.Checked) { sup.setProductCategory("Bottle"); } int i = sda.insert(sup, conn); if (i > 0) { supplierListDataGridView.Rows.Add(false, sup.getSupplierID(), sup.getSupplierName(), ((sup.getProductCategory().Equals("Perfume")) ? rs.GetString("perfumeText") : ((sup.getProductCategory().Equals("Package")) ? rs.GetString("packageText") : rs.GetString("bottleText"))), sup.getContectNo(), sup.getEmail(), sup.getAddress()); supplierListDataGridView.ClearSelection(); foreach (DataGridViewRow row in supplierListDataGridView.Rows) { if (idTextBox.Text.Equals(row.Cells["supplierIDColumn"].Value.ToString())) { row.Selected = true; supplierListDataGridView.FirstDisplayedScrollingRowIndex = row.Index; } } deleteButton.Enabled = true; deselectAllButton.Enabled = true; selectAllButton.Enabled = true; addButton.Enabled = false; updateButton.Enabled = true; staffIdHintLabel.Visible = false; MessageBox.Show(rs.GetString("addSuccessMsg")); } else { MessageBox.Show(rs.GetString("failToAddMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private bool isInputCorrect() { bool correct = true; if (!perfumeRadioButton.Checked && !packageRadioButton.Checked && !bottleRadioButton.Checked) { supplierTypeErrorLabel.Visible = true; correct = false; } else { supplierTypeErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(supplierNameTextBox.Text) || !nameFormat.IsMatch(supplierNameTextBox.Text)) { supplierNameErrorLabel.Visible = true; correct = false; } else { supplierNameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(supplierContactNoTextBox.Text) || !phoneFormat.IsMatch(supplierContactNoTextBox.Text)) { supplierContactNoErrorLabel.ForeColor = Color.Red; correct = false; } else { supplierContactNoErrorLabel.ForeColor = SystemColors.ControlText; } if (string.IsNullOrWhiteSpace(emailTextBox.Text) || !FormatChecker.isValidEmail(emailTextBox.Text)) { emailErrorLabel.Text = rs.GetString("inputValidEmail"); emailErrorLabel.Visible = true; correct = false; } else { bool emailExist = false; List <Supplier> suppliers = sda.getAllSuppliers(conn); List <Supplier> deletedSuppliers = sda.getAllDeletedSuppliers(conn); if (!emailExist) { foreach (Supplier sup in suppliers) { if (!string.IsNullOrWhiteSpace(sup.getEmail()) && sup.getEmail().Equals(emailTextBox.Text)) { if (!string.IsNullOrWhiteSpace(sup.getSupplierID()) && !sup.getSupplierID().Equals(idTextBox.Text)) { emailExist = true; break; } } } } if (!emailExist) { foreach (Supplier sup in deletedSuppliers) { if (!string.IsNullOrWhiteSpace(sup.getEmail()) && sup.getEmail().Equals(emailTextBox.Text)) { if (!string.IsNullOrWhiteSpace(sup.getSupplierID()) && !sup.getSupplierID().Equals(idTextBox.Text)) { emailExist = true; break; } } } } if (emailExist) { emailErrorLabel.Text = rs.GetString("emailExists"); emailErrorLabel.Visible = true; correct = false; } else { emailErrorLabel.Text = " "; emailErrorLabel.Visible = false; } } if (string.IsNullOrWhiteSpace(supplierAddressTextBox.Text)) { supplierAddressErrorLabel.Visible = true; correct = false; } else { supplierAddressErrorLabel.Visible = false; } return(correct); }
private bool isInputCorrect() { bool correct = true; if (string.IsNullOrWhiteSpace(categoryComboBox.Text)) { categoryErrorLabel.Visible = true; correct = false; } else { categoryErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(englishNameTextBox.Text)) { englishNameErrorLabel.Visible = true; correct = false; } else { englishNameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(tChineseNameTextBox.Text) || !FormatChecker.includeChineseChar(tChineseNameTextBox.Text)) { tChineseNameErrorLabel.Visible = true; correct = false; } else { tChineseNameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(quantityTextBox.Text) || !(int.Parse(quantityTextBox.Text) >= 500)) { quantityErrorLabel.ForeColor = Color.Red; correct = false; } else { quantityErrorLabel.ForeColor = SystemColors.ControlText; } if (string.IsNullOrWhiteSpace(priceTextBox.Text) || !(int.Parse(priceTextBox.Text) > 0 && int.Parse(priceTextBox.Text) <= 100)) { priceErrorLabel.ForeColor = Color.Red; correct = false; } else { priceErrorLabel.ForeColor = SystemColors.ControlText; } if (string.IsNullOrWhiteSpace(engDescTextBox.Text)) { engDescErrorLabel.Visible = true; correct = false; } else { engDescErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(tChiDescTextBox.Text) || !FormatChecker.includeChineseChar(tChiDescTextBox.Text)) { tChiDescErrorLabel.Visible = true; correct = false; } else { tChiDescErrorLabel.Visible = false; } if (productPhotoBox.Image == null) { photoErrorLabel.ForeColor = Color.Red; correct = false; } else { photoErrorLabel.ForeColor = SystemColors.ControlText; } return(correct); }
private void updateButton_Click(object sender, EventArgs e) { bool correct = true; if (string.IsNullOrWhiteSpace(customerSurnameTextBox.Text)) { customerSurnameErrorLabel.Visible = true; correct = false; } else { customerSurnameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(customerGivenNameTextBox.Text)) { customerGivenNameErrorLabel.Visible = true; correct = false; } else { customerGivenNameErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(emailTextBox.Text) || !FormatChecker.isValidEmail(emailTextBox.Text)) { emailErrorLabel.Visible = true; correct = false; } else { emailErrorLabel.Visible = false; } int mobilePhoneNo; if (string.IsNullOrWhiteSpace(mobilePhoneNoTextBox.Text) || !int.TryParse(mobilePhoneNoTextBox.Text, out mobilePhoneNo)) { mobilePhoneNoErrorLabel.Visible = true; correct = false; } else { mobilePhoneNoErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(customerAddressTextBox.Text)) { customerAddressErrorLabel.Visible = true; correct = false; } else { customerAddressErrorLabel.Visible = false; } if (correct) { Customer customer = cda.getOneCustomerByID(idTextBox.Text, Language.getLanguageCode(), conn); customer.setCustomerSurname(customerSurnameTextBox.Text); customer.setCustomerGivenName(customerGivenNameTextBox.Text); customer.setEmail(emailTextBox.Text); customer.setAgeGroupCode((int)ageComboBox.SelectedValue); customer.setAgeGroup(ageComboBox.Text); customer.setGender((maleRadioButton.Checked) ? 'M' : 'F'); customer.setRegeionCode((int)regionCodeComboBox.SelectedValue); customer.setMobilePhoneNo(int.Parse(mobilePhoneNoTextBox.Text)); customer.setAddress(customerAddressTextBox.Text); int i = cda.update(customer, conn); if (i > 0) { foreach (DataGridViewRow row in customerListDataGridView.Rows) { if (idTextBox.Text.Equals(row.Cells["customerIDColumn"].Value.ToString())) { row.Cells["customerNameColumn"].Value = customer.getCustomerSurname().ToUpper() + " " + customer.getCustomerGivenName(); row.Cells["customerEmailColumn"].Value = customer.getEmail(); row.Cells["customerAgeColumn"].Value = customer.getAgeGroup(); row.Cells["genderColumn"].Value = (customer.getGender().Equals('M') ? maleRadioButton.Text : femaleRadioButton.Text); row.Cells["customerMobilePhoneNoColumn"].Value = "+" + customer.getRegeionCode() + "-" + customer.getMobilePhoneNo(); row.Cells["customerAddressColumn"].Value = customer.getAddress(); } } MessageBox.Show(rs.GetString("updateSuccessMsg")); } else { MessageBox.Show(rs.GetString("failToUpdateMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }