//Delete from Linq list and add to dropdown list
protected void grdOpenVacancy_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = (int)grdOpenVacancy.DataKeys[e.RowIndex].Value;
DataTable dtOpenVacancy = ViewState["vwOpenVacancy"] as DataTable;
DataRow dr= dtOpenVacancy.AsEnumerable().Where(a=>a.Field<int>("ID") == id).FirstOrDefault();
//GridViewRow grdrow = grdOpenVacancy.Rows[e.RowIndex];
bool i = Repository.DeleteOpenVacancy(id);
// ddlCadreType_SelectedIndexChanged(null, null);
if (ViewState["dt2"] != null)
{
DataTable dt3 = (DataTable)ViewState["dt2"];
DataRow workRow = dt3.NewRow();
// workRow["Institute"] = grdrow.Cells[0].Text;
workRow["Institute"] = dr["InstituteName"];
workRow["Discipline"] = dr["disciplineName"];
workRow["cadrename"] = dr["cadreName"];
workRow["cadreID"] = dr["cadreID"];
workRow["SS"] = dr["SanctionedStrength"];
workRow["IP"] = dr["inposition"];
workRow["Vacancy"] = dr["vacancy"];
dt3.Rows.Add(workRow);
ViewState["dt2"] = dt3;
//ddlInstitute.SelectedIndex = 0;
//ddlDiscipline.SelectedIndex = 0;
//ddlDiscipline.Items.Clear();
//ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));
if (ddlInstitute.SelectedIndex > 0)
{
var allDisciplines = dt3.AsEnumerable().Where(p => p.Field<string>("Institute") != null).CopyToDataTable();
//var disciplines = allDisciplines.AsEnumerable().Where(s => s.Field<string>("institute") == ddlInstitute.SelectedItem.Text && s.Field<int>("ss") != 0).Select(d => new { discipline = d.Field<String>("discipline") });
if (ddlCadreType.SelectedItem.Text == (String)dr["cadrename"] && ddlInstitute.SelectedItem.Text == (String)dr["InstituteName"])
{
var disciplines = allDisciplines.AsEnumerable().Where(s => s.Field<string>("institute") == dr["InstituteName"].ToString() && s.Field<int>("ss") != 0 && s.Field<string>("cadrename") == dr["cadrename"].ToString()).Select(d => new { discipline = d.Field<String>("discipline") });
if (disciplines.Count() > 0)
{
//JavaScriptSerializer js = new JavaScriptSerializer();
ddlDiscipline.DataSource = disciplines;
ddlDiscipline.DataValueField = "discipline";
ddlDiscipline.DataTextField = "discipline";
ddlDiscipline.DataBind();
ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));
}
else
{
ddlDiscipline.Items.Clear();
ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));
}
}
}
}
this.BindOpenVacancy();
}
// Add to LINQ list and delete from dropdown
protected void btnAddNew_Click(object sender, EventArgs e)
{
//AddNewRowToGrid();
int openVacancyID = 0;
bool i = Repository.UpdateOpenVacancy(openVacancyID, ddlCadreType.SelectedItem.Text, int.Parse(ddlCadreType.SelectedValue), ddlInstitute.SelectedItem.Text, (int?)null, ddlDiscipline.SelectedItem.Text, null, int.Parse(txtSanctionedStrength.Text), int.Parse(txtInPosition.Text), int.Parse(txtVacancy.Text), int.Parse(txtOpenVacancy.Text));
if (i == true)
{
//if (ViewState["O_id"].ToString() == "")
//{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Added Successfully')", true);
if (ViewState["dt2"] != null)
{
var exceptionList =
allData.AsEnumerable().Where(a=>a.Field<string>("discipline") == ddlDiscipline.SelectedItem.Text && a.Field<string>("institute") == ddlInstitute.SelectedItem.Text && a.Field<int>("cadreID") == int.Parse(ddlCadreType.SelectedValue)).ToList();
ddlDiscipline.ClearSelection();
DataTable dt3 = (DataTable)ViewState["dt2"];
var allDisciplines = dt3.AsEnumerable().Where(p => p.Field<string>("Institute") != null);
var disciplines = allDisciplines.Where(s => s.Field<string>("institute") == ddlInstitute.SelectedItem.Text && s.Field<int>("ss") != 0).Select(d => new { discipline = d.Field<String>("discipline") });
//ViewState["allDisSSInPosVacancy"] = dt3;
//.AsEnumerable().Where(p => p.Field<string>("Institute") != "");
//.Where(s => s.Field<string>("institute") == ddlInstitute.SelectedItem.Text && s.Field<int>("ss") != 0);
//.Select(d => new { discipline = d.Field<String>("discipline"), SS = d.Field<int>("SS"), IP = d.Field<int>("IP"), vacancy = d.Field<int>("vacancy") });
if (disciplines.Count() > 0)
{
//JavaScriptSerializer js = new JavaScriptSerializer();
ddlDiscipline.DataSource = disciplines;
ddlDiscipline.DataValueField = "discipline";
ddlDiscipline.DataTextField = "discipline";
ddlDiscipline.DataBind();
ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));
}
else
{
ddlDiscipline.Items.Clear();
ddlDiscipline.Items.Insert(0, new ListItem("--Select--", "--Select--"));
}
//}
//else
//{ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Updated Successfully')", true); }
//bindgrid_o();
}
}
private void ResetmainData()
{
BindOpenVacancy();
DataTable dtOpenVacancy = ViewState["vwOpenVacancy"] as DataTable;
var allData = ViewState["dt2"] as DataTable;
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + allData.Count() + "')", true);
removeAddMainData(allData, dtOpenVacancy);
}
private void removeAddMainData(DataTable allData, DataTable dtOpenVacancy)
{
if (ViewState["vwOpenVacancy"] != null)
{
var exceptionList =
allData.AsEnumerable().Where(a => dtOpenVacancy.AsEnumerable().Select(q => q.Field<string>("disciplinename")).Contains(a.Field<string>("discipline")) && dtOpenVacancy.AsEnumerable().Select(q => q.Field<string>("institutename")).Contains(a.Field<string>("institute")) && dtOpenVacancy.AsEnumerable().Select(q => q.Field<int>("cadreID")).Contains(int.Parse(ddlCadreType.SelectedValue))).ToList();
ViewState["dt2"] = allData.AsEnumerable().Except(exceptionList.AsEnumerable()).CopyToDataTable();
}
else
{
ViewState["dt2"] = allData.AsEnumerable().CopyToDataTable();
}
}
// at page load
DataTable dt = new DataAccess().Read(procName, param).Tables[0];
dt.Columns.Add("cadrename", typeof(string));
dt.Columns.Add("cadreID", typeof(int));
foreach (DataRow item in dt.Rows)
{
item["cadrename"] = ddlCadreType.SelectedItem.Text;
item["cadreID"] = ddlCadreType.SelectedValue;
}
DataTable dt2 = dt.Copy();
if (ViewState["dt2"] == null && dt.Rows.Count > 0)
{
//ViewState["dt2"] = dt.Copy();
DataTable dtMainData = dt.Copy();
DataTable dtOpenVacancy = ViewState["vwOpenVacancy"] as DataTable;
var allData = dtMainData.AsEnumerable().Where(p => p.Field<string>("institute") != null).CopyToDataTable();
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + allData.Count() + "')", true);
if (ViewState["vwOpenVacancy"] != null)
{
var exceptionList =
allData.AsEnumerable().Where(a => dtOpenVacancy.AsEnumerable().Select(q => q.Field<string>("disciplinename")).Contains(a.Field<string>("discipline")) && dtOpenVacancy.AsEnumerable().Select(q => q.Field<string>("institutename")).Contains(a.Field<string>("institute")) && dtOpenVacancy.AsEnumerable().Select(q => q.Field<int>("cadreid")).Contains(int.Parse(ddlCadreType.SelectedItem.Value))).ToList();
ViewState["dt2"] = allData.AsEnumerable().Except(exceptionList.AsEnumerable()).CopyToDataTable();
}
else
{
ViewState["dt2"] = allData.AsEnumerable().CopyToDataTable();
}
}
else
{
ddlInstitute.Visible = false;
lblInstitute.Visible = false;
}
dt2.Clear();
List<vacancy> vacancies = new List<vacancy>();
foreach (var v in vacancies)
{
DataRow dr2 = dt2.NewRow();
dr2["Institute"] = v.Institute;
dr2["Discipline"] = v.Discipline;
dr2["State"] = v.State;
dr2["SMD"] = v.SMD;
dr2["SS"] = v.SS;
dr2["IP"] = v.IP;
dr2["Vacancy"] = v.Vacancy;
dt2.Rows.Add(dr2);
}
gridVacancy.DataSource = ViewState["dt2"];
gridVacancy.DataBind();
var s = gridVacancy.DataSource as DataTable;
JavaScriptSerializer js = new JavaScriptSerializer();
var institutes = dt.AsEnumerable().Select(d => new { Institute = d.Field<String>("institute") }).Distinct();
No comments:
Post a Comment