Example #1
0
 private bool action(string act)
 {
     try
     {
         if (tbDeparture.Text.Trim() != tbDestination.Text.Trim())
         {
             var check = dc.Routes.Where(i => i.RouteDeparture == Convert.ToInt32(tbDeparture.Text.Trim()) && i.RouteDestination == Convert.ToInt32(tbDestination.Text.Trim())).ToList();
             if (check.Count == 0)
             {
                 using (TransactionScope ts = new TransactionScope())
                 {
                     rt = act == "insert" ? new Route() : dc.Routes.FirstOrDefault(id => id.Id == Convert.ToInt32(lbIdValue.Text));
                     rt.RouteDeparture = Convert.ToInt32(tbDeparture.Text.Trim());
                     rt.RouteDestination = Convert.ToInt32(tbDestination.Text.Trim());
                     if (act == "insert")
                         dc.Routes.InsertOnSubmit(rt);
                     dc.SubmitChanges();
                     ts.Complete();
                     if (act != "insert")
                     {
                         lbIdValue.Text = "";
                         lbIdValue.Visible = false;
                         lbID.Visible = false;
                         bCancel.Visible = false;
                     }
                     tbDeparture.ResetText();
                     tbDepartureNameLocation.ResetText();
                     tbDestination.ResetText();
                     tbDestinationNameLocation.ResetText();
                     return true;
                 }
             }
             else
             {
                 MessageBox.Show("The route is already exists", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                 return false;
             }
         }
         else
         {
             MessageBox.Show("Departure and Destination must be different", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             return false;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         return false;
     }
 }
Example #2
0
        private bool DeleteRoute()
        {
            DialogResult dr = MessageBox.Show("Are you sure to delete this Route ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                try
                {
                    rt = dc.Routes.Single(x => x.Id == Convert.ToInt32(dgRoute.CurrentRow.Cells[0].Value));
                    using (TransactionScope ts = new TransactionScope())
                    {
                        if (rt != null)
                        {
                            dc.Routes.DeleteOnSubmit(rt);
                            dc.SubmitChanges();
                            ts.Complete();
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
		private void detach_Routes1(Route entity)
		{
			this.SendPropertyChanging();
			entity.Venue1 = null;
		}
		private void attach_Routes1(Route entity)
		{
			this.SendPropertyChanging();
			entity.Venue1 = this;
		}
 partial void DeleteRoute(Route instance);
 partial void UpdateRoute(Route instance);
 partial void InsertRoute(Route instance);