Exemplo n.º 1
0
        private void GrdConditionsAdd()
        {
            if (ValidateFooterAdd())
            {
                Page.Validate("Conditions");
                if (Page.IsValid)
                {
                    int conditionId = Int32.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 = Int32.Parse(((DropDownList)grdConditions.FooterRow.FindControl("ddlConditionNumber")).SelectedValue);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    string fmType = hdfFmType.Value;
                    int viewId = Int32.Parse(hdfViewId.Value);

                    FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway();
                    fmTypeViewConditionGateway.LoadByFmTypeConditionId(fmType, companyId, conditionId);
                    string type = fmTypeViewConditionGateway.GetType(fmType, companyId, 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);

                    FmViewConditionGateway fmViewConditionGateway = new FmViewConditionGateway();
                    int refId = fmViewConditionGateway.GetLastRefIdByViewIdCompanyIdFmTypeConditionId(viewId, companyId, fmType, conditionId);
                    refId = refId + 1;

                    model.InsertForEdit(refId, 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;
                }
            }
        }
        /// <summary>
        /// SaveForEdit
        /// </summary>
        /// <param name="viewId">viewId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="fmType">fmType</param>
        public void SaveForEdit(int viewId, int companyId, string fmType)
        {
            foreach (FmViewTDS.FmViewConditionNewRow rowNew in (FmViewTDS.FmViewConditionNewDataTable)Data.Tables["FmViewConditionNew"])
            {
                FmViewCondition fmViewCondition = new FmViewCondition(null);

                if (!rowNew.Deleted && !rowNew.InDatabase)
                {
                    FmViewConditionGateway fmViewConditionGateway = new FmViewConditionGateway(null);

                    int refId = fmViewConditionGateway.GetLastRefIdByViewIdCompanyIdFmTypeConditionId(viewId, companyId, fmType, rowNew.ConditionID);
                    refId = refId + 1;

                    fmViewCondition.InsertDirect(viewId, companyId, fmType, rowNew.ConditionID, refId, rowNew.Operator, rowNew.ConditionNumber, rowNew.Value_, rowNew.Deleted);
                }

                if (!rowNew.Deleted && rowNew.InDatabase)
                {
                    FmViewConditionGateway fmViewConditionGateway = new FmViewConditionGateway();
                    fmViewConditionGateway.LoadAllByViewIdFmTypeConditionIdRefId(viewId, companyId, fmType, rowNew.ConditionID, rowNew.RefID);

                    int originalViewId = viewId;
                    int originalCompanyId = companyId;
                    string originalFmType = fmType;
                    int originalConditionId = rowNew.ConditionID;
                    int originalRefId = rowNew.RefID; //fmViewConditionGateway.GetRefId(viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID);
                    string originalOperator_ = fmViewConditionGateway.GetOperator(viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID);
                    int originalConditionNumber = fmViewConditionGateway.GetConditionNumber(viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID);
                    string originalValue_ = fmViewConditionGateway.GetValue_(viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID);
                    bool originalDeleted = fmViewConditionGateway.GetDeleted(viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID);

                    fmViewCondition.UpdateDirect(originalViewId, originalFmType, originalCompanyId, originalConditionId, originalRefId, originalOperator_, originalConditionNumber, originalValue_, originalDeleted, viewId, fmType, companyId, rowNew.ConditionID, rowNew.RefID, rowNew.Operator, rowNew.ConditionNumber, rowNew.Value_, rowNew.Deleted);
                }

                if (rowNew.Deleted && rowNew.InDatabase)
                {
                    fmViewCondition.DeleteDirectForEditView(viewId, companyId, fmType, rowNew.ConditionID, rowNew.RefID);
                }
            }
        }
Exemplo n.º 3
0
        protected void grdConditions_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("ConditionsUpdate");
            if (Page.IsValid)
            {
                int id = (int)e.Keys["ID"];

                int conditionId = Int32.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 = Int32.Parse(((DropDownList)grdConditions.Rows[e.RowIndex].Cells[2].FindControl("ddlConditionNumber")).SelectedValue);

                int companyId = Int32.Parse(hdfCompanyId.Value);
                string fmType = hdfFmType.Value;

                FmTypeViewConditionGateway fmTypeViewConditionGateway = new FmTypeViewConditionGateway();
                fmTypeViewConditionGateway.LoadByFmTypeConditionId(fmType, companyId, conditionId);
                string type = fmTypeViewConditionGateway.GetType(fmType, companyId, 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);

                FmViewConditionGateway fmViewConditionGateway = new FmViewConditionGateway();
                int viewId = Int32.Parse(hdfViewId.Value);

                int refId = fmViewConditionGateway.GetLastRefIdByViewIdCompanyIdFmTypeConditionId(viewId, companyId, fmType, conditionId);
                refId = refId + 1;

                model.UpdateForEdit(refId, id, conditionId, name, operator_, sign, conditionNumber, value, false, false);
                Session["fmViewConditionNew"] = dataSet.FmViewConditionNew;
                fmViewConditionNew = dataSet.FmViewConditionNew;
            }
            else
            {
                e.Cancel = true;
            }
        }