Esempio n. 1
0
        // ////////////////////////////////////////////////////////////////////////
        //
        // 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 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;
            }
        }