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; } } } } } }
/// <summary> /// LoadByViewIdCompanyIdFmType /// </summary> /// <param name="viewId">viewId</param> /// <param name="companyId">companyId</param> /// <param name="fmType">fmType</param> public void LoadByViewIdCompanyIdFmType(int viewId, int companyId, string fmType) { // process temp table DataRow[] toCopy = Data.Tables["FmViewConditionTemp"].Select(); foreach (DataRow rowTemp in toCopy) { int id = ((FmViewTDS.FmViewConditionTempRow)rowTemp).ID; int conditionId = ((FmViewTDS.FmViewConditionTempRow)rowTemp).ConditionID; string name = ((FmViewTDS.FmViewConditionTempRow)rowTemp).Name; int refId = ((FmViewTDS.FmViewConditionTempRow)rowTemp).RefID; string operator_ = ((FmViewTDS.FmViewConditionTempRow)rowTemp).Operator; string sign = ((FmViewTDS.FmViewConditionTempRow)rowTemp).Sign; int conditionNumber = ((FmViewTDS.FmViewConditionTempRow)rowTemp).ConditionNumber; string value = ((FmViewTDS.FmViewConditionTempRow)rowTemp).Value_; bool inDatabase = ((FmViewTDS.FmViewConditionTempRow)rowTemp).InDatabase; bool deleted = ((FmViewTDS.FmViewConditionTempRow)rowTemp).Deleted; Insert(conditionId, name, operator_, sign, conditionNumber, value, inDatabase, deleted); } // load from database if (Table.Rows.Count == 0) { FmViewConditionNewGateway fmViewConditionNewGateway = new FmViewConditionNewGateway(Data); fmViewConditionNewGateway.LoadByViewIdFmType(viewId, companyId, fmType); } }