Example #1
0
        private void AFP_Add_Flight_Button_Click(object sender, EventArgs e)
        {
            int    warning = 0;
            int    nameV   = 0;
            string fids    = "";

            fids     = AFP_FIDTB.Text;
            fName    = AFP_Flight_Name_Box.Text;
            des      = AFP_DestinationBox.Text;
            dep      = AFP_DepertureBox.Text;
            date     = AFP_Date.Value.ToString("dd-MM-yyyy");
            time     = AFP_Time.Value.ToString("H:mm");
            availES  = AFP_AvailESB.Text;
            availBS  = AFP_AvailBSB.Text;
            ecoCost  = AFP_EcoCostBox.Text;
            bsnsCost = AFP_BsnsCostBox.Text;

            bool allDigitAES = availES.All(char.IsDigit);
            bool allDigitABS = availBS.All(char.IsDigit);
            bool allDigitEC  = ecoCost.All(char.IsDigit);
            bool allDigitBC  = bsnsCost.All(char.IsDigit);
            bool allDigitFID = fids.All(char.IsDigit);
            int  availES2I   = 0;
            int  availBS2I   = 0;
            int  ecoCost2I   = 0;
            int  bsnsCost2I  = 0;

            if ((fName == "") || (des == "") || (dep == "") || (date == "") || (time == "") || (availES == "") || (availBS == "") || (ecoCost == "") || (bsnsCost == "") || (fids == ""))
            {
                MessageBox.Show("Can't skip any field!!! Fill up all to proceed!");
            }
            else
            {
                if (allDigitAES == false)
                {
                    MessageBox.Show("Number of Economy seat is invalid");
                    warning = 1;
                }
                else
                {
                    availES2I = Convert.ToInt32(availES);
                }

                if (allDigitFID == false)
                {
                    MessageBox.Show("Number of Economy seat is invalid");
                    warning = 1;
                }
                else
                {
                    fID = Convert.ToInt32(fids);
                }

                if (allDigitABS == false)
                {
                    MessageBox.Show("Number of Business seat is invalid");
                    warning = 2;
                }
                else
                {
                    availBS2I = Convert.ToInt32(availBS);
                }

                if (allDigitEC == false)
                {
                    MessageBox.Show("Economy Seeat Amount is invalid");
                    warning = 3;
                }
                else
                {
                    ecoCost2I = Convert.ToInt32(ecoCost);
                }

                if (allDigitBC == false)
                {
                    MessageBox.Show("Business Seat Amount is invalid");
                    warning = 4;
                }
                else
                {
                    bsnsCost2I = Convert.ToInt32(bsnsCost);
                }

                if (Regex.IsMatch(des, @"^[a-zA-Z]+$") == true) //all character
                {
                    //MessageBox.Show("All are letters");
                }
                else
                {
                    MessageBox.Show("Not a valid Destination!");
                    warning = 5;
                }

                if (Regex.IsMatch(dep, @"^[a-zA-Z]+$") == true) //all character
                {
                    //MessageBox.Show("All are letters");
                }
                else
                {
                    MessageBox.Show("Not a valid Departure!");
                    warning = 6;
                }

                if (Regex.IsMatch(fName, @"^[a-zA-Z ]{2,30}$") == true)
                {
                    //MessageBox.Show("valid name no number upto 30!");
                    nameV = 1;
                }
                else
                {
                    //MessageBox.Show("Invalid name");
                    warning = 1;
                }

                if (nameV == 0)
                {
                    if (Regex.IsMatch(fName, @"^[a-zA-Z ]{2,26}[0-9]{1,4}$") == true)
                    {
                        //MessageBox.Show("at first letter then number up to 5");
                        warning = 0;
                    }
                    else
                    {
                        MessageBox.Show("Invalid name");
                        warning = 1;
                    }
                }
            }

            if (status == "Add")
            {
                if (warning == 0)
                {
                    Flight_Detail fdT = new Flight_Detail
                    {
                        Flight_ID          = fID,
                        Flight_Name        = fName,
                        Destination        = des,
                        Departure          = dep,
                        Date               = date,
                        Time               = time,
                        Available_Seat_E_  = availES2I,
                        Available_Seat_B_  = availBS2I,
                        Economy_Cost_BDT_  = ecoCost2I,
                        Business_Cost_BDT_ = bsnsCost2I
                    };

                    aFPD.Flight_Details.InsertOnSubmit(fdT);
                    aFPD.SubmitChanges();

                    this.Hide();
                    apDGV.DataSource = aFPD.Flight_Details;

                    MessageBox.Show("Flight Added Successfully");
                }
            }
            else if (status == "Update")
            {
                var x = from a in aFPD.Flight_Details
                        where a.Flight_ID == flightListNo
                        select a;
                if (warning == 0)
                {
                    x.First().Flight_Name        = fName;
                    x.First().Destination        = des;
                    x.First().Departure          = dep;
                    x.First().Date               = date;
                    x.First().Time               = time;
                    x.First().Available_Seat_E_  = availES2I;
                    x.First().Available_Seat_B_  = availBS2I;
                    x.First().Economy_Cost_BDT_  = ecoCost2I;
                    x.First().Business_Cost_BDT_ = bsnsCost2I;

                    aFPD.SubmitChanges();

                    apDGV.DataSource = aFPD.Flight_Details;

                    MessageBox.Show("Flight Updated Successfully");

                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Something wnt wrong");
                }
            }
        }
 partial void UpdateFlight_Detail(Flight_Detail instance);
 partial void DeleteFlight_Detail(Flight_Detail instance);
 partial void InsertFlight_Detail(Flight_Detail instance);