protected void Add_Click(object sender, EventArgs e)
        {
            var isValid = Validation(sender, e);

            if (isValid)
            {
                bool found = false;
                foreach (var item in Employee)
                {
                    if (item.ID == int.Parse(ID.Text))
                    {
                        found = true;
                    }
                }
                if (found)
                {
                    ShowMessage("Record already exists.", "alert alert-info");
                }
                else
                {
                    Employee newitem = new Employee(int.Parse(ID.Text), Name.Text, Phone.Text);
                    Employee.Add(newitem);
                    EmployeeGridView.DataSource = Employee;
                    EmployeeGridView.DataBind();
                    ShowMessage("Record added.", "alert alert-success");
                }
            }
        }
Beispiel #2
0
 //Method used when one of the events on the page is updating the table and query
 private void Binding(DataView view)
 {
     //Sets the datasource of the webpage's Gridview to the TableBase object's returned Dataview from event methods.
     EmployeeGridView.DataSource = view;
     //Calls for the page to be updated and a postback
     EmployeeGridView.DataBind();
 }
Beispiel #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            /*string connectionString = ConfigurationManager
             *  .ConnectionStrings["SqlSqlConnection"].ConnectionString;
             *
             * using (SqlConnection con = new SqlConnection(connectionString))
             * {
             *  using (SqlCommand cmd = new SqlCommand())
             *  {
             *      cmd.CommandText = "SELECT * FROM Employees";
             *      cmd.Connection = con;
             *      con.Open();
             *      GridView1.DataSource = cmd.ExecuteReader();
             *      GridView1.DataBind();
             *  }
             * }*/

            // Since I do not have database, I've to manually populate the data here.
            EmployeeGridView.DataSource = new List <Employee>
            {
                new Employee {
                    Id = 1, FirstName = "John", LastName = "Doe"
                },
                new Employee {
                    Id = 2, FirstName = "Janet", LastName = "Doe"
                },
                new Employee {
                    Id = 3, FirstName = "Eric", LastName = "Newton"
                }
            };
            EmployeeGridView.DataBind();
        }
    }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var data = RecordsRepository.GetRepository().GetAllRecords();

                EmployeeGridView.DataSource = data;
                EmployeeGridView.DataBind();
            }
        }
Beispiel #5
0
        protected void EmployeeGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var id = long.Parse(EmployeeGridView.DataKeys[e.RowIndex].Value.ToString());

            RecordsRepository.GetRepository().DelRecord(id);
            var data = RecordsRepository.GetRepository().GetAllRecords();

            EmployeeGridView.DataSource = data;
            EmployeeGridView.DataBind();
            EmployeeGridView.Visible = true;
            FilePersistence.SaveRecords();
        }
Beispiel #6
0
        protected void SortBySurnameAndBirthYear_Click(object sender, EventArgs e)
        {
            var data = RecordsRepository.GetRepository().GetAllRecords();

            IList <EmployeeRecord> result = data.OrderBy(x => x.Surname).ThenBy(x => x.YearOfBirth).ToList();

            data = result;

            EmployeeGridView.DataSource = data;
            EmployeeGridView.DataBind();
            EmployeeGridView.Visible = true;
        }
Beispiel #7
0
 /// <summary>
 /// This Method Populates/Refreshes the list of drivers
 ///     There are two types of drivers:
 ///         1. Truck  Drivers
 ///         2. Equipment Drivers
 /// </summary>
 /// <param name="type">The type specifies the list of drivers to be returned</param>
 protected void RefreshDriverList(int type)
 {
     InfoUserControl.TryRun(() =>
     {
         int unitId = int.Parse(SelectUnitDDL.SelectedValue);
         int yardId = int.Parse(YardID.Text);
         FleetController fleetManager = new FleetController();
         List <Driver> drivers        = fleetManager.GetTruckDrivers(yardId, unitId, type);
         EmployeeGridView.DataSource  = drivers;
         EmployeeGridView.DataBind();
     });
 }
