|
#region DotNet Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
#endregion
#region Custom Namespaces
using CommonEnums = EHS.CommonDataHelpers.Enums;
using ServiceLayer;
using BEs.Person;
using EHS.CommonDataHelpers.Enums;
using BEs.Engin;
using BEs.Enums;
using BEs.Car;
#endregion
namespace DataEntry
{
public partial class _Default : System.Web.UI.Page
{
#region Protected Events
#region Common Events
#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
//Fill the Drop Down lists in the person tab
this.FillDropDownListsPersonTab();
}
#endregion
#region DataEntry_ActiveTabChanged
protected void DataEntry_ActiveTabChanged(object sender, EventArgs e)
{
if (this.DataEntry.ActiveTabIndex == 0)
{
if(!this.IsPostBack)
//This method will fill the drop down lists in the person tab
this.FillDropDownListsPersonTab();
}
else if (this.DataEntry.ActiveTabIndex == 2)
//This method will fill the drop down lists in the car tab
this.FillDropDownListsCar();
else if(this.DataEntry.ActiveTabIndex == 3)
{
//Binding the data taken from the database to the grid view 'gvAllCarsWithDetails'
this.gvAllCarsWithDetails.DataSource = new CommonServices().CarGetAllCarDetails();
this.gvAllCarsWithDetails.DataBind();
}
}
#endregion
#endregion
#region Person Events
#region btnAddData_Click
protected void btnAddData_Click(object sender, EventArgs e)
{
//Adding the new person to the database and get the status of the transaction
this.lblPersonMessage.Text = new CommonServices().Person_Insert(this.FillPerson()).Message;
}
#endregion
#region btnClearPerson_Click
protected void btnClearPerson_Click(object sender, EventArgs e)
{
//To Clear the person tab page
this.ddlTitle.SelectedIndex = 0;
this.txtFullName.Text = string.Empty;
this.txtAge.Text = string.Empty;
this.txtAddress.Text = string.Empty;
this.ddlStatus.SelectedIndex = 0;
this.lblPersonMessage.Text = string.Empty;
}
#endregion
#endregion
#region Engin Events
#region btnAddEnginData_Click
protected void btnAddEnginData_Click(object sender, EventArgs e)
{
//To fill the new engin object with the data you entered
Engin objEngin = new Engin()
{
Description = this.txtEnginDescription.Text
};
//To enter the new engin to the database and get the status of the transaction
this.lblEnginMessage.Text = new CommonServices().Engin_Insert(objEngin).Message;
}
#endregion
#region btnClearEngin_Click
protected void btnClearEngin_Click(object sender, EventArgs e)
{
//To clear the Engin tab page
this.txtEnginDescription.Text = string.Empty;
this.lblEnginMessage.Text = string.Empty;
}
#endregion
#endregion
#region Car Events
#region btnAddCarData_Click
protected void btnAddCarData_Click(object sender, EventArgs e)
{
//To enter the new car to the database and the status of the transaction
this.lblCarMessage.Text = new CommonServices().Car_Insert(this.FillCar()).Message;
}
#endregion
#region btnClearCar_Click
protected void btnClearCar_Click(object sender, EventArgs e)
{
//To clear the car tab page
this.ddlCarOwner.SelectedIndex = 0;
this.txtCarDescription.Text = string.Empty;
this.ddlCarType.SelectedIndex = 0;
this.ddlCarEnginId.SelectedIndex = 0;
this.ddlCarColour.SelectedIndex = 0;
this.txtCarUsage.Text = string.Empty;
}
#endregion
#endregion
#endregion
#region Private Methods
#region Person
#region FillDropDownListsPersonTab
private void FillDropDownListsPersonTab()
{
this.ddlTitle.Items.Clear();
this.ddlStatus.Items.Clear();
string[] titleCollection = new string[] { CommonEnums.Title.Miss.ToString(), CommonEnums.Title.Mr.ToString(), CommonEnums.Title.Mrs.ToString() };
string[] statusCollection = new string[] { CommonEnums.Status.Active.ToString(), CommonEnums.Status.Inactive.ToString() };
foreach (string title in titleCollection)
this.ddlTitle.Items.Add(title);
foreach (string status in statusCollection)
this.ddlStatus.Items.Add(status);
}
#endregion
#region FillPerson
//This method will fill the person object with new data you entered
private Person FillPerson()
{
Person objPerson = new Person()
{
Name = string.Format("{0}.{1}", this.ddlTitle.Text, this.txtFullName.Text),
Address = this.txtAddress.Text,
Status = (Status)this.ddlStatus.SelectedIndex,
Age = int.Parse(this.txtAge.Text)
};
return objPerson;
}
#endregion
#endregion
#region Car
#region FillDropDownListsCar
private void FillDropDownListsCar()
{
this.ddlCarColour.Items.Clear();
this.ddlCarType.Items.Clear();
string[] carColours = new string[] { Color.Aqua.ToString(), Color.Black.ToString(), Color.Blue.ToString(), Color.DarkCyan.ToString() };
string[] carTypes = new string[] { CarType.Bajaj.ToString(), CarType.Bens.ToString(), CarType.Toyota.ToString() };
foreach(string colour in carColours)
this.ddlCarColour.Items.Add(colour);
foreach (string carType in carTypes)
this.ddlCarType.Items.Add(carType);
this.FillCarOwnerDropDownList();
this.FillEnginDropDownList();
}
#endregion
#region FillCarOwnerDropDownList
private void FillCarOwnerDropDownList()
{
//To get all the people in database
People objPeople = new CommonServices().Person_GetAll();
//Binding the people object to the drop down list
this.ddlCarOwner.DataSource = objPeople;
this.ddlCarOwner.DataBind();
}
#endregion
#region FillEnginDropDownList
private void FillEnginDropDownList()
{
Engins objEngins = new CommonServices().Engin_GetAll();
this.ddlCarEnginId.DataSource = objEngins;
this.ddlCarEnginId.DataBind();
}
#endregion
#region FillCar
private Car FillCar()
{
Person objPerson = new Person()
{
ID = long.Parse(this.ddlCarOwner.SelectedValue),
IsReferenceData = true //To tell the system that this field is a forign key field
};
Engin objEngin = new Engin()
{
ID = int.Parse(this.ddlCarEnginId.SelectedValue),
IsReferenceData = true
};
Car objCar = new Car();
objCar.Engin = objEngin;
objCar.Owner = objPerson;
objCar.Color = this.ddlCarColour.Text;
objCar.Description = this.txtCarDescription.Text;
if (!string.IsNullOrEmpty(this.txtCarUsage.Text))
objCar.Usage = int.Parse(this.txtCarUsage.Text);
objCar.Type = (BEs.Enums.CarType)Enum.Parse(typeof(CarType), this.ddlCarType.Text);
return objCar;
}
#endregion
#endregion
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.