/// <summary>
        /// LoadByViewIdCompanyIdWorkType
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="companyId"></param>
        /// <param name="workType"></param>
        public void LoadByViewIdCompanyIdWorkType(int viewId, int companyId, string workType)
        {
            // process temp table
            DataRow[] toCopy = Data.Tables["WorkViewConditionTemp"].Select();

            foreach (DataRow rowTemp in toCopy)
            {
                int id = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).ID;
                int conditionId = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).ConditionID;
                string name = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).Name;
                int refId = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).RefID;
                string operator_ = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).Operator;
                string sign = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).Sign;
                int conditionNumber = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).ConditionNumber;
                string value = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).Value_;
                bool inDatabase = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).InDatabase;
                bool deleted = ((WorkViewTDS.WorkViewConditionTempRow)rowTemp).Deleted;

                Insert(conditionId, name, operator_, sign, conditionNumber, value, inDatabase, deleted);
            }

            // load from database
            if (Table.Rows.Count == 0)
            {
                WorkViewConditionNewGateway workViewConditionNewGateway = new WorkViewConditionNewGateway(Data);
                workViewConditionNewGateway.LoadByViewIdWorkType(viewId, companyId, workType);
            }
        }
Esempio n. 2
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"));

                    WorkViewTDS dataSet = new WorkViewTDS();
                    dataSet.WorkViewConditionNew.Merge(workViewConditionNew, true);
                    WorkViewConditionNew model = new WorkViewConditionNew(dataSet);
                    int conditionNumber = model.GetNewConditionNumber();

                    ddlConditionNumber.SelectedValue = conditionNumber.ToString();

                    WorkTypeViewConditionGateway workTypeViewConditionGateway = new WorkTypeViewConditionGateway();
                    workTypeViewConditionGateway.LoadByWorkTypeConditionId(hdfWorkType.Value, conditionId, int.Parse(hdfCompanyId.Value));
                    string type = workTypeViewConditionGateway.GetType(hdfWorkType.Value, int.Parse(hdfCompanyId.Value), conditionId);

                    if (ddlOperator.SelectedItem == null)
                    {
                        WorkTypeViewOperatorList workTypeViewOperatorList = new WorkTypeViewOperatorList(new DataSet());
                        workTypeViewOperatorList.LoadAndAddItem(type, Int32.Parse(hdfCompanyId.Value));
                        ddlOperator.DataSource = workTypeViewOperatorList.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)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))))
            {
                WorkViewTDS dataSet = new WorkViewTDS();
                dataSet.WorkViewConditionNew.Merge(workViewConditionNew, true);
                WorkViewConditionNewGateway gateway = new WorkViewConditionNewGateway(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)
                {
                    WorkTypeViewConditionGateway workTypeViewConditionGateway = new WorkTypeViewConditionGateway();
                    workTypeViewConditionGateway.LoadByWorkTypeConditionId(hdfWorkType.Value, conditionId, int.Parse(hdfCompanyId.Value));
                    string type = workTypeViewConditionGateway.GetType(hdfWorkType.Value, int.Parse(hdfCompanyId.Value), conditionId);

                    ddlName.DataBind();
                    ddlName.SelectedValue = conditionId.ToString();

                    WorkTypeViewOperatorList workTypeViewOperatorList = new WorkTypeViewOperatorList(new DataSet());
                    workTypeViewOperatorList.LoadAndAddItem(type, Int32.Parse(hdfCompanyId.Value));
                    ddlOperator.DataSource = workTypeViewOperatorList.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
                            WorkTypeViewConditionItemList workTypeViewConditionItemList = new WorkTypeViewConditionItemList(new DataSet());
                            workTypeViewConditionItemList.LoadAndAddItemInView(hdfWorkType.Value, Int32.Parse(hdfCompanyId.Value), conditionId);
                            ddlValue.DataSource = workTypeViewConditionItemList.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
                            WorkTypeViewSubAreaList workTypeViewSubAreaList = new WorkTypeViewSubAreaList(new DataSet());
                            workTypeViewSubAreaList.LoadAndAddItem(hdfWorkType.Value, Int32.Parse(hdfCompanyId.Value), int.Parse(hdfProjectId.Value));
                            if (workTypeViewSubAreaList.Table.Rows.Count > 0)
                            {
                                ddlValue.DataSource = workTypeViewSubAreaList.Table;
                                ddlValue.DataValueField = "SubArea";
                                ddlValue.DataTextField = "SubArea";
                                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;
                            }
                        }
                    }
                }
            }
        }