Пример #1
0
        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;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)
        {
            Label lblValidateValue = ((Label)grdConditions.Rows[grdConditions.EditIndex].FindControl("lblValidateValue"));
            lblValidateValue.Visible = false;

            ImageButton ibtnAdd = ((ImageButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("ibtnAccept"));
            ibtnAdd.Visible = true;

            DropDownList ddlName = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlName"));
            DropDownList ddlOperator = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlOperator"));

            FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway();
            fmTypeViewConditionGateway.LoadByFmTypeConditionId(hdfFmType.Value, int.Parse(hdfCompanyId.Value), int.Parse(ddlName.SelectedValue));
            string type = fmTypeViewConditionGateway.GetType(hdfFmType.Value, int.Parse(hdfCompanyId.Value), int.Parse(ddlName.SelectedValue));
            int index = grdConditions.SelectedIndex;

            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") || (type == "Distance"))
            {
                ddlOperator.Enabled = true;

                TextBox tbxValue = ((TextBox)grdConditions.Rows[grdConditions.EditIndex].FindControl("tbxValue"));
                tbxValue.Visible = true;

                DropDownList ddlValue = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlValue"));
                ddlValue.Visible = false;

                RadioButton rbtnYes = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnYes"));
                rbtnYes.Visible = false;

                RadioButton rbtnNo = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnNo"));
                rbtnNo.Visible = false;
            }

            if ((type == "FixedItems") || (type == "DynamicItems") || (type == "Boolean"))
            {
                ddlOperator.Enabled = false;

                if (type == "FixedItems")
                {
                    DropDownList ddlValue = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].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), int.Parse(ddlName.SelectedValue));
                    ddlValue.DataSource = fmTypeViewConditionItemList.Table;
                    ddlValue.DataValueField = "Name";
                    ddlValue.DataTextField = "Name";
                    ddlValue.DataBind();
                    ddlValue.SelectedIndex = 0;

                    TextBox tbxValue = ((TextBox)grdConditions.Rows[grdConditions.EditIndex].FindControl("tbxValue"));
                    tbxValue.Visible = false;

                    RadioButton rbtnYes = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnYes"));
                    rbtnYes.Visible = false;

                    RadioButton rbtnNo = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnNo"));
                    rbtnNo.Visible = false;
                }

                if (type == "DynamicItems")
                {
                    DropDownList ddlValue = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlValue"));

                    // 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();
                            ddlValue.SelectedIndex = 0;

                            ibtnAdd.Visible = true;
                        }
                        else
                        {
                            ddlValue.Visible = false;
                            ibtnAdd.Visible = false;

                            lblValidateValue.Visible = true;
                        }
                    }
                    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.SelectedIndex = 0;

                            ibtnAdd.Visible = true;
                        }
                        else
                        {
                            ddlValue.Visible = false;
                            ibtnAdd.Visible = false;

                            lblValidateValue.Visible = true;
                        }
                    }

                    TextBox tbxValue = ((TextBox)grdConditions.Rows[grdConditions.EditIndex].FindControl("tbxValue"));
                    tbxValue.Visible = false;

                    RadioButton rbtnYes = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnYes"));
                    rbtnYes.Visible = false;

                    RadioButton rbtnNo = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnNo"));
                    rbtnNo.Visible = false;
                }

                if (type == "Boolean")
                {
                    DropDownList ddlValue = ((DropDownList)grdConditions.Rows[grdConditions.EditIndex].FindControl("ddlValue"));
                    ddlValue.Visible = false;

                    TextBox tbxValue = ((TextBox)grdConditions.Rows[grdConditions.EditIndex].FindControl("tbxValue"));
                    tbxValue.Visible = false;

                    RadioButton rbtnYes = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnYes"));
                    rbtnYes.Visible = true;

                    RadioButton rbtnNo = ((RadioButton)grdConditions.Rows[grdConditions.EditIndex].FindControl("rbtnNo"));
                    rbtnNo.Visible = true;
                }
            }
        }