Beispiel #8
0
        /// <summary>
        /// This event fires when the user select a unit category (Equipment/truck)
        ///     It resets the EmployeeGirwView to null
        ///     It turns Off all button controls
        ///     It populates the list of Units (Equipment/Truck) in the DrompDownList control
        /// </summary>
        /// <param name="sender">the sender is a RadioButtonList</param>
        /// <param name="e"></param>
        protected void FleetCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            int             yardId = int.Parse(YardID.Text);
            FleetController fleet  = new FleetController();

            string category = (FleetCategory.SelectedItem.Text).Trim();

            if (category == "Equipments")
            {
                EmployeeGridView.DataSource = null;
                EmployeeGridView.DataBind();
                EmployeeGridView.Visible = false;
                CreateCrew.Visible       = false;
                Done.Visible             = false;
                Cancel.Visible           = true;
                CrewID.Text = "";
                MessageUserControl.TryRun(() =>
                {
                    List <Equipment> equipments  = fleet.GetEquipments(yardId);
                    SelectUnitDDL.DataSource     = equipments;
                    SelectUnitDDL.DataTextField  = nameof(Equipment.Description);
                    SelectUnitDDL.DataValueField = nameof(Equipment.EquipmentID);
                    SelectUnitDDL.Visible        = true;
                    SelectUnitDDL.DataBind();
                    SelectUnitDDL.Items.Insert(0, "Select an Equipment");
                });
            }
            else if (category == "Trucks")
            {
                EmployeeGridView.DataSource = null;
                EmployeeGridView.DataBind();
                EmployeeGridView.Visible = false;
                CreateCrew.Visible       = false;
                Done.Visible             = false;
                Cancel.Visible           = true;
                CrewID.Text = "";
                MessageUserControl.TryRun(() =>
                {
                    List <Truck> units           = fleet.GetTrucks(yardId);
                    SelectUnitDDL.DataSource     = units;
                    SelectUnitDDL.DataTextField  = nameof(Truck.TruckDescription);
                    SelectUnitDDL.DataValueField = nameof(Truck.TruckID);
                    SelectUnitDDL.Visible        = true;
                    SelectUnitDDL.DataBind();
                    SelectUnitDDL.Items.Insert(0, "Select a Truck");
                });
            }
        }
Beispiel #9
0
 /// <summary>
 /// This method Populates/refreshes the list all employee for selction
 ///     It turns On/Off all necessary/unnecessary column(s) on the EmployeeGridView
 /// </summary>
 protected void RefreshCrewMember()
 {
     MessageUserControl.TryRun(() =>
     {
         //Retrieve all employees
         EmployeeController EmployeeManager = new EmployeeController();
         List <Driver> employees            = EmployeeManager.GetEmployees(int.Parse(YardID.Text));
         employees.Sort((x, y) => x.Name.CompareTo(y.Name));
         EmployeeGridView.DataSource = employees;
         EmployeeGridView.DataBind();
         EmployeeGridView.Columns[4].Visible = false;
         EmployeeGridView.Columns[5].Visible = false;
         EmployeeGridView.Columns[6].Visible = false;
         EmployeeGridView.Columns[7].Visible = true;
         EmployeeGridView.Visible            = true;
     });
 }
Beispiel #10
0
        protected void EmployeeGridView_Sorting(object sender, GridViewSortEventArgs e)
        {
            var data = RecordsRepository.GetRepository().GetAllRecords();

            if (e.SortExpression == "Surname")
            {
                IList <EmployeeRecord> result = data.OrderBy(x => x.Surname).ToList();
                data = result;
            }
            if (e.SortExpression == "YearOfBirth")
            {
                IList <EmployeeRecord> result = data.OrderBy(x => x.YearOfBirth).ToList();
                data = result;
            }

            EmployeeGridView.DataSource = data;
            EmployeeGridView.DataBind();
            EmployeeGridView.Visible = true;
        }
Beispiel #11
0
 protected void BindData()
 {
     log.Debug("Binding the employee Grid view. Function BindData from DefinePermissionsByUser.apsx page");
     EmployeeGridView.DataBind();
 }
Beispiel #12
0
 //Method used when the page is intially called and loaded
 private void Binding()
 {
     //Sets the datasource of the webpage's Gridview to the TableBase object's returned DataView
     EmployeeGridView.DataSource = Base.BindGrid();
     EmployeeGridView.DataBind();  //Calls for the page to be updated and a postback
 }