private async void changeName_Click(object sender, EventArgs e) // This method run when changeName button clicked { logCreate.Visible = true; // Unvisable log info logCreate.Text = "Checking for empty gaps"; // Inform user about current operation if (newName.Text == "") // If new name is empty { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.emptyGap(), appErrors.textError(), // Inform user about some empty gap MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon of messagebox } else // Else { logCreate.Text = "Checking code"; // Inform user about current operation var asyncControl = await checkCodeExist(newName.Text); // This variable store value returned by checkCodeExist async method if (asyncControl == 0) // If asyncControl value is 0 { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.noInternet(), appErrors.webError(), // Inform user about no internet connection MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 1) // If asyncControl value is 1 { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.databaseFail(), appErrors.databaseError(), // Inform user about error while working in database MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 2) // If asyncControl value is 2 { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.codeExist(), appErrors.databaseError(), // Inform user about code with this name exist MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 3) // If asyncControl value is 3 { logCreate.Text = "Updateing value"; // Inform user about current operation asyncControl = await updateValue("code_name", newName.Text); // This variable store value returned by async method updateValue as parameters send code_name and new value if (asyncControl == 0) // If asyncControl value is 0 { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.noInternet(), appErrors.webError(), // Inform user about no internet connection MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 1) // If asyncControl value is 1 { logCreate.Visible = false; // Unvisable log info MessageBox.Show(appErrors.databaseFail(), appErrors.databaseError(), // Inform user about error while working in database MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 2) // If asyncControl value is 2 { appFile.refreshTemporary(newName.Text); // Updateing temporary file logCreate.Visible = false; // Unvisable log info MessageBox.Show(appInfos.updateingFine(), appInfos.everythingFine(), // Inform user about successfull updateing MessageBoxButtons.OK, MessageBoxIcon.Information); // Set buttons and icon for messagebox } } } }
private async void createButton_Click(object sender, EventArgs e) // This method run when createButton clicked { logCreate.Visible = true; // Visiable log logCreate.Text = "Checking for empty gaps"; // inform user about current operation int asyncControl = await checkForSomeEmptyGaps(); // Seting asyncControl variable value as a value returned by async method checkForSomeEmptyGaps if (asyncControl == 0) // If asyncControl value is 0 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.emptyGap(), appErrors.textError(), // Inform user about some empty gaps MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox return; // Stoping create code } else // Else { logCreate.Text = "Checking for some replaced char codes"; // inform user about current operation asyncControl = await checkForSomeReplaceCode(); // Seting asyncControl variable value as a value returned by async method checkForSomeReplaceCode if (asyncControl == 0) // If asyncControl value is 0 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.codeReplace(), appErrors.textError(), // Inform user about same code given two times MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox return; // Stoping create code } else // Else { logCreate.Text = "Inserting new code to database"; // Inform user about current operation asyncControl = await insertNewCode(); // Seting asyncControl variable value as a value returned by async method insertNewCode if (asyncControl == 0) // If asyncControl value is 0 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.noInternet(), appErrors.webError(), // Inform user about no internet connection MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 1) // If asyncControl value is 1 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.databaseFail(), appErrors.databaseError(), // Inform user about some error while working in database MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 2) // If asyncControl value is 2 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.codeExist(), appErrors.databaseError(), // Inform user about code with given name already exist MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 3) // If asyncControl value is 3 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appErrors.insertFail(), appErrors.databaseError(), // Inform user about some error while inserting new code MessageBoxButtons.OK, MessageBoxIcon.Error); // Set buttons and icon for messagebox } else if (asyncControl == 4) // If asyncControl value is 4 { logCreate.Visible = false; // Unvisiable log MessageBox.Show(appInfos.insertingFine(), appInfos.everythingFine(), // Inform user about successfull operation MessageBoxButtons.OK, MessageBoxIcon.Information); // Set buttons and icon for messagebox) } } } }