private void BindEmployeeFuel()
        {
            try
            {
                EmployeeFuel employeeFuel = EmployeeFuel.GetEmployeeFuelByEmployeeFuelId(this.employeeFuelId);
                DropDownListVehicle.Items.FindByValue(employeeFuel.VehicleId.ToString()).Selected = true;
                TextBoxDateOfFuel.Text = employeeFuel.DateOfFuel.ToString("yyyy/MM/dd");
                DropDownListPaymentType.Items.FindByValue(employeeFuel.PaymentTypeId.ToString()).Selected = true;
                TextBoxValue.Text     = employeeFuel.Value.ToString();
                TextBoxLitres.Text    = employeeFuel.Litres.ToString();
                TextBoxKMReading.Text = employeeFuel.KMReading.ToString();

                BindGridviewResult();
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
            catch (Exception exception)
            {
                LabelError.Text   += (exception.Message + "<br />");
                PanelError.Visible = true;
            }
        }
        protected void GridViewResult_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow currentRow = e.Row;

            //if (currentRow.RowIndex > 0)
            if (currentRow.RowType == DataControlRowType.DataRow)
            {
                EmployeeFuel employeeFuel = (EmployeeFuel)currentRow.DataItem;

                if (employeeFuel.Attachment.Length == 0)
                {
                    currentRow.Cells[7].ForeColor = System.Drawing.Color.White;
                    currentRow.Cells[7].Text      = "-";
                    currentRow.Cells[7].Enabled   = false;
                }
            }
        }
        protected void GridViewResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                switch (e.CommandName.ToLower())
                {
                case "removeemployeefuel":
                {
                    EmployeeFuel.DeleteEmployeeFuelByEmployeeFuelId(Convert.ToInt32(e.CommandArgument));
                    BindGridviewResult();
                    break;
                }

                case "viewattachment":
                {
                    EmployeeFuel employeeFuel = EmployeeFuel.GetEmployeeFuelByEmployeeFuelId(Convert.ToInt32(e.CommandArgument));

                    Response.Clear();
                    Response.ContentType = "image/jpg";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=FuelAttachment.jpg");
                    Response.TransmitFile(employeeFuel.Attachment);
                    Response.End();

                    break;
                }
                }
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                LabelError.Text = "";
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
        }
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                LabelError.Text    = "";
                PanelError.Visible = false;

                DateTime dateOfFuel;
                bool     isDate = DateTime.TryParse(TextBoxDateOfFuel.Text, out dateOfFuel);

                if (!isDate)
                {
                    LabelError.Text   += "Date Of Fuel is required.<br />";
                    PanelError.Visible = true;
                    return;
                }

                //EmployeeFuel currentEmployeeFuel = EmployeeFuel.GetEmployeeFuelByVehicleIdEmployeeId(Convert.ToInt32(DropDownListVehicle.SelectedValue), this.employeeId);

                //EmployeeVehicle employeeVehicle = new EmployeeVehicle();
                //employeeVehicle.EmployeeVehicleId = currentEmployeeFuel.EmployeeVehicleId;//Convert.ToInt32(ViewState["employeeVehicleId"]);
                //employeeVehicle.EmployeeId = this.employeeId;
                //employeeVehicle.VehicleId = Convert.ToInt32(DropDownListVehicle.SelectedValue);
                //employeeVehicle.ModifiedUser = this.Master.LoggedOnAccount;
                //employeeVehicle.Save();
                //ViewState["employeeVehicleId"] = (employeeVehicle.EmployeeVehicleId != 0) ? employeeVehicle.EmployeeVehicleId : this.employeeVehicleId;

                EmployeeVehicle employeeVehicle = EmployeeVehicle.GetEmployeeVehicleByEmployeeIdVehicleId(this.employeeId, Convert.ToInt32(DropDownListVehicle.SelectedValue));

                EmployeeFuel employeeFuel = new EmployeeFuel();
                employeeFuel.EmployeeFuelId    = this.employeeFuelId;//Convert.ToInt32(ViewState["employeeFuelId"]);
                employeeFuel.EmployeeVehicleId = employeeVehicle.EmployeeVehicleId;
                employeeFuel.DateOfFuel        = Convert.ToDateTime(TextBoxDateOfFuel.Text);
                employeeFuel.PaymentTypeId     = Convert.ToInt32(DropDownListPaymentType.SelectedValue);
                employeeFuel.Value             = Convert.ToDouble(TextBoxValue.Text);
                employeeFuel.Litres            = Convert.ToDouble(TextBoxLitres.Text);
                employeeFuel.KMReading         = Convert.ToDouble(TextBoxKMReading.Text);
                employeeFuel.ModifiedUser      = this.Master.LoggedOnAccount;
                employeeFuel.Attachment        = UploadAttachment();

                try
                {
                    employeeFuel.Save();
                    this.employeeFuelId = employeeFuel.EmployeeFuelId;

                    Button clickedButton = (Button)sender;
                    switch (clickedButton.ID)
                    {
                    case "ButtonSave":
                        Response.Redirect(String.Format("EmployeeEdit.aspx?employeeId={0}", this.employeeId));
                        break;

                    case "ButtonSaveNew":
                        Response.Redirect(String.Format("EmployeeFuelEdit.aspx?employeeId={0}&vehicleId={1}", this.employeeId, Convert.ToInt32(DropDownListVehicle.SelectedValue)));
                        //TextBoxValue.Text = "";
                        //TextBoxLitres.Text = "";
                        //TextBoxKMReading.Text = "";
                        //ViewState["employeeFuelId"] = "0";
                        //ViewState["employeeVehicleId"] = "0";
                        //BindGridviewResult();
                        break;
                    }
                }
                catch (System.Data.SqlClient.SqlException sqlEx)
                {
                    LabelError.Text = "";
                    for (int i = 0; i < sqlEx.Errors.Count; i++)
                    {
                        LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                    }
                    PanelError.Visible = true;
                }
            }
        }
 private void BindGridviewResult()
 {
     GridViewResult.DataSource = EmployeeFuel.GetEmployeeFuelList(this.employeeId);
     GridViewResult.DataBind();
 }