Пример #1
0
        private void button_save_Click(object sender, EventArgs e)
        {
            if (!CheckForm())
            {
                MessageBox.Show("Fill all the mandatory fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                City city = FormToCity();
                if (city.ID == 0)
                {
                    CityArr oldCityArr = new CityArr();
                    oldCityArr.Fill();
                    if (!oldCityArr.IsContain(city.CityName))
                    {
                        if (city.Insert())
                        {
                            MessageBox.Show("Thank you for you registration!");
                            CityArr cityArr = new CityArr();
                            cityArr.Fill();
                            city = cityArr.GetCityWithMaxId();
                            CityArrToForm(city);
                        }

                        else
                        {
                            MessageBox.Show("Couldn't add the city", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    else
                    {
                        MessageBox.Show("City already existing");
                    }
                }

                else
                {
                    if (city.Update())
                    {
                        MessageBox.Show("Update succesfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        CityArrToForm(city);
                    }

                    else
                    {
                        MessageBox.Show("Couldn't update the city", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #2
0
 private void button_save_Click(object sender, EventArgs e)
 {
     if (!CheckGood())
     {
         MessageBox.Show("You didn't write right", "TRY AGAIN", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
         All_White();
     }
     else
     {
         City city = FormToCity();
         if (city.ID == 0)
         {
             CityArr oldCityArr = new CityArr();
             oldCityArr.Fill();
             if (!oldCityArr.IsContain(city.CityName))
             {
                 if (city.Insert())
                 {
                     MessageBox.Show("City Details Saved");
                     Clean_Form();
                     CityArr cityArr = new CityArr();
                     cityArr.Fill();
                     city = cityArr.GetCityWithMaxId();
                     CityArrToForm(city);
                 }
                 else
                 {
                     MessageBox.Show("Cannot Save City Details");
                 }
             }
             else
             {
                 MessageBox.Show("City already existing");
             }
         }
         else
         {
             if (city.Update())
             {
                 MessageBox.Show("City Details UPDATED");
                 Clean_Form();
                 CityArrToForm(null);
             }
             else
             {
                 MessageBox.Show("Cannot UPDATE City Details");
             }
         }
     }
 }
Пример #3
0
        private void SaveButtonClick(object sender, EventArgs e)
        {
            //Client client = new Client();

            if (!CheckForm())
            {
                MessageBox.Show("נא מלא את הפרטים החסרים", "השלמת פרטים", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                City city = FormToCity();
                if (city.ID == 0)
                {
                    //ללקוח יש מזהה אפס – זהו לקוח חדש )טרם נוצרה לו רשומה באקסס ולכן עדיין לא קיבל מספור אוטומטי של המזהה(.
                    //הוספת לקוח חדש

                    if (city.Insert())
                    {
                        MessageBox.Show("הוסף בהצלחה", "הוספת עיר", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        MessageBox.Show("שגיאה בהוספה", "הוספת עיר", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    CityArr cityArr = new CityArr();
                    cityArr.Fill();
                    city = cityArr.GetCityWithMaxId();
                }
                else
                {
                    //עדכון לקוח קיים

                    if (city.Update())
                    {
                        MessageBox.Show("עודכן בהצלחה", "עידכון עיר", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        //כיוון שמדובר על ישוב חדש, ניעזר במזהה הגבוה ביותר = הישוב האחרון שנוסף לטבלה
                        CityArr cityArr = new CityArr();
                        cityArr.Fill();
                        city = cityArr.GetCityWithMaxId();
                    }
                    else
                    {
                        MessageBox.Show("שגיאה בהוספה", "עידכון עיר", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                CityArrToForm(city);
            }
        }
Пример #4
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (CheckForm())
            {
                City city = new City();
                city = FormToCity();

                CityArr oldCityArr = new CityArr();
                oldCityArr.Fill();

                if (!oldCityArr.IsContain(city.Name))
                {
                    if (city.Id == 0)
                    {
                        if (city.Insert())
                        {
                            MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            CityArr cityArr = new CityArr();
                            cityArr.Fill();
                            city = cityArr.GetCityWithMaxId();

                            CityArrToForm(city);
                        }
                    }
                    else
                    {
                        if (city.Update())
                        {
                            MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            CityArr cityArr = new CityArr();
                            cityArr.Fill();
                            city = cityArr.GetCityWithMaxId();
                            CityArrToForm(city);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("City already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ClearForm();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Check the final data on the form and if it is ok, then it sends the data to the database.
        /// </summary>
        private void Button_Save_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult;

            if (!CheckForm())
            {
                //The entered information is not valid.
                dialogResult = MessageBox.Show("המידע שסיפקת אינו תקין.\nאנא תקן את השדות האדומים על מנת להמשיך", "אזהרה", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            }

            else
            {
                //The information was valid

                City city = FormToCity();//Make a city object from the information on the form.

                if (city.Id == 0)
                {
                    CityArr oldCityArr = new CityArr();
                    oldCityArr.Fill();
                    if (!oldCityArr.IsContains(city.Name))
                    {
                        if (city.Insert())//Try to insert the new city to the database.
                        {
                            //The insertion of the city data was successfull.
                            CityArr cityArr = new CityArr();
                            cityArr.Fill();
                            CityArrToForm(cityArr.GetCityWithMaxId());
                            dialogResult = MessageBox.Show("העיר נוספה בהצלחה", "יאי!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                        }
                        else
                        {
                            //There was a problem insreting the data to the database.
                            dialogResult = MessageBox.Show("קרתה תקלה בעת שמירת העיר בבסיס הנתונים", "תקלה", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                        }
                    }
                    else
                    {
                        dialogResult = MessageBox.Show("העיר שאתה מנסה להוסיף כבר קיימת במערכת!", "הפעולה נמנעה", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                    }
                }
                else
                {
                    if (textBox_Name.Text != SelectedCity.Name)
                    {
                        if (city.Update())
                        {
                            CityArr cityArr = new CityArr();
                            cityArr.Fill();
                            CityArrToForm(cityArr.GetCityWithMaxId());
                            dialogResult = MessageBox.Show("העיר עודכנה בהצלחה", "יאי!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                        }
                        else
                        {
                            dialogResult = MessageBox.Show("קרתה תקלה בעת עדכון העיר בבסיס הנתונים", "תקלה", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                        }
                    }
                    else
                    {
                        dialogResult = DialogResult.OK;
                    }
                }
            }

            //MessageBox results actions:
            switch (dialogResult)
            {
            case DialogResult.OK:    //Do nothing
                break;

            case DialogResult.Cancel:    //Clear all of the text and "restart".
            {
                CityToForm(null);
                break;
            }

            case DialogResult.Abort:    //Close the form
            {
                Environment.Exit(0);
                break;
            }

            case DialogResult.Retry:
            {
                Button_Save_Click(null, null);        //Try again.
                break;
            }

            case DialogResult.Ignore:    //Do nothing.
                break;

            default:
                break;
            }
        }//<<<<<<<<<<<<<<<<<<-------------------------