예제 #1
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            model.First_Name = textFName.Text.Trim();
            model.Last_Name  = textLName.Text.Trim();
            model.Birthday   = textBirthday.Text.Trim();
            model.City       = textCity.Text.Trim();
            model.Phone      = textPhone.Text.Trim();
            model.E_mail     = textMail.Text.Trim();

            using (RailwayDbEntities db = new RailwayDbEntities())
            {
                if (model.CustomerID == 0)
                {
                    db.Customers.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            Clear();
            PopulateDataGrid();
            MessageBox.Show("Submitted Succesfully !");
        }
 public Ticket_Reservation()
 {
     InitializeComponent();
     db = new RailwayDbEntities();
     BindDeparture();
     BindArrival();
 }
예제 #3
0
 void PopulateDataGrid()
 {
     dataCustomer.AutoGenerateColumns = false;
     using (RailwayDbEntities db = new RailwayDbEntities())
     {
         dataCustomer.DataSource = db.Customers.ToList <Customer>();
         foreach (var item in db.Customers.ToList <Customer>())
         {
             model.First_Name = item.First_Name;
         }
     }
 }
예제 #4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete ?", "Delete Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (RailwayDbEntities db = new RailwayDbEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Customers.Attach(model);
             }
             db.Customers.Remove(model);
             db.SaveChanges();
             PopulateDataGrid();
             Clear();
             MessageBox.Show("Deleted Successfully !");
         }
     }
 }
예제 #5
0
 private void dataCustomer_DoubleClick(object sender, EventArgs e)
 {
     if (dataCustomer.CurrentRow.Index != -1)
     {
         model.CustomerID = Convert.ToInt32(dataCustomer.CurrentRow.Cells["CustomerID"].Value);
         using (RailwayDbEntities db = new RailwayDbEntities())
         {
             model             = db.Customers.Where(x => x.CustomerID == model.CustomerID).FirstOrDefault();
             textFName.Text    = model.First_Name;
             textLName.Text    = model.Last_Name;
             textBirthday.Text = model.Birthday;
             textCity.Text     = model.City;
             textPhone.Text    = model.Phone;
             textMail.Text     = model.E_mail;
         }
         btnInsert.Text    = "Update";
         btnDelete.Enabled = true;
     }
 }
예제 #6
0
        private void button_login_Click(object sender, EventArgs e)
        {
            try
            {
                //common.Logger.OpenLogger();
                RailwayDbEntities db = new RailwayDbEntities();
                if (usr_txt.Text != string.Empty && pass_txt.Text != string.Empty)
                {
                    var user = db.Admins.Where(a => a.Username.Equals(usr_txt.Text.Trim())).SingleOrDefault();
                    if (user != null)
                    {
                        if (user.Password.Equals(pass_txt.Text))
                        {
                            MessageBox.Show("Logged in successfully as Admin !");
                            this.Visible = false;
                            Home obj1 = new Home();
                            obj1.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Wrong Password !");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong Username !");
                    }
                }
                else
                {
                    MessageBox.Show("Please insert Username & Password !");
                }

                // common.Logger.CloseLogger();
            }
            catch (Exception ex)
            {
                error     = ex.Message;
                errorTime = DateTime.Now; //exception time
                LogErMsg();               //Call the error information method
                MessageBox.Show("Error ! Please check the error log !");
            }
        }
예제 #7
0
 public RoutesInfo()
 {
     InitializeComponent();
     db = new RailwayDbEntities();
 }