private bool StepConditionsNext() { // Validate data bool validData = true; // Edit if there is data to save Page.Validate("ConditionsUpdate"); if (!Page.IsValid) validData = false; if (validData) { // Conditions Gridview, if the gridview is edition mode if (grdConditions.EditIndex >= 0) { grdConditions.UpdateRow(grdConditions.EditIndex, true); grdConditions.DataBind(); } } Page.Validate("ConditionsNext"); if (!Page.IsValid) validData = false; if (validData) { // Add conditions if exists at footer if (ValidateFooterNext()) { GrdConditionsAdd(); } // create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); // Process new conditions FmViewConditionNew model = new FmViewConditionNew(dataSet); tbxLogic.Text = model.GetConditionsByDefault(); // Get changes fmViewConditionNew.Rows.Clear(); fmViewConditionNew.Merge(model.Table); // Store tables Session.Remove("fmViewConditionNewDummy"); Session["fmViewConditionNew"] = fmViewConditionNew; hdfStep.Value = "StepConditions"; return true; } else { return false; } }
private bool StepLogicNext() { Page.Validate("Logic"); if (Page.IsValid) { // Load FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_SORT.Merge(fmTypeViewSort, true); FmTypeViewSort model = new FmTypeViewSort(dataSet); if (dataSet.LFS_FM_TYPE_VIEW_SORT.Rows.Count <= 0) { model.LoadByFmTypeInView(hdfFmType.Value, int.Parse(hdfCompanyId.Value), true); } // Store tables fmTypeViewSort = (FmViewTDS.LFS_FM_TYPE_VIEW_SORTDataTable)model.Table; Session["fmTypeViewSort"] = fmTypeViewSort; return true; } else { return false; } }
private bool StepColumnsToDisplayNext() { ViewState["columnsToDisplayPageIndex"] = grdColumnsToDisplay.PageIndex; Page.Validate("ColumsToDisplay"); if (Page.IsValid) { StepColumnsToDisplayProcessGrid(); fmViewDisplayTemp.Rows.Clear(); // Create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_DISPLAY.Merge(fmTypeViewDisplay, true); dataSet.FmViewDisplayTemp.Merge(fmViewDisplayTemp, true); // Process new sections FmViewDisplayTemp model = new FmViewDisplayTemp(dataSet); model.Process(int.Parse(hdfViewId.Value), hdfFmType.Value, int.Parse(hdfCompanyId.Value)); // Get changes fmViewDisplayTemp.Rows.Clear(); fmViewDisplayTemp.Merge(model.Table); // Store tables Session.Remove("fmTypeViewDisplayDummy"); Session["fmTypeViewDisplay"] = fmTypeViewDisplay; Session["fmViewDisplayTemp"] = fmViewDisplayTemp; return true; } else { return false; } }
private void StepColumnsToDisplayProcessGrid() { FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_DISPLAY.Merge(fmTypeViewDisplay, true); FmTypeViewDisplay model = new FmTypeViewDisplay(dataSet); // Update rows if (Session["fmTypeViewDisplayDummy"] == null) { foreach (GridViewRow row in grdColumnsToDisplay.Rows) { int displayId = int.Parse(grdColumnsToDisplay.DataKeys[row.RowIndex].Values["DisplayID"].ToString()); bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked; model.Update(hdfFmType.Value, int.Parse(hdfCompanyId.Value), displayId, selected); } model.Table.AcceptChanges(); fmTypeViewDisplay = (FmViewTDS.LFS_FM_TYPE_VIEW_DISPLAYDataTable)model.Table; Session["fmTypeViewDisplay"] = fmTypeViewDisplay; } }
protected void grdConditions_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { int conditionId = 0; conditionId = int.Parse(((DropDownList)e.Row.FindControl("ddlName")).SelectedValue); DropDownList ddlOperator = ((DropDownList)e.Row.FindControl("ddlOperator")); if (conditionId > 0) { DropDownList ddlConditionNumber = ((DropDownList)e.Row.FindControl("ddlConditionNumber")); FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew model = new FmViewConditionNew(dataSet); int conditionNumber = model.GetNewConditionNumber(); ddlConditionNumber.SelectedValue = conditionNumber.ToString(); FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway(); fmTypeViewConditionGateway.LoadByFmTypeConditionId(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string type = fmTypeViewConditionGateway.GetType(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); if (ddlOperator.SelectedItem == null) { FmTypeViewOperatorList fmTypeViewOperatorList = new FmTypeViewOperatorList(new DataSet()); fmTypeViewOperatorList.LoadAndAddItem(type, Int32.Parse(hdfCompanyId.Value)); ddlOperator.DataSource = fmTypeViewOperatorList.Table; ddlOperator.DataValueField = "Sign"; ddlOperator.DataTextField = "Operator"; ddlOperator.DataBind(); ddlOperator.SelectedIndex = 0; } if ((type == "String") || (type == "Date") || (type == "Int") || (type == "Decimal")) { ddlOperator.Enabled = true; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = true; DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if ((type == "FixedItems") || (type == "DynamicItems") || (type == "Boolean")) { ddlOperator.Enabled = false; if (type == "FixedItems") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = true; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if (type == "DynamicItems") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = true; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if (type == "Boolean") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = false; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = true; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = true; } } } } if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))) { FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNewGateway gateway = new FmViewConditionNewGateway(dataSet); int id = int.Parse(((Label)e.Row.FindControl("lblId")).Text); int conditionId = gateway.GetConditionId(id); DropDownList ddlName = ((DropDownList)e.Row.FindControl("ddlName")); DropDownList ddlOperator = ((DropDownList)e.Row.FindControl("ddlOperator")); if (conditionId > 0) { FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway(); fmTypeViewConditionGateway.LoadByFmTypeConditionId(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string type = fmTypeViewConditionGateway.GetType(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); ddlName.DataBind(); ddlName.SelectedValue = conditionId.ToString(); FmTypeViewOperatorList fmTypeViewOperatorList = new FmTypeViewOperatorList(new DataSet()); fmTypeViewOperatorList.LoadAndAddItem(type, Int32.Parse(hdfCompanyId.Value)); ddlOperator.DataSource = fmTypeViewOperatorList.Table; ddlOperator.DataValueField = "Sign"; ddlOperator.DataTextField = "Operator"; ddlOperator.DataBind(); ddlOperator.SelectedValue = gateway.GetSign(id); if ((type == "String") || (type == "Date") || (type == "Int") || (type == "Decimal") || (type == "Distance")) { ddlOperator.Enabled = true; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = true; tbxValue.Text = gateway.GetValue_(id); DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if ((type == "FixedItems") || (type == "DynamicItems") || (type == "Boolean")) { ddlOperator.Enabled = false; if (type == "FixedItems") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = true; // Prepare initial data // ... For view type FmTypeViewConditionItemList fmTypeViewConditionItemList = new FmTypeViewConditionItemList(new DataSet()); fmTypeViewConditionItemList.LoadAndAddItemInView(hdfFmType.Value, Int32.Parse(hdfCompanyId.Value), conditionId); ddlValue.DataSource = fmTypeViewConditionItemList.Table; ddlValue.DataValueField = "Name"; ddlValue.DataTextField = "Name"; ddlValue.DataBind(); ddlValue.SelectedValue = gateway.GetValue_(id); TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if (type == "DynamicItems") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = true; // Prepare initial data // ... For view type if (ddlName.SelectedItem.Text == "Category") { //Category for Units Category category = new Category(categoriesTDS); category.LoadAllUnitTypes(Int32.Parse(hdfCompanyId.Value)); Session["categoriesTDSForAddView"] = categoriesTDS; if (category.Table.Rows.Count > 0) { GetNodeForCategory(0, ddlValue);//Equipments level = -1; GetNodeForCategory(-1, ddlValue);//Vehicles ddlValue.DataBind(); string categorySelected = gateway.GetValue_(id); foreach (ListItem li in ddlValue.Items) { if (li.Text.Contains(categorySelected)) { li.Selected = true; } } } else { ddlValue.Visible = false; } } else { //State for Services FmTypeViewStateList fmTypeViewStateList = new FmTypeViewStateList(new DataSet()); fmTypeViewStateList.LoadAndAddItem(Int32.Parse(hdfCompanyId.Value)); if (fmTypeViewStateList.Table.Rows.Count > 0) { ddlValue.DataSource = fmTypeViewStateList.Table; ddlValue.DataValueField = "State"; ddlValue.DataTextField = "State"; ddlValue.DataBind(); ddlValue.SelectedValue = gateway.GetValue_(id); } else { ddlValue.Visible = false; } } TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = false; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = false; } if (type == "Boolean") { DropDownList ddlValue = ((DropDownList)e.Row.FindControl("ddlValue")); ddlValue.Visible = false; TextBox tbxValue = ((TextBox)e.Row.FindControl("tbxValue")); tbxValue.Visible = false; RadioButton rbtnYes = ((RadioButton)e.Row.FindControl("rbtnYes")); rbtnYes.Visible = true; RadioButton rbtnNo = ((RadioButton)e.Row.FindControl("rbtnNo")); rbtnNo.Visible = true; if (gateway.GetValue_(id) == "Yes") { rbtnYes.Checked = true; } else { rbtnNo.Checked = true; } } } } } }
private bool StepColumnsToDisplayNext() { ViewState["columnsToDisplayPageIndex"] = grdColumnsToDisplay.PageIndex; Page.Validate("ColumsToDisplay"); if (Page.IsValid) { hdfStep.Value = "StepColumnsToDisplay"; StepColumnsToDisplayProcessGrid(); fmViewDisplayTemp.Rows.Clear(); // Create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_DISPLAY.Merge(fmTypeViewDisplay, true); dataSet.FmViewDisplayTemp.Merge(fmViewDisplayTemp, true); // Process int companyId = Int32.Parse(hdfCompanyId.Value); string fmType = hdfFmType.Value; int viewId = Int32.Parse(hdfViewId.Value); FmViewDisplayTemp model = new FmViewDisplayTemp(dataSet); model.ProcessForEdit(viewId, fmType, companyId); // get changes fmViewDisplayTemp.Rows.Clear(); fmViewDisplayTemp.Merge(model.Table); // Store tables Session.Remove("fmTypeViewDisplayDummy"); Session["fmTypeViewDisplay"] = fmTypeViewDisplay; Session["fmViewDisplayTemp"] = fmViewDisplayTemp; // Load conditions for next step dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); dataSet.FmViewConditionTemp.Merge(fmViewConditionTemp, true); FmViewConditionNew modelConditionNew = new FmViewConditionNew(dataSet); modelConditionNew.LoadByViewIdCompanyIdFmType(viewId, companyId, fmType); // Store tables fmViewConditionNew = (FmViewTDS.FmViewConditionNewDataTable)modelConditionNew.Table; Session["fmViewConditionNew"] = fmViewConditionNew; return true; } else { return false; } }
private string GetWhere() { // Process view FmViewTDS dataset = new FmViewTDS(); dataset.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew modelFmViewConditionNew = new FmViewConditionNew(dataset); string whereClause = ""; whereClause = modelFmViewConditionNew.ParserLogic(tbxLogic.Text, hdfFmType.Value, int.Parse(hdfCompanyId.Value)); return whereClause; }
// ///////////////////////////////////////////////////////////////////////////////////////////////////// // // STEP6 - SUMMARY // // //////////////////////////////////////////////////////////////////////// // STEP6 - SUMMARY - METHODS // private void StepSummaryIn() { // Set instruction Label instruction = (Label)this.Master.FindControl("lblInstruction"); instruction.Text = "Summary"; // Tag Page hdfStep.Value = "StepSummary"; hdfUpdate.Value = "yes"; // Initialize summary FmView fmView = new FmView(fmViewTDS); // Process view FmViewTDS dataset = new FmViewTDS(); dataset.FmViewDisplayTemp.Merge(fmViewDisplayTemp, true); dataset.FmViewConditionNew.Merge(fmViewConditionNew, true); dataset.FmViewSortTemp.Merge(fmViewSortTemp, true); FmViewDisplayTemp modelFmViewDisplayTemp = new FmViewDisplayTemp(dataset); FmViewConditionNew modelFmViewConditionNew = new FmViewConditionNew(dataset); FmViewSortTemp modelFmViewSortTemp = new FmViewSortTemp(dataset); string summary = ""; summary = summary + "Name: " + tbxName.Text + "\n\n"; summary = summary + "Columns To Display; " + modelFmViewDisplayTemp.GetColumnsToDisplay() + "\n\n"; summary = summary + "Conditions: " + modelFmViewConditionNew.GetConditionsForSummary(hdfFmType.Value, int.Parse(hdfCompanyId.Value)) + "\n\n"; summary = summary + "Logical Expression: " + tbxLogic.Text + "\n\n"; summary = summary + "Order by: " + modelFmViewSortTemp.GetSortForSummary() + "\n\n"; tbxSummary.Text = summary; }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Validate query string if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["fm_type"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in view_add.aspx"); } // Security check if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_ADD"]))) { if ((string)Request.QueryString["fm_type"] == "Services") { if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"]))) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } } if ((string)Request.QueryString["fm_type"] == "Units") { if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_VIEW"]))) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } } } // Tag page hdfFmType.Value = (string)Request.QueryString["fm_type"]; hdfCompanyId.Value = Session["companyID"].ToString(); hdfUpdate.Value = "no"; ViewState["columnsToDisplayPageIndex"] = 0; ViewState["sortPageIndex"] = 0; Session.Remove("fmTypeViewDisplay"); Session.Remove("fmTypeViewDisplayDummy"); Session.Remove("fmTypeViewSort"); Session.Remove("fmTypeViewSortDummy"); Session.Remove("fmViewDisplayTemp"); Session.Remove("fmViewSortTemp"); Session.Remove("fmViewConditionNew"); Session.Remove("fmViewConditionNewDummy"); Session.Remove("categoriesTDSForAddView"); FmViewGateway fmViewGateway = new FmViewGateway(); hdfViewId.Value = (fmViewGateway.GetLastViewId() + 1).ToString().Trim(); // Prepare initial data // ... For view type FmViewTypeList fmViewTypeList = new FmViewTypeList(new DataSet()); fmViewTypeList.LoadAndAddItem("(Select a type)", Int32.Parse(hdfCompanyId.Value)); ddlType.DataSource = fmViewTypeList.Table; ddlType.DataValueField = "Type"; ddlType.DataTextField = "Type"; ddlType.DataBind(); ddlType.SelectedIndex = 0; // ... Global Views check if (!Convert.ToBoolean(Session["sgLFS_GLOBALVIEWS_ADD"])) { ddlType.Items.Remove("Global"); } // If coming from // ... services_navigator.aspx, services_navigator2.aspx, units_navigator.aspx or units_navigator2.aspx if ((Request.QueryString["source_page"] == "services_navigator.aspx") || (Request.QueryString["source_page"] == "services_navigator2.aspx") || (Request.QueryString["source_page"] == "units_navigator.aspx") || (Request.QueryString["source_page"] == "unit_navigator2.aspx")) { // ... For Grids fmViewTDS = new FmViewTDS(); fmTypeViewDisplay = new FmViewTDS.LFS_FM_TYPE_VIEW_DISPLAYDataTable(); fmTypeViewSort = new FmViewTDS.LFS_FM_TYPE_VIEW_SORTDataTable(); fmViewDisplayTemp = new FmViewTDS.FmViewDisplayTempDataTable(); fmViewSortTemp = new FmViewTDS.FmViewSortTempDataTable(); fmViewConditionNew = new FmViewTDS.FmViewConditionNewDataTable(); // ... for Categories categoriesTDS = new CategoriesTDS(); // ... Store datasets Session["fmViewTDS"] = fmViewTDS; Session["fmTypeViewDisplay"] = fmTypeViewDisplay; Session["fmTypeViewSort"] = fmTypeViewSort; Session["fmViewDisplayTemp"] = fmViewDisplayTemp; Session["fmViewSortTemp"] = fmViewSortTemp; Session["fmViewConditionNew"] = fmViewConditionNew; Session["categoriesTDSForAddView"] = categoriesTDS; } // StepSection1In wzViews.ActiveStepIndex = 0; StepBeginIn(); } else { // Restore datasets fmViewTDS = (FmViewTDS)Session["fmViewTDS"]; fmTypeViewDisplay = (FmViewTDS.LFS_FM_TYPE_VIEW_DISPLAYDataTable)Session["fmTypeViewDisplay"]; fmTypeViewSort = (FmViewTDS.LFS_FM_TYPE_VIEW_SORTDataTable)Session["fmTypeViewSort"]; fmViewDisplayTemp = (FmViewTDS.FmViewDisplayTempDataTable)Session["fmViewDisplayTemp"]; fmViewSortTemp = (FmViewTDS.FmViewSortTempDataTable)Session["fmViewSortTemp"]; fmViewConditionNew = (FmViewTDS.FmViewConditionNewDataTable)Session["fmViewConditionNew"]; categoriesTDS = (CategoriesTDS)Session["categoriesTDSForAddView"]; } // Control for postback hdfTag.Value = DateTime.Now.ToLongTimeString(); }
private string GetOrder() { // Process view FmViewTDS dataset = new FmViewTDS(); dataset.FmViewSortTemp.Merge(fmViewSortTemp, true); FmViewSortTemp modelFmSortTemp = new FmViewSortTemp(dataset); string orderClause = ""; orderClause = modelFmSortTemp.GetSortForSql(); if (orderClause == "") { if (hdfFmType.Value == "Services") { orderClause = "LFS.ServiceID"; } if (hdfFmType.Value == "Units") { orderClause = "FMU.UnitID"; } } return " ORDER BY " + orderClause; }
protected void grdConditions_RowUpdating(object sender, GridViewUpdateEventArgs e) { Page.Validate("ConditionsUpdate"); if (Page.IsValid) { int id = (int)e.Keys["ID"]; int conditionId = int.Parse(((DropDownList)grdConditions.Rows[e.RowIndex].Cells[3].FindControl("ddlName")).SelectedValue); string name = ((DropDownList)grdConditions.Rows[e.RowIndex].Cells[3].FindControl("ddlName")).SelectedItem.Text; DropDownList ddlOperator = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlOperator")); string operator_ = ddlOperator.SelectedItem.Text; string sign = ddlOperator.SelectedValue; int conditionNumber = int.Parse(((DropDownList)grdConditions.Rows[e.RowIndex].Cells[2].FindControl("ddlConditionNumber")).SelectedValue); FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway(); fmTypeViewConditionGateway.LoadByFmTypeConditionId(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string type = fmTypeViewConditionGateway.GetType(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string value = ""; if ((type == "String") || (type == "Date") || (type == "Int") || (type == "Decimal") ) { value = ((TextBox)grdConditions.Rows[e.RowIndex].Cells[5].FindControl("tbxValue")).Text; } if ((type == "FixedItems") || (type == "DynamicItems")) { value = ((DropDownList)grdConditions.Rows[e.RowIndex].Cells[5].FindControl("ddlValue")).SelectedItem.Text.Replace("-", ""); value = value.Trim(); } if (type == "Boolean") { if (((RadioButton)grdConditions.Rows[e.RowIndex].Cells[5].FindControl("rbtnYes")).Checked) value = "Yes"; if (((RadioButton)grdConditions.Rows[e.RowIndex].Cells[5].FindControl("rbtnNo")).Checked) value = "No"; } FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew model = new FmViewConditionNew(dataSet); model.Update(id, conditionId, name, operator_, sign, conditionNumber, value, false, false); Session["fmViewConditionNew"] = dataSet.FmViewConditionNew; fmViewConditionNew = dataSet.FmViewConditionNew; } else { e.Cancel = true; } }
// ///////////////////////////////////////////////////////////////////////////////////////////////////// // // STEP3 - CONDITIONS // // ///////////////////////////////////////////////////////////////////////////////////////////////////// // STEP3 - CONDITIONS - EVENTS // protected void grdConditions_RowDeleting(object sender, GridViewDeleteEventArgs e) { // Conditions Gridview, if the gridview is edition mode if (grdConditions.EditIndex >= 0) { grdConditions.UpdateRow(grdConditions.EditIndex, true); } // Delete conditions int id = (int)e.Keys["ID"]; FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew model = new FmViewConditionNew(dataSet); model.Delete(id); Session["fmViewConditionNew"] = dataSet.FmViewConditionNew; }
private bool StepConditionsNext() { // Validate data bool validData = true; // Edit if there is data to save Page.Validate("ConditionsUpdate"); if (!Page.IsValid) validData = false; if (validData) { // Conditions Gridview, if the gridview is edition mode if (grdConditions.EditIndex >= 0) { grdConditions.UpdateRow(grdConditions.EditIndex, true); grdConditions.DataBind(); } } Page.Validate("ConditionsNext"); if (!Page.IsValid) validData = false; if (validData) { // Add conditions if exists at footer if (ValidateFooterNext()) { GrdConditionsAdd(); } int companyId = Int32.Parse(hdfCompanyId.Value); int viewId = Int32.Parse(hdfViewId.Value); FmViewGateway fmViewGateway = new FmViewGateway(); fmViewGateway.LoadByViewId(viewId, companyId ); fmViewConditionTemp.Rows.Clear(); // Create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); dataSet.FmViewConditionTemp.Merge(fmViewConditionTemp, true); // Process conditions FmViewConditionTemp model = new FmViewConditionTemp(dataSet); FmViewConditionNew modelLogic = new FmViewConditionNew(dataSet); string originalLogic = fmViewGateway.GetLogic(viewId); string newLogic = modelLogic.GetConditionsByDefault(); ArrayList aConditions = new ArrayList(); aConditions = modelLogic.GetConditions(); bool isConditionsUpdate = false; if (originalLogic.Trim() != newLogic.Trim()) { foreach (string conditionNumber in aConditions) { if (!originalLogic.Contains(conditionNumber)) { isConditionsUpdate = true; } } if (!isConditionsUpdate) { if (Session["conditionsUpdate"] != null) { if (Session["conditionsUpdate"].ToString() == "true") { isConditionsUpdate = true; } } } } else { tbxLogic.Text = originalLogic.Trim(); } if (isConditionsUpdate) { tbxLogic.Text = newLogic.Trim(); } else { tbxLogic.Text = originalLogic.Trim(); } // Get changes fmViewConditionNew.Rows.Clear(); fmViewConditionNew.Merge(modelLogic.Table); fmViewConditionTemp.Rows.Clear(); fmViewConditionTemp.Merge(model.Table); // Store tables Session.Remove("fmViewConditionNewDummy"); Session.Remove("fmViewConditionTempDummy"); Session["fmViewConditionNew"] = fmViewConditionNew; Session["fmViewConditionTemp"] = fmViewConditionTemp; Session["conditionsUpdate"] = null; return true; } else { return false; } }
private bool StepSortByNext() { ViewState["sortPageIndex"] = grdSort.PageIndex; Page.Validate("SortBy"); if (Page.IsValid) { StepSortProcessGrid(); fmViewSortTemp.Rows.Clear(); // Create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_SORT.Merge(fmTypeViewSort, true); dataSet.FmViewSortTemp.Merge(fmViewSortTemp, true); // Process sort by FmViewSortTemp model = new FmViewSortTemp(dataSet); model.Process(int.Parse(hdfViewId.Value), hdfFmType.Value, int.Parse(hdfCompanyId.Value)); // Get changes fmViewSortTemp.Rows.Clear(); fmViewSortTemp.Merge(model.Table); // Store tables Session.Remove("fmTypeViewSortDummy"); Session["fmTypeViewSort"] = fmTypeViewSort; Session["fmViewSortTemp"] = fmViewSortTemp; return true; } else { return false; } }
private void GrdConditionsAdd() { if (ValidateFooterAdd()) { Page.Validate("Conditions"); if (Page.IsValid) { int conditionId = int.Parse(((DropDownList)grdConditions.FooterRow.FindControl("ddlName")).SelectedValue); string name = ((DropDownList)grdConditions.FooterRow.FindControl("ddlName")).SelectedItem.Text; string operator_ = ((DropDownList)grdConditions.FooterRow.FindControl("ddlOperator")).SelectedItem.Text; string sign = ((DropDownList)grdConditions.FooterRow.FindControl("ddlOperator")).SelectedValue; int conditionNumber = int.Parse(((DropDownList)grdConditions.FooterRow.FindControl("ddlConditionNumber")).SelectedValue); FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway(); fmTypeViewConditionGateway.LoadByFmTypeConditionId(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string type = fmTypeViewConditionGateway.GetType(hdfFmType.Value, int.Parse(hdfCompanyId.Value), conditionId); string value = ""; if ((type == "String") || (type == "Date") || (type == "Int") || (type == "Decimal")) { value = ((TextBox)grdConditions.FooterRow.FindControl("tbxValue")).Text; } if ((type == "FixedItems") || (type == "DynamicItems")) { value = ((DropDownList)grdConditions.FooterRow.FindControl("ddlValue")).SelectedItem.Text.Replace("-", ""); value = value.Trim(); } if (type == "Boolean") { if (((RadioButton)grdConditions.FooterRow.FindControl("rbtnYes")).Checked) value = "Yes"; if (((RadioButton)grdConditions.FooterRow.FindControl("rbtnNo")).Checked) value = "No"; } FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew model = new FmViewConditionNew(dataSet); model.Insert(conditionId, name, operator_, sign, conditionNumber, value, false, false); Session.Remove("fmViewConditionNewDummy"); fmViewConditionNew = dataSet.FmViewConditionNew; Session["fmViewConditionNew"] = dataSet.FmViewConditionNew; grdConditions.DataBind(); grdConditions.PageIndex = grdConditions.PageCount - 1; } } }
private void StepSortProcessGrid() { FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_SORT.Merge(fmTypeViewSort, true); FmTypeViewSort model = new FmTypeViewSort(dataSet); // Update rows if (Session["fmTypeViewSortDummy"] == null) { foreach (GridViewRow row in grdSort.Rows) { int sortId = int.Parse(grdSort.DataKeys[row.RowIndex].Values["SortID"].ToString()); bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked; int order = 0; try { order = int.Parse(((DropDownList)row.FindControl("ddlOrder")).SelectedValue); } catch { order = 0; } model.Update(hdfFmType.Value, int.Parse(hdfCompanyId.Value), sortId, order, selected); } model.Table.AcceptChanges(); fmTypeViewSort = (FmViewTDS.LFS_FM_TYPE_VIEW_SORTDataTable)model.Table; Session["fmTypeViewSort"] = fmTypeViewSort; } }
private void Save() { // Process view FmViewTDS dataset = new FmViewTDS(); dataset.FmViewDisplayTemp.Merge(fmViewDisplayTemp, true); dataset.FmViewConditionNew.Merge(fmViewConditionNew, true); dataset.FmViewSortTemp.Merge(fmViewSortTemp, true); FmViewDisplayTemp modelFmViewDisplayTemp = new FmViewDisplayTemp(dataset); FmViewConditionNew modelFmViewConditionNew = new FmViewConditionNew(dataset); FmViewSortTemp modelFmViewSortTemp = new FmViewSortTemp(dataset); // Get parameters int viewId = int.Parse(hdfViewId.Value); int companyId = int.Parse(hdfCompanyId.Value); int loginId = Convert.ToInt32(Session["loginID"]); string name = tbxName.Text; string type = ddlType.SelectedValue; string logic = tbxLogic.Text; string sqlCommand = GetSqlCommand(); string fmType = hdfFmType.Value; if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_ADD"])) && ((string)Request.QueryString["fm_type"] == "Services")) { if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"])) && ((string)Request.QueryString["fm_type"] == "Services")) { type = "Personal"; } } if (!(Convert.ToBoolean(Session["sgLFS_VIEWS_ADD"])) && ((string)Request.QueryString["fm_type"] == "Units")) { if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_VIEW"])) && ((string)Request.QueryString["fm_type"] == "Units")) { type = "Personal"; } } // Save to database DB.Open(); DB.BeginTransaction(); try { FmView fmView = new FmView(null); fmView.InsertDirect(viewId, loginId, name, type, logic, sqlCommand, fmType, false, companyId); modelFmViewDisplayTemp.Save(); modelFmViewConditionNew.Save(viewId, companyId, fmType); modelFmViewSortTemp.Save(viewId, fmType, companyId); DB.CommitTransaction(); } catch (Exception ex) { DB.RollbackTransaction(); string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' ')); Response.Redirect(url); } }
// //////////////////////////////////////////////////////////////////////// // // STEP4 - LOGIC // // //////////////////////////////////////////////////////////////////////// // STEP4 - LOGIC - AUXILIAR EVENTS // protected void cvLogic_ServerValidate(object source, ServerValidateEventArgs args) { LogicValidator logicValidator = new LogicValidator(); string message; ArrayList conditions = new ArrayList(); // Create dataset FmViewTDS dataSet = new FmViewTDS(); dataSet.FmViewConditionNew.Merge(fmViewConditionNew, true); // Process new conditions FmViewConditionNew model = new FmViewConditionNew(dataSet); conditions = model.GetConditions(); // Get changes fmViewConditionNew.Rows.Clear(); fmViewConditionNew.Merge(model.Table); // Store tables Session["fmViewConditionNew"] = fmViewConditionNew; if (conditions.Count > 0) { bool bOk = logicValidator.Validate(tbxLogic.Text, conditions, out message); if (bOk) { args.IsValid = true; } else { args.IsValid = false; cvLogic.ErrorMessage = message; } } else { if (tbxLogic.Text == "") { args.IsValid = true; } else { args.IsValid = false; cvLogic.ErrorMessage = "There are no conditions, The logical expression must be empty"; } } }
private bool StepBeginNext() { Page.Validate("StepBegin"); if (Page.IsValid) { // Load FmViewTDS dataSet = new FmViewTDS(); dataSet.LFS_FM_TYPE_VIEW_DISPLAY.Merge(fmTypeViewDisplay, true); FmTypeViewDisplay model = new FmTypeViewDisplay(dataSet); if (dataSet.LFS_FM_TYPE_VIEW_DISPLAY.Rows.Count <= 0) { model.LoadByFmType(hdfFmType.Value, int.Parse(hdfCompanyId.Value)); } // Store tables fmTypeViewDisplay = (FmViewTDS.LFS_FM_TYPE_VIEW_DISPLAYDataTable)model.Table; Session["fmTypeViewDisplay"] = fmTypeViewDisplay; return true; } return false; }
/// <summary> /// InitData. /// </summary> protected override void InitData() { _data = new FmViewTDS(); }
private string GetWhere() { FmViewTDS dataset = new FmViewTDS(); dataset.FmViewConditionNew.Merge(fmViewConditionNew, true); FmViewConditionNew modelFmViewConditionNew = new FmViewConditionNew(dataset); int companyId = Int32.Parse(hdfCompanyId.Value); string fmType = hdfFmType.Value; string whereClause = ""; whereClause = modelFmViewConditionNew.ParserLogic(tbxLogic.Text, fmType, companyId); return whereClause; }