protected void btnQueryAddIns_Click(object sender, EventArgs e) { string Mode = "Ins"; Guid InspectionId = Guid.Empty; if (null == ViewState["InspectionQueryListDetails"]) { ViewState["InspectionQueryListDetails"] = new Inspection().GetInspectionQueriesByInspectionId(Guid.Empty); InspectionId = Guid.Empty; } GridView GvInspectionQueries = ((GridView) WzInspection.FindControl("GvInspectionQueries" + Mode)); DataTable dtInspectionQueryListDetails = (DataTable) ViewState["InspectionQueryListDetails"]; DropDownList ddlCheckListId = ((DropDownList) WzInspection.FindControl("ddlCheckListId" + Mode)); TextBox txtQuery = (TextBox) WzInspection.FindControl("txtQuery" + Mode); TextBox txtQueryRemarks = (TextBox) WzInspection.FindControl("txtQueryRemarks" + Mode); DataRow dr = dtInspectionQueryListDetails.NewRow(); dr["QueryId"] = Guid.NewGuid(); dr["InspectionId"] = Guid.Empty; dr["CheckListId"] = ddlCheckListId.SelectedItem.Value; dr["Description"] = ddlCheckListId.SelectedItem.Text; dr["Query"] = txtQuery.Text; dr["Remarks"] = txtQueryRemarks.Text; dtInspectionQueryListDetails.Rows.Add(dr); ViewState["InspectionQueryListDetails"] = dtInspectionQueryListDetails; GvInspectionQueries.DataSource = (DataTable) ViewState["InspectionQueryListDetails"]; GvInspectionQueries.DataBind(); txtQuery.Text = ""; txtQueryRemarks.Text = ""; }
protected void btnSearch_Click(object sender, EventArgs e) { Inspection objinspection= new Inspection(); GvInspectionMemo.DataSource = objinspection.SearchInspectionDetails(txtInspectionNo.Text); GvInspectionMemo.DataBind(); }
protected void btnUpdate_Click(object sender, EventArgs e) { string Mode = "Ins"; Guid InspectionId = Guid.Empty; if (null == ViewState["MemoDetails"]) { ViewState["MemoDetails"] = new Inspection().GetInspectionMemoById(Guid.Empty); InspectionId = Guid.Empty; } if (fvMemo.CurrentMode == FormViewMode.Edit) { InspectionId = (Guid) fvMemo.DataKey["InspectionId"]; Mode = "Upd"; } // GridView GvInspectionMemoDetailsIns = (GridView) sender; DataTable dtMemoDetails = (DataTable) ViewState["MemoDetails"]; TextBox txtSubject = ((TextBox) fvMemo.FindControl("txtSubject" + Mode)); TextBox txtMemoDate = ((TextBox) fvMemo.FindControl("txtMemoDate" + Mode)); TextBox txtMemoBody = ((TextBox) fvMemo.FindControl("txtMemoBody" + Mode)); object[] keys = new object[gvMemo.SelectedDataKey.Values.Count]; for (int i = 0; i < keys.Length; i++) { keys[i] = gvMemo.SelectedDataKey.Values[i]; } DataRow dr = dtMemoDetails.Rows.Find(keys); if (null != dr) { dr["InspectionMemoId"] = Guid.NewGuid(); dr["Subject"] = txtSubject.Text; dr["MemoDate"] = txtMemoDate.Text.ToString(); dr["MemoBody"] = txtMemoBody.Text; //dr["MemoDate"] = txtMemoDate. dr["InspectionId"] = InspectionId; //dtMemoDetails.Rows.Add(dr); } gvMemo.DataSource = (DataTable) ViewState["MemoDetails"]; // gvMemo.DataBind(); gvMemo.SelectedIndex = -1; txtSubject.Text = ""; txtMemoDate.Text = ""; txtMemoBody.Text = ""; ((Button) fvMemo.FindControl("btnAdd")).Visible = true; ((Button) fvMemo.FindControl("btnUpdate")).Visible = false; }
protected void FvInspectionIternary_DataBound(object sender, EventArgs e) { string Mode = String.Empty; switch (FvInspectionIternary.CurrentMode) { case FormViewMode.Edit: Mode = "Upd"; break; case FormViewMode.Insert: Mode = "Ins"; break; case FormViewMode.ReadOnly: Mode = "Itm"; break; default: break; } // Get the Yearly Schedule Id Guid ScheduleId = new Guid(fldScheduleId.Value); // Get the Monthly schedule details for the selected Schedule Inspection objInspection = new Inspection(); DataTable dtScheduleDetails = objInspection.GetYearlyInspectionDetailsById(ScheduleId); DropDownList ddlInspectionMonth = ((DropDownList)FvInspectionIternary.FindControl("ddlMonth" + Mode)); GvInspectionDetails.DataSource = dtScheduleDetails; GvInspectionDetails.DataBind(); if (dtScheduleDetails.Rows.Count > 0) { //int year= (int)dtScheduleDetails.Rows[0]["Year"]; //Label lblYear = (Label)FvInspectionIternary.FindControl("lblYear" + Mode); //if (lblYear != null) // lblYear.Text = Convert.ToString(year); //PopCalendar popInspectingDate = (PopCalendar)FvInspectionIternary.FindControl("popInspectingDate" + Mode); //RangeFrom DateFrom = new RangeFrom(); //RangeTo DateTo = new RangeTo(); //DateFrom.Date = new DateTime(year, ddlInspectionMonth.SelectedIndex, 01); //DateTo.Date = new DateTime(year, ddlInspectionMonth.SelectedIndex, DateTime.DaysInMonth(year, ddlInspectionMonth.SelectedIndex)); //if (popInspectingDate != null){ //popInspectingDate.From = DateFrom; //popInspectingDate.To = DateTo; //} ddlInspectionMonth.SelectedIndex = Convert.ToInt32(dtScheduleDetails.Rows[0]["Month"]); } }
protected void btnSave_Click(object sender, EventArgs e) { Inspection ins = new Inspection(); }
protected void GvYearlyInspection_SelectedIndexChanged(object sender, EventArgs e) { // Get the Yearly Schedule Id Guid ScheduleId = (Guid)GvYearlyInspection.SelectedDataKey.Value; fldScheduleId.Value = Convert.ToString(ScheduleId); // Get the Monthly schedule details for the selected Schedule Inspection objInspection = new Inspection(); DataTable dtScheduleDetails = objInspection.GetYearlyInspectionDetailsById(ScheduleId); DataTable dtOfficeDetails = new Inspection().GetMonthlyInspectionScheduleByDetailScheduleId(ScheduleId); string officeNames = ""; // Get the selected Offices if (dtScheduleDetails.Rows.Count > 0) { foreach (DataRow drScheduleDetail in dtScheduleDetails.Rows) { officeNames = ""; DataRow[] drOfficeDetail = dtOfficeDetails.Select("DetailScheduleId='" + drScheduleDetail["DetailScheduleId"].ToString() + "'"); for (int i = 0; i < drOfficeDetail.Length; i++) { officeNames += Convert.ToString(drOfficeDetail[i]["OfficeName"]) + ", "; } // Remove the coma at the end of the string if (officeNames.Length > 2) { officeNames = officeNames.Substring(0, officeNames.Length - 2); } drScheduleDetail["OfficeName"] = officeNames; } GvInspectionDetails.DataSource = dtScheduleDetails; GvInspectionDetails.DataBind(); } //DropDownList ddlInspectionMonth = ((DropDownList)FvInspectionIternary.FindControl("ddlMonth" + Mode)); }
protected void btnQueryUpdateIns_Click(object sender, EventArgs e) { string Mode = "Ins"; Guid InspectionId = Guid.Empty; if (null == ViewState["InspectionQueryListDetails"]) { ViewState["InspectionQueryListDetails"] = new Inspection().GetInspectionQueriesByInspectionId(Guid.Empty); InspectionId = Guid.Empty; } GridView GvInspectionQueries = ((GridView) WzInspection.FindControl("GvInspectionQueries" + Mode)); DataTable dtInspectionQueryListDetails = (DataTable) ViewState["InspectionQueryListDetails"]; DropDownList ddlCheckListId = ((DropDownList) WzInspection.FindControl("ddlCheckListId" + Mode)); TextBox txtQuery = ((TextBox) WzInspection.FindControl("txtQuery" + Mode)); TextBox txtQueryRemarks = ((TextBox) WzInspection.FindControl("txtQueryRemarks" + Mode)); object[] keys = { GvInspectionQueries.SelectedDataKey.Value }; DataRow dr = dtInspectionQueryListDetails.Rows.Find(keys); if (null != dr) { dr["CheckListId"] = ddlCheckListId.SelectedValue; dr["Query"] = txtQuery.Text; dr["Remarks"] = txtQueryRemarks.Text; } ((Button) WzInspection.FindControl("btnQueryAdd" + Mode)).Visible = true; ((Button) WzInspection.FindControl("btnQueryUpdate" + Mode)).Visible = false; GvInspectionQueries.DataSource = (DataTable) ViewState["InspectionQueryListDetails"]; GvInspectionQueries.DataBind(); GvInspectionQueries.SelectedIndex = -1; txtQuery.Text = ""; txtQueryRemarks.Text = ""; }
protected void WzInspection_FinishButtonClick(object sender, WizardNavigationEventArgs e) { Inspection objInspection = new Inspection(); InspectionDetailsRow InspectionDetails = Inspection.GetInspectionDetailsRow(); InspectionDetails.InspectionTypeId = new Guid(ddlInspectionTypeIdIns.SelectedValue); InspectionDetails.InspectingOfficerId = new Guid(ddlInspectingOfficerIdIns.SelectedValue); InspectionDetails.InspectorOfficeName = txtInspectorOfficeNameIns.Text; InspectionDetails.InspectedOfficeId = new Guid(ddlInspectedOfficeIdIns.SelectedValue); InspectionDetails.LicenseId = new Guid(ddlLicenseIdIns.SelectedValue); InspectionDetails.IsDiscrepancyFound = chkIsDiscrepancyFoundIns.Checked; InspectionDetails.Remarks = txtInspectionRemarksIns.Text; Wizard Container = (Wizard) Master.FindControl("Main").FindControl("WzInspection"); List<CheckListInspectionRow> CheckListRows = new List<CheckListInspectionRow>(); string filename = Server.MapPath("~\\Inspection\\InspectionCheckList.xml"); XmlDocument InspectionCheckListXml = new XmlDocument(); InspectionCheckListXml.Load(filename); foreach (XmlNode Node in InspectionCheckListXml.SelectNodes("DocumentElement/Page/Items")) { CheckListInspectionRow CheckListRow = Inspection.GetCheckListRow(); TextBox txtRemarks = (TextBox) Container.FindControl("txt" + Node.Attributes["ItemId"].Value); CheckBox chkYesNo = (CheckBox) Container.FindControl("chk" + Node.Attributes["ItemId"].Value); CheckListRow.InspectionCheckListId = new Guid(Node.Attributes["ItemId"].Value); if (null != txtRemarks) CheckListRow.Remarks = txtRemarks.Text; else CheckListRow.SetRemarksNull(); if (null != chkYesNo) CheckListRow.Checked = chkYesNo.Checked; else CheckListRow.Checked = false; CheckListRows.Add(CheckListRow); } DataTable InspectionQueries = (DataTable) ViewState["InspectionQueryListDetails"]; //objInspection.AddNewInspection(InspectionDetails, CheckListRows, InspectionQueries); }
protected void WzInspection_DataBinding(object sender, EventArgs e) { GridView GvInspectionDetails = ((GridView) mvInspectionDetails.FindControl("GvInspectionDetails")); Guid InspectionId = (Guid) GvInspectionDetails.SelectedDataKey.Value; Inspection objInspection = new Inspection(); DataTable dtInspectionDetails = new DataTable(); //dtInspectionDetails = objInspection.GetAllInspectionDetailsById(InspectionId); txtInspectorOfficeNameUpd.Text = Convert.ToString(dtInspectionDetails.Columns["InspectorOfficeName"]); DataTable dtQueries = new DataTable(); dtQueries = objInspection.GetInspectionQueriesByInspectionId(InspectionId); GvInspectionQueriesUpd.DataSource = dtQueries; GvInspectionQueriesUpd.DataBind(); }
protected void WzInspectionUpd_DataBinding(object sender, EventArgs e) { if (fldSelectedKey.Value != "") { Guid InspectionId = new Guid(fldSelectedKey.Value); Inspection objInspection = new Inspection(); DataRow drInspectionDetails = objInspection.GetInspectionDetailsById(InspectionId).Rows[0]; //ddlInspectionTypeIdUpd.DataValueField = ((Guid) drInspectionDetails["InspectionTypeId"]).ToString(); // ddlInspectingOfficerIdUpd.DataValueField = ((Guid) drInspectionDetails["InspectingOfficerId"]).ToString(); //ddlInspectionTypeIdUpd.DataTextField = ((Guid) drInspectionDetails["InspectionTypeId"]).ToString(); //ddlInspectingOfficerIdUpd.DataTextField = ((Guid) drInspectionDetails["InspectingOfficerId"]).ToString(); //txtInspectorOfficeNameUpd.Text = ((Guid) drInspectionDetails["InspectorOfficeName"]).ToString(); txtInspectorOfficeNameUpd.Text = Convert.ToString(drInspectionDetails["InspectorOfficeName"]); IsdescripancyFoundUpd.Checked = (bool) (drInspectionDetails["IsDiscrepancyFound"]); txtInspectionRemarksUpd.Text = Convert.ToString(drInspectionDetails["Remarks"]); DataTable dtQueries = new DataTable(); dtQueries = objInspection.GetInspectionQueriesByInspectionId(InspectionId); GvInspectionQueriesUpd.DataSource = dtQueries; GvInspectionQueriesUpd.DataBind(); Wizard Container = (Wizard) Master.FindControl("Main").FindControl("WzInspectionUpd"); List<CheckListInspectionRow> CheckListRows = new List<CheckListInspectionRow>(); string filename = Server.MapPath("~\\Inspection\\InspectionCheckList.xml"); XmlDocument InspectionCheckListXml = new XmlDocument(); InspectionCheckListXml.Load(filename); foreach (XmlNode Node in InspectionCheckListXml.SelectNodes("DocumentElement/Items")) { CheckListInspectionTable dtChecklist = new CheckListInspectionTable(); dtChecklist = (CheckListInspectionTable) objInspection.GetInspectionCheckListById(InspectionId); CheckListInspectionRow drCheckListRow = Inspection.GetCheckListRow(); Guid[] keys = { InspectionId, new Guid(Node.Attributes["ItemId"].Value) }; drCheckListRow = (CheckListInspectionRow) dtChecklist.FindByInspectionIdInspectionCheckListId(keys[0], keys[1]); TextBox txtRemarks = (TextBox) Container.FindControl("txt" + Node.Attributes["ItemId"].Value); CheckBox chkYesNo = (CheckBox) Container.FindControl("chk" + Node.Attributes["ItemId"].Value); if (null != txtRemarks) { txtRemarks.Text = Convert.ToString(drCheckListRow["Remarks"]); } if (null != chkYesNo) { chkYesNo.Checked = (bool) drCheckListRow["Checked"]; } } } }
protected void GvInspectionQueriesUpd_SelectedIndexChanged(object sender, EventArgs e) { if (fldSelectedKey.Value != "") { Guid InspectionId = new Guid(fldSelectedKey.Value); string Mode = "Upd"; if (null == ViewState["InspectionQueryListDetails"]) { ViewState["InspectionQueryListDetails"] = new Inspection().GetInspectionQueriesByInspectionId(InspectionId); } GridView GvInspectionQueries = ((GridView) WzInspectionUpd.FindControl("GvInspectionQueries" + Mode)); DataTable dtInspectionQueryListDetails = (DataTable) ViewState["InspectionQueryListDetails"]; DropDownList ddlCheckListId = ((DropDownList) WzInspectionUpd.FindControl("ddlCheckListId" + Mode)); TextBox txtQuery = ((TextBox) WzInspectionUpd.FindControl("txtQuery" + Mode)); TextBox txtQueryRemarks = ((TextBox) WzInspectionUpd.FindControl("txtQueryRemarks" + Mode)); object[] keys = { GvInspectionQueries.SelectedDataKey.Value }; DataRow dr = dtInspectionQueryListDetails.Rows.Find(keys); if (null != dr) { ddlCheckListId.SelectedValue = Convert.ToString(dr["CheckListId"]); txtQuery.Text = Convert.ToString(dr["Query"]); txtQueryRemarks.Text = Convert.ToString(dr["Remarks"]); } ((Button) WzInspectionUpd.FindControl("btnQueryAdd" + Mode)).Visible = false; ((Button) WzInspectionUpd.FindControl("btnQueryUpdate")).Visible = true; } }
protected void GvInspectionQueriesUpd_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (fldSelectedKey.Value != "") { Guid InspectionId = new Guid(fldSelectedKey.Value); string Mode = "Upd"; if (null == ViewState["InspectionQueryListDetails"]) { ViewState["InspectionQueryListDetails"] = new Inspection().GetInspectionQueriesByInspectionId(InspectionId); } GridView GvInspectionQueries = (GridView) sender; DataTable dtInspectionQueryListDetails = (DataTable) ViewState["InspectionQueryListDetails"]; int i = e.RowIndex; dtInspectionQueryListDetails.Rows[i].Delete(); dtInspectionQueryListDetails.AcceptChanges(); ViewState["InspectionQueryListDetails"] = dtInspectionQueryListDetails; GvInspectionQueries.DataSource = ViewState["InspectionQueryListDetails"]; GvInspectionQueries.DataBind(); } }
protected void GvInspectionQueriesIns_RowDeleting(object sender, GridViewDeleteEventArgs e) { Guid InspectionId = Guid.Empty; if (null == ViewState["InspectionQueryListDetails"]) { ViewState["InspectionQueryListDetails"] = new Inspection().GetInspectionQueriesByInspectionId(Guid.Empty); InspectionId = Guid.Empty; } GridView GvInspectionQueries = (GridView) sender; DataTable dtInspectionQueryListDetails = (DataTable) ViewState["InspectionQueryListDetails"]; int i = e.RowIndex; dtInspectionQueryListDetails.Rows[i].Delete(); dtInspectionQueryListDetails.AcceptChanges(); ViewState["InspectionQueryListDetails"] = dtInspectionQueryListDetails; GvInspectionQueries.DataSource = ViewState["InspectionQueryListDetails"]; GvInspectionQueries.DataBind(); }
protected void GvInspectionDetailsIns_SelectedIndexChanged(object sender, EventArgs e) { string Mode = String.Empty; switch (FvYearlySchedule.CurrentMode) { case FormViewMode.Edit: Mode = "Upd"; break; case FormViewMode.Insert: Mode = "Ins"; break; case FormViewMode.ReadOnly: Mode = "Itm"; break; default: break; } // Declare the varioables and get reference to the controls Guid ScheduleId = Guid.Empty; GridView gvInspectionDetails = ((GridView)FvYearlySchedule.FindControl("GvInspectionDetails" + Mode)); DropDownList ddlMonth = ((DropDownList)FvYearlySchedule.FindControl("ddlMonth" + Mode)); ListBox lstInspectingOffice = ((ListBox)FvYearlySchedule.FindControl("lstInspectingOffice" + Mode)); TextBox txtDetailRemarks = ((TextBox)FvYearlySchedule.FindControl("txtDetailRemarks" + Mode)); if (null == ViewState["ScheduleDetails"]) { ViewState["ScheduleDetails"] = new Inspection().GetYearlyInspectionDetailsById(Guid.Empty); ScheduleId = Guid.Empty; } if (FvYearlySchedule.CurrentMode == FormViewMode.Edit) { if (null == ViewState["SelectedOffices"]) { ViewState["SelectedOffices"] = new Inspection().GetMonthlyInspectionScheduleByDetailScheduleId((Guid)gvInspectionDetails.SelectedDataKey.Value); } ScheduleId = (Guid)FvYearlySchedule.DataKey["ScheduleId"]; } DataTable dtScheduleDetails = (DataTable)ViewState["ScheduleDetails"]; DataTable dtOfficeDetails = (DataTable)ViewState["SelectedOffices"]; object[] keys = { gvInspectionDetails.SelectedDataKey.Value }; DataRow drScheduleDetail = dtScheduleDetails.Rows.Find(keys); Guid DetailScheduleId = (Guid)drScheduleDetail["DetailScheduleId"]; if (null != drScheduleDetail) { ddlMonth.SelectedValue = Convert.ToString(drScheduleDetail["Month"]); txtDetailRemarks.Text = Convert.ToString(drScheduleDetail["Remarks"]); // Find and select each of the Offices lstInspectingOffice.ClearSelection(); foreach (DataRow row in dtOfficeDetails.Rows) { if (DetailScheduleId.Equals(row["DetailScheduleId"])) lstInspectingOffice.Items.FindByValue(row["InspectingOfficeId"].ToString()).Selected = true; } } // Show appropriate buttons ((Button)FvYearlySchedule.FindControl("btnAddInspectionDetail" + Mode)).Visible = false; ((Button)FvYearlySchedule.FindControl("btnUpdateInspectionDetail" + Mode)).Visible = true; }
//protected void GvInspectionDetailsIns_SelectedIndexChanged(object sender, EventArgs e) //{ // string Mode=String.Empty; // switch (FvYearlySchedule.CurrentMode) // { // case FormViewMode.Edit: // Mode = "Upd"; // break; // case FormViewMode.Insert: // Mode = "Ins"; // break; // case FormViewMode.ReadOnly: // Mode = "Itm"; // break; // default: // break; // } // // Declare the varioables and get reference to the controls // Guid ScheduleId = Guid.Empty; // GridView gvInspectionDetails = ((GridView) FvYearlySchedule.FindControl("GvInspectionDetails" + Mode)); // DropDownList ddlMonth = ((DropDownList) FvYearlySchedule.FindControl("ddlMonth" + Mode)); // ListBox lstInspectingOffice = ((ListBox) FvYearlySchedule.FindControl("lstInspectingOffice" + Mode)); // TextBox txtDetailRemarks = ((TextBox) FvYearlySchedule.FindControl("txtDetailRemarks" + Mode)); // if (null == ViewState["ScheduleDetails"]) // { // ViewState["ScheduleDetails"] = new Inspection().GetYearlyInspectionDetailsById(Guid.Empty); // ScheduleId = Guid.Empty; // } // if (FvYearlySchedule.CurrentMode == FormViewMode.Edit) // { // if (null == ViewState["SelectedOffices"]) // { // ViewState["SelectedOffices"] = new Inspection().GetMonthlyInspectionScheduleByDetailScheduleId((Guid)gvInspectionDetails.SelectedDataKey.Value); // } // ScheduleId = (Guid)FvYearlySchedule.DataKey["ScheduleId"]; // } // DataTable dtScheduleDetails = (DataTable) ViewState["ScheduleDetails"]; // DataTable dtOfficeDetails = (DataTable) ViewState["SelectedOffices"]; // object[] keys = { gvInspectionDetails.SelectedDataKey.Value }; // DataRow drScheduleDetail = dtScheduleDetails.Rows.Find(keys); // Guid DetailScheduleId = (Guid)drScheduleDetail["DetailScheduleId"]; // if (null != drScheduleDetail) // { // ddlMonth.SelectedValue = Convert.ToString(drScheduleDetail["Month"]); // txtDetailRemarks.Text = Convert.ToString(drScheduleDetail["Remarks"]); // // Find and select each of the Offices // lstInspectingOffice.ClearSelection(); // foreach (DataRow row in dtOfficeDetails.Rows) // { // if (DetailScheduleId.Equals(row["DetailScheduleId"])) // lstInspectingOffice.Items.FindByValue(row["InspectingOfficeId"].ToString()).Selected = true; // } // } // ((Button) FvYearlySchedule.FindControl("btnAddInspectionDetail" + Mode)).Visible = false; // ((Button) FvYearlySchedule.FindControl("btnUpdateInspectionDetail" + Mode)).Visible = true; //} protected void GvInspectionDetailsIns_RowDeleting(object sender, GridViewDeleteEventArgs e) { Guid ScheduleId = Guid.Empty; if (null == ViewState["ScheduleDetails"]) { ViewState["ScheduleDetails"] = new Inspection().GetYearlyInspectionDetailsById(Guid.Empty); ScheduleId = Guid.Empty; } if (FvYearlySchedule.CurrentMode == FormViewMode.Edit) { ScheduleId = (Guid)FvYearlySchedule.DataKey["ScheduleId"]; } GridView GvInspectionDetails = (GridView)sender; DataTable dtScheduleDetails = (DataTable)ViewState["ScheduleDetails"]; int i = e.RowIndex; dtScheduleDetails.Rows[i].Delete(); dtScheduleDetails.AcceptChanges(); ViewState["ScheduleDetails"] = dtScheduleDetails; GvInspectionDetails.DataSource = ViewState["ScheduleDetails"]; GvInspectionDetails.DataBind(); }
//public void InitofficesAssigned() //{ // dtofficesSelected = (DataTable)Session["ActsApplicable"]; // if (dtofficesSelected == null) // { // dtofficesSelected = new DataTable(); // dtofficesSelected.Columns.Add("OfficeId", typeof(Guid)); // dtofficesSelected.Columns.Add("OfficeName", typeof(bool)); // dtofficesSelected.PrimaryKey = new DataColumn[] { dtActsApplicable.Columns["OfficeId"] }; // } //} protected void btnAddDetail_Click(object sender, EventArgs e) { string Mode = String.Empty; switch (FvYearlySchedule.CurrentMode) { case FormViewMode.Edit: Mode = "Upd"; break; case FormViewMode.Insert: Mode="Ins"; break; case FormViewMode.ReadOnly: Mode="Itm"; break; default: break; } string inspectionOffices = ""; if (null == ViewState["ScheduleDetails"]) { ViewState["ScheduleDetails"] = new Inspection().GetYearlyInspectionDetailsById(Guid.Empty); } // Check if office details already exist in the ViewState if (null == ViewState["SelectedOffices"]) { // Create the Office Details schema DataTable SelectedOffices = new DataTable(); SelectedOffices = new DataTable(); SelectedOffices.Columns.Add("MonthlyScheduleId", typeof(Guid)); SelectedOffices.Columns.Add("DetailScheduleId", typeof(Guid)); SelectedOffices.Columns.Add("InspectingOfficeId", typeof(Guid)); SelectedOffices.PrimaryKey = new DataColumn[] { SelectedOffices.Columns["MonthlyScheduleId"]}; ViewState["SelectedOffices"] = SelectedOffices; } // Get the coltrols DataTable dtScheduleDetails = (DataTable)ViewState["ScheduleDetails"]; DataTable dtOfficeDetails = (DataTable)ViewState["SelectedOffices"]; GridView grdScheduleDetails = ((GridView)FvYearlySchedule.FindControl("GvInspectionDetails" + Mode)); DropDownList ddlInspectionMonth = ((DropDownList)FvYearlySchedule.FindControl("ddlMonth" + Mode)); ListBox lstInspectingOffice = ((ListBox)FvYearlySchedule.FindControl("lstInspectingOffice" + Mode)); TextBox txtDetailRemarks = ((TextBox)FvYearlySchedule.FindControl("txtDetailRemarks" + Mode)); // Create the DataRow to insert Yearly Schedule Details (each Month) DataRow drScheduleDetail = null; // Assign coluimn values Guid ScheduleId = Guid.Empty; Guid DetailScheduleId = Guid.NewGuid(); drScheduleDetail = dtScheduleDetails.NewRow(); drScheduleDetail["ScheduleId"] = ScheduleId; drScheduleDetail["DetailScheduleId"] = DetailScheduleId; drScheduleDetail["Month"] = Convert.ToDecimal(ddlInspectionMonth.SelectedValue); drScheduleDetail["Remarks"] = txtDetailRemarks.Text; // Get the selected offices foreach (ListItem Item in lstInspectingOffice.Items) { if (Item.Selected) { // Create the DataRow to insert Office details (each Office/Month) DataRow drOfficeDetail = null; drOfficeDetail = dtOfficeDetails.NewRow(); drOfficeDetail["MonthlyScheduleId"] = Guid.NewGuid(); drOfficeDetail["DetailScheduleId"] = DetailScheduleId; drOfficeDetail["InspectingOfficeId"] = Item.Value; // Generate the coma seperated text to display in the Grid inspectionOffices += Item.Text + ", "; dtOfficeDetails.Rows.Add(drOfficeDetail); } } // Remove the coma at the end of the string if (inspectionOffices.Length > 2) { inspectionOffices = inspectionOffices.Substring(0, inspectionOffices.Length - 2); } // Add the coma seperated text to the column value drScheduleDetail["OfficeName"] = inspectionOffices; // Add the row to the table dtScheduleDetails.Rows.Add(drScheduleDetail); // Store OfficeDetails and ScheduleDetails in ViewState ViewState["SelectedOffices"] = dtOfficeDetails; ViewState["ScheduleDetails"] = dtScheduleDetails; // Reset the Controls ddlInspectionMonth.SelectedIndex = -1; lstInspectingOffice.SelectedIndex = -1; txtDetailRemarks.Text = String.Empty; grdScheduleDetails.SelectedIndex = -1; // Bind the DataGrid grdScheduleDetails.DataSource = dtScheduleDetails; grdScheduleDetails.DataBind(); }
protected void FvYearlySchedule_DataBound(object sender, EventArgs e) { if (FvYearlySchedule.CurrentMode == FormViewMode.Edit) { // Get the Yearly Schedule Id Guid ScheduleId = (Guid)GvYearlyInspection.SelectedDataKey.Values["ScheduleId"]; // Get the Monthly schedule details for the selected Schedule Inspection objInspection = new Inspection(); DataTable dtScheduleDetails = objInspection.GetYearlyInspectionDetailsById(ScheduleId); DataTable dtOfficeDetails = new Inspection().GetMonthlyInspectionScheduleByDetailScheduleId(ScheduleId); string officeNames = ""; // Get the selected Offices if (dtScheduleDetails.Rows.Count > 0) { foreach (DataRow drScheduleDetail in dtScheduleDetails.Rows) { officeNames = ""; DataRow[] drOfficeDetail = dtOfficeDetails.Select("DetailScheduleId='" + drScheduleDetail["DetailScheduleId"].ToString() + "'"); for (int i = 0; i < drOfficeDetail.Length; i++) { officeNames += Convert.ToString(drOfficeDetail[i]["OfficeName"]) + ", "; } // Remove the coma at the end of the string if (officeNames.Length > 2) { officeNames = officeNames.Substring(0, officeNames.Length - 2); } drScheduleDetail["OfficeName"] = officeNames; } ViewState["ScheduleDetails"] = dtScheduleDetails; ViewState["SelectedOffices"] = dtOfficeDetails; GridView grd = (GridView)FvYearlySchedule.FindControl("GvInspectionDetailsUpd"); grd.DataSource = dtScheduleDetails; grd.SelectedIndex = -1; grd.DataBind(); } } }