Using Some XMl code and some logic implements:

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using BusinessRule.BLClasses;

using BusinessRule.DBClasses;

namespace Web.Screens.Admin

{

public partial class Comp_CorporateActions : System.Web.UI.Page

{

public string pstrMsg;

string UserId = “”;

DataTable dtActiveTicerks = new DataTable();

string TickerSelected = “”;

protected void Page_Load(object sender, EventArgs e)

{

DataSet ds = new DataSet();

//SessionHandler();

if (Session[“UserID”] != null)

{

UserId = Session[“UserID”].ToString();

}

else

{

UserId = “6482”;

//Response.Write(“~logout~”);

//Response.End();

}

if (!Page.IsPostBack)

{

FetchIdentifiers();

dtActiveTicerks = AdminMtds.FetchCompanyInfo();

ds.Tables.Add(dtActiveTicerks.Copy());

Session[“DropDownDataTable”] = ds.GetXml();

hid_chkTickerStatus.Value = “0”;

Fetchticker();

}

}

// To read the xml dataset and store them in the values

private DataSet GenerateXML()

{

DataSet dsTables = new DataSet();

System.IO.StringReader rdr;

string sXML = “”;

sXML = Session[“DropDownDataTable”].ToString();

rdr = new System.IO.StringReader(sXML);

dsTables.ReadXml(rdr);

return dsTables;

}

private void SessionHandler()

{

string outPutString = “”;

if (!Common.gFunctions.CheckIsAuthorized(“NOCHECK”, ref outPutString))

{

Response.Write(outPutString);

Response.End();

}

}

// To Fetch Active Ticker

private void Fetchticker()

{

DataSet dset = GenerateXML();

DataTable dtbl;

dtbl = dset.Tables[0];

DataView dv = new DataView(dtbl);

dv.Sort = “ci_vTicker asc”;

ddlActivetickers.DataSource = dv;

ddlActivetickers.DataValueField = “ci_icompanycode”;

ddlActivetickers.DataTextField = “ci_vTicker”;

ddlActivetickers.DataBind();

ddlActivetickers.Items.Insert(0, new ListItem(“Select…”, “0”));

}

// This Function to Fetch Old Identifier

private void FetchOldIdentier()

{

string strColumnVal = “”;

string strColumnVal1 = “”;

string strColumnVal2 = “”;

string ddlActiveSelectedVal = “”;

ddlActiveSelectedVal = ddlActivetickers.SelectedValue.ToString();

DataTable dtbl = AdminMtds.FetchCompanyDtl(Convert.ToInt64(ddlActiveSelectedVal));

DataRow[] drows;

strColumnVal1 = “ci_iCompanyCode”;

strColumnVal2 = “ci_vCompanyName”;

switch (ddlActions.SelectedValue)

{

case “1”:

strColumnVal = “ci_vSedol”;

break;

case “2”:

strColumnVal = “ci_vTicker”;

break;

case “3”:

strColumnVal = “ci_iCIQCode”;

break;

case “4”:

strColumnVal = “ci_vCompanyName”;

Comp_Name.Visible = false;

break;

case “5”:

strColumnVal = “ci_vCusip”;

break;

case “6”:

strColumnVal = “ci_vDJGIID”;

break;

case “7”:

strColumnVal = “ci_iGICSSubsectorCode”;

break;

case “8”:

strColumnVal = “ci_vGVKey”;

break;

case “9”:

strColumnVal = “ci_vISIN”;

break;

case “10”:

strColumnVal = “ci_vRIC”;

break;

case “11”:

strColumnVal = “ci_iStockKey”;

break;

case “12”:

strColumnVal = “ci_iICBSubsectorCode”;

break;

case “13”:

strColumnVal = “ci_iTradingItemId”;

break;

default:

break;

}

drows = dtbl.Select(“ci_iCompanyCode='” + ddlActiveSelectedVal + “‘”, “ci_vTicker asc”);

try

{

if (drows.Length > 0)

{

for (int i = 0; i <= drows.Length; i++)

{

txtOldIdentifier.Text = drows[0][“” + strColumnVal + “”].ToString();

if (txtOldIdentifier.Text == “”)

{

txtOldIdentifier.Text = “—“;

}

txtComp_Code.Text = drows[0][“” + strColumnVal1 + “”].ToString();

if (txtComp_Code.Text == “”)

{

txtComp_Code.Text = “—“;

}

txtComp_Name.Text = drows[0][“” + strColumnVal2 + “”].ToString();

if (txtComp_Name.Text == “”)

{

txtComp_Name.Text = “—“;

}

}

}

else

{

txtOldIdentifier.Text = “”;

txtComp_Code.Text = “”;

txtComp_Name.Text = “”;

}

}

catch (Exception ex)

{

pstrMsg = ex.Message;

}

}

// Action Drop Down Selected Index Change

protected void ddlActions_SelectedIndexChanged(object sender, EventArgs e)

{

txtOldIdentifier.Text = “”;

txtComp_Code.Text = “”;

txtComp_Name.Text = “”;

txtIdentifiers.Text = “”;

Fetchticker();

TickerStaus();

if (ddlActions.SelectedValue == “0”)

{

fnClearValues();

}

else if (ddlActions.SelectedValue != “100” && ddlActions.SelectedValue != “200”)

{

txtEffectivefrom.Enabled = true;

txtIdentifiers.Enabled = true;

txtOldIdentifier.Enabled = true;

txtComp_Code.Enabled = true;

txtComp_Name.Enabled = true;

}

else

{

txtEffectivefrom.Enabled = false;

txtIdentifiers.Enabled = false;

txtOldIdentifier.Enabled = false;

txtComp_Code.Enabled = false;

txtComp_Name.Enabled = false;

}

switch (ddlActions.SelectedValue)

{

case “2”:

txtIdentifiers.MaxLength = 12;

break;

case “4”:

txtIdentifiers.MaxLength = 100;

break;

case “6”:

txtIdentifiers.MaxLength = 20;

break;

case “9”:

txtIdentifiers.MaxLength = 12;

break;

case “1”:

txtIdentifiers.MaxLength = 12;

break;

case “5”:

txtIdentifiers.MaxLength = 12;

break;

default:

txtIdentifiers.MaxLength = 12;

break;

}

}

// Active Ticker Drop Down Selected Index Change

protected void ddlActivetickers_SelectedIndexChanged(object sender, EventArgs e)

{

TickerStaus();

txtOldIdentifier.Text = “”;

txtComp_Code.Text = “”;

txtComp_Name.Text = “”;

if (ddlActions.SelectedValue == “0”)

{

ddlActivetickers.ClearSelection();

pstrMsg = “Please select action”;

return;

}

else if (ddlActions.SelectedValue != “100” && ddlActions.SelectedValue != “200”)

{

Comp_Name.Visible = true;

txtEffectivefrom.Enabled = true;

txtIdentifiers.Enabled = true;

txtOldIdentifier.Enabled = true;

txtComp_Code.Enabled = true;

txtComp_Name.Enabled = true;

FetchOldIdentier();

}

}

// To check Current Status of Ticker for Pipeline and Deactive

private string CheckStatus(string Companycode)

{

Companycode = TickerSelected.ToString();

DataTable dtCheckStatus = GenerateXML().Tables[0];

DataRow[] drow;

string ChkStatus = “”;

drow = dtCheckStatus.Select(“ci_vTicker='” + TickerSelected + “‘”);

if (drow.Length > 0)

{

ChkStatus = drow[0][“ci_cstatus”].ToString();

return ChkStatus;

}

else

{

return ChkStatus;

}

}

//To Update in DB when button is clicked

protected void btnUpdate_Click1(object sender, ImageClickEventArgs e)

{

try

{

DataTable dtCheckIdentifierName = new DataTable();

dtCheckIdentifierName = PipelineQAMtds.CheckIdentifierName(Convert.ToInt32(ddlActions.SelectedValue), txtIdentifiers.Text);

if (dtCheckIdentifierName.Rows.Count > 0)

{

string chkIdentifiername = dtCheckIdentifierName.Rows[0][“Ih_vIdentifier”].ToString();

pstrMsg = “Following identifier already exists.”;

return;

}

int status = 0;

string Descriptionlength = txtDescription.Text.ToString();

Int64 CompCode = Convert.ToInt64(ddlActivetickers.SelectedValue);

string Action = ddlActions.SelectedValue.ToString();

string ActionDesc = ddlActions.SelectedItem.Text;

string OldVal = txtOldIdentifier.Text.ToString();

string NewVal = txtIdentifiers.Text.ToString().Trim();

string Dates = txtEffectivefrom.Text.ToString();

char chrUpdate;

TickerSelected = ddlActivetickers.SelectedItem.ToString();

if (OldVal == “—“)

{

OldVal = “”;

}

if (Action == “2”)

{

status = PipelineQAMtds.UpdateTicker(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “1”)

{

status = PipelineQAMtds.UpdateSedol(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “3”)

{

status = PipelineQAMtds.UpdateCIQCode(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “4”)

{

status = PipelineQAMtds.UpdateCompName(CompCode, TickerSelected, NewVal, Dates);

}

else if (Action == “5”)

{

status = PipelineQAMtds.UpdateCUSIP(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “6”)

{

status = PipelineQAMtds.UpdateDJID(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “7”)

{

DataTable dtCheckSubSectorcode = new DataTable();

dtCheckIdentifierName = PipelineQAMtds.CheckSubsectorcode(NewVal);

if (dtCheckIdentifierName.Rows.Count > 0)

{

status = PipelineQAMtds.UpdateGICSSubSectorCode(CompCode, OldVal, NewVal, Dates);

}

else

{

pstrMsg = “Sub sector code not available”;

return;

}

}

else if (Action == “8”)

{

status = PipelineQAMtds.UpdateGVKey(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “9”)

{

status = PipelineQAMtds.UpdateISIN(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “10”)

{

status = PipelineQAMtds.UpdateRIC(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “11”)

{

status = PipelineQAMtds.UpdateStockKey(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “12”)

{

DataTable dtCheckSubSectorcode = new DataTable();

dtCheckIdentifierName = PipelineQAMtds.CheckSubsectorcode(NewVal);

if (dtCheckIdentifierName.Rows.Count > 0)

{

status = PipelineQAMtds.UpdateSubsectorCode(CompCode, OldVal, NewVal, Dates);

}

else

{

pstrMsg = “Sub sector code not available”;

return;

}

}

else if (Action == “13”)

{

status = PipelineQAMtds.UpdateTradingItemId(CompCode, OldVal, NewVal, Dates);

}

else if (Action == “100”)

{

chrUpdate = ‘D’;

if (CheckStatus(TickerSelected) != Convert.ToString(chrUpdate))

{

status = PipelineQAMtds.UpdateDeactiveCorporateActions(CompCode, Convert.ToInt64(UserId));

}

else

{

pstrMsg = “Ticker is already in deactive state”;

return;

}

}

else if (Action == “200”)

{

chrUpdate = ‘P’;

if (CheckStatus(TickerSelected) != Convert.ToString(chrUpdate))

{

status = PipelineQAMtds.UpdatePipeLineCorporateActions(CompCode, Convert.ToInt64(UserId));

}

else

{

pstrMsg = “Ticker is already in pipeline”;

return;

}

}

ClientScript.RegisterStartupScript(this.GetType(), “startup”, “<script language=’javascript’>document.getElementById(‘dvLoad’).style.display=’none’;</script>”);

if (status == 1)

{

int Result = PipelineQAMtds.InsertTickerCompanyCorporateActions(CompCode, ActionDesc, Descriptionlength.ToString(), Convert.ToInt32(UserId));

if (Result == 1)

{

if (Action != “100” && Action != “200”)

pstrMsg = ActionDesc + ” updated successfully”;

else if (Action == “100”)

pstrMsg = “Ticker deactivated successfully”;

else

pstrMsg = “Ticker is moved to pipeline”;

DataTable dtable = new DataTable();

dtable = AdminMtds.FetchCompanyInfo();

Session[“DropDownDataTable”] = dtable.DataSet.GetXml();

Fetchticker();

fnClearValues();

}

}

else

{

pstrMsg = ActionDesc + ” not updated”;

}

}

catch (Exception ex)

{

pstrMsg = ex.Message;

}

}

// To Clear all the values in page

protected void btnCancel_Click(object sender, ImageClickEventArgs e)

{

fnClearValues();

}

//Function to clear the values in controls

private void fnClearValues()

{

ddlActions.SelectedValue = “0”;

ddlActivetickers.SelectedValue = “0”;

txtDescription.Text = “”;

txtEffectivefrom.Text = “”;

txtIdentifiers.Text = “”;

txtOldIdentifier.Text = “”;

txtComp_Code.Text = “”;

txtComp_Name.Text = “”;

hid_chkTickerStatus.Value = “0”;

TickerStaus();

}

private void TickerStaus()

{

DataTable dtblTickerStatus = new DataTable();

string TickerSelected = ddlActivetickers.SelectedItem.ToString();

dtblTickerStatus = PipelineQAMtds.FetchTickerStatus(TickerSelected);

if (dtblTickerStatus.Rows.Count > 0)

{

string TickerStatus = dtblTickerStatus.Rows[0][0].ToString();

string TickerStatusValue = “”;

switch (TickerStatus)

{

case “A”:

TickerStatusValue = “Active”;

break;

case “P”:

TickerStatusValue = “Pipeline”;

break;

case “D”:

TickerStatusValue = “Deactive”;

break;

}

lbltickerStatus.Text = TickerStatusValue;

}

else

lbltickerStatus.Text = “”;

}

private void FetchIdentifiers()

{

DataTable dtFetchIdentifiers = new DataTable();

dtFetchIdentifiers = PipelineQAMtds.FetchIdentifiers();

ddlActions.DataSource = dtFetchIdentifiers;

ddlActions.DataValueField = “IT_iTypeId”;

ddlActions.DataTextField = “IT_vTypeName”;

ddlActions.DataBind();

ddlActions.Items.Insert(0, new ListItem(“Select…”, “0”));

}

}

}

Leave a comment