Add page code
#region Using Directives
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ELearning.SystemCore.BLL.Object;
using ELearning.SystemCore.BLL;
using ELearning.Common;
#endregion
///
/// Summary description for UserControls_UCAddJob
///
public partial class UserControls_UCAddJob : System.Web.UI.UserControl
{
private int mode;
#region Public Properties
int _selectedJobId = 0;
public int SelectedJobId
{
get { return _selectedJobId; }
set { _selectedJobId = value; }
}
#endregion
#region Protected Methods
protected void Page_Load(object sender, EventArgs e)
{
ELearning.Common.Configuration.GetQueryStringValue("id", out _selectedJobId);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
if (!Page.IsPostBack)
InitializeControls();
}
#endregion
#region Public Methods
#endregion
#region Private Methods
private void InitializeControls()
{
try
{
ClearControls();
mode = SetControlMode();
if (mode == (int)ELearning.Common.ELearningEnum.PageMode.Add)
{
btnAdd.Text = "Add";
}
else if (mode == (int)ELearning.Common.ELearningEnum.PageMode.Edit)
{
btnAdd.Text = "Edit";
}
else
{
ClearMessages();
lblErrorMessage.Text = "Invalid mode";
return;
}
SetForJob();
}
catch (Exception ex)
{
ELearning.ErrorLogger.Error.WriteErrorLog(ex);
lblErrorMessage.Text = "Error has occured!";
}
}
private int SetControlMode()
{
try
{
if (_selectedJobId == 0)
return (int)ELearning.Common.ELearningEnum.PageMode.Add;
else
return (int)ELearning.Common.ELearningEnum.PageMode.Edit;
}
catch (Exception ex)
{
ELearning.ErrorLogger.Error.WriteErrorLog(ex);
return -1;
}
}
private void SetHeader()
{
try
{
string header = string.Empty;
//Set Mode
if (mode == (int)ELearningEnum.PageMode.Add)
header = "Add Position Title";
else if (mode == (int)ELearningEnum.PageMode.Edit)
header = "Edit Position Title";
ClearMessages();
h1Heading.InnerHtml = header;
}
catch (Exception ex)
{
lblErrorMessage.Text = "Error has occurred while binding header Information.";
ELearning.ErrorLogger.Error.WriteErrorLog(ex, "Error has occurred while binding header Information.");
}
}
private void SetForJob()
{
mode = SetControlMode();
SetHeader();
if (mode == (int)ELearningEnum.PageMode.Edit)
{
LoadJob(SelectedJobId);
}
}
private void LoadJob(int jobId)
{
Job job = null;
try
{
job = new ManageJob().GetJob(jobId);
if (job != null)
{
txtJobName.Text = job.Name;
txtJobDescription.Text = job.Description;
}
else
{
ClearMessages();
lblErrorMessage.Text = "Position Title not found!";
}
}
catch (Exception ex)
{
lblErrorMessage.Text = "Data binding error!";
ELearning.ErrorLogger.Error.WriteErrorLog(ex, "Data binding error!");
}
}
private void ClearControls()
{
txtJobName.Text = string.Empty;
txtJobDescription.Text = string.Empty;
}
private void ClearMessages()
{
lblErrorMessage.Text = string.Empty;
lblSuccessMessage.Text = string.Empty;
}
#endregion
protected void btnAdd_Click(object sender, EventArgs e)
{
bool isAdd;
bool isSuccess = false;
ClearMessages();
try
{
mode = SetControlMode();
if (mode == (int)ELearning.Common.ELearningEnum.PageMode.Add)
{
isAdd = true;
}
else
{
isAdd = false;
}
int? organizationId = null;
ManageJob manageJob = new ManageJob();
int retJobId = manageJob.AddJob(isAdd,
SelectedJobId,
txtJobName.Text.Trim(),
txtJobDescription.Text.Trim(),
organizationId);
isSuccess = (retJobId > 0);
if (isSuccess)
{
if (isAdd)
{
lblSuccessMessage.Text = "Position Title successfully added!";
ClearControls();
}
else
{
lblSuccessMessage.Text = "Position Title successfully updated!";
}
}
else
{
if (retJobId == -99)
lblErrorMessage.Text = "Position Title already exists!";
else
lblErrorMessage.Text = "Error has occured!";
}
}
catch (Exception ex)
{
lblErrorMessage.Text = "Error has occured!";
ELearning.ErrorLogger.Error.WriteErrorLog(ex);
}
}
}
0 Response to "Add page code"
Post a Comment