예제 #1
0
        public static void FormEvaluation(this HtmlHelper helper, FormEvaluation formEvaluation, FormState formState = FormState.DataEntryMode, bool withoutahp = false, bool newgenerate = false)
        {
            var generateForm = FormGeneratorComponent.Instance.FormEvaluationFacade.GenerateEvaluation(formEvaluation, withoutahp, newgenerate);

            generateForm.FormState = formState;
            GeneratorEvaluationControls(helper, generateForm);
        }
예제 #2
0
        private static void GeneratorEvaluationControls(HtmlHelper helper, FormEvaluation formEvaluation)
        {
            if (formEvaluation == null)
            {
                return;
            }
            var stringWriter = new StringWriter();
            var writer       = new Html32TextWriter(stringWriter);



            writer.AddAttribute(HtmlTextWriterAttribute.Class.ToString(), "fitper");
            writer.RenderBeginTag(HtmlTextWriterTag.Div.ToString());

            writer.AddAttribute(HtmlTextWriterAttribute.Id.ToString(), "FormId");
            writer.AddAttribute(HtmlTextWriterAttribute.Name.ToString(), "FormId");
            writer.AddAttribute(HtmlTextWriterAttribute.Value.ToString(), formEvaluation.ControlId);
            writer.AddAttribute(HtmlTextWriterAttribute.Type.ToString(), "hidden");
            writer.RenderBeginTag(HtmlTextWriterTag.Input.ToString());
            writer.RenderEndTag();


            foreach (Control controlvalueModel in formEvaluation.Controls)
            {
                controlvalueModel.Writer    = writer;
                controlvalueModel.FormState = formEvaluation.FormState;
                if (formEvaluation.GetFormControl != null)
                {
                    controlvalueModel.Value = formEvaluation.GetFormControl.ContainsKey(controlvalueModel.Id) ? formEvaluation.GetFormControl[controlvalueModel.Id] : null;
                }
                controlvalueModel.Generate();


                writer.AddAttribute(HtmlTextWriterAttribute.Id.ToString(), "Order-" + controlvalueModel.Id);
                writer.AddAttribute(HtmlTextWriterAttribute.Name.ToString(), "Order-" + controlvalueModel.Id);
                writer.AddAttribute(HtmlTextWriterAttribute.Value.ToString(), controlvalueModel.Order.ToString());
                writer.AddAttribute(HtmlTextWriterAttribute.Type.ToString(), "hidden");
                writer.RenderBeginTag(HtmlTextWriterTag.Input.ToString());
                writer.RenderEndTag();
            }

            writer.RenderEndTag();
            var resourceScript = helper.ViewContext.GenerateResourceScript();
            var format         = resourceScript + stringWriter;

            helper.ViewContext.Writer.Write(format);
        }
예제 #3
0
        public ActionResult GenerateEvaluation(string Id, int?count, int?minvalue, int?maxvalue, string culture, bool newGenerate = false)
        {
            var model = FormGeneratorComponent.Instance.FormEvaluationFacade.GetByCulture(Id, culture);

            if (model == null || newGenerate)
            {
                model = new FormEvaluation()
                {
                    ControlId    = Id,
                    OpinionCount = count,
                    MinScale     = minvalue,
                    MaxScale     = maxvalue
                };
            }
            ViewBag.newGenerate = newGenerate;
            ViewBag.Withoutahp  = true;
            return(PartialView("PVEvaluation", model));
        }
예제 #4
0
        public ActionResult SetEvaluationListControl(FormCollection collection)
        {
            try
            {
                var list = new List <FormEvaluation>();
                if (string.IsNullOrEmpty(collection["ControlId"]))
                {
                    ShowMessage("خطایی در ذخیره اطلاعات رخ داده است", "خطا", messageIcon: MessageIcon.Error);
                    return(Content("false"));
                }
                var dictionarymaster = new Dictionary <string, double>();
                var controlsid       = collection["ControlId"].Split(',');
                foreach (var id in controlsid)
                {
                    var formEvaluation = new FormEvaluation
                    {
                        ControlId    = id,
                        OpinionCount =
                            string.IsNullOrEmpty(collection["OpinionCount-" + id])
                                ? (int?)null
                                : collection["OpinionCount-" + id].ToInt(),
                        MaxScale =
                            string.IsNullOrEmpty(collection["MaxScale-" + id])
                                ? (int?)null
                                : collection["MaxScale-" + id].ToInt(),
                        MinScale =
                            string.IsNullOrEmpty(collection["MinScale-" + id])
                                ? (int?)null
                                : collection["MinScale-" + id].ToInt(),
                    };
                    var enumerable = collection.AllKeys.Where(x => x.StartsWith("EV-" + id));
                    foreach (var controlId in enumerable)
                    {
                        var textBox = new TextBox
                        {
                            Id      = controlId,
                            Name    = controlId,
                            Caption = string.Format("نظر {0}", collection["Order-" + controlId]),
                            Order   = collection["Order-" + controlId].ToInt()
                        };
                        formEvaluation.Controls.Add(textBox);
                    }
                    var dictionary = new Dictionary <string, double>();
                    foreach (var controlId in enumerable)
                    {
                        if (string.IsNullOrEmpty(controlId))
                        {
                            continue;
                        }
                        dictionary.Add(controlId, collection[controlId].ToFloat());
                        formEvaluation.GetFormControl.Add(controlId, collection[controlId]);
                    }
                    dictionarymaster.Add(id, AHP.GetWeight(dictionary));

                    list.Add(formEvaluation);
                }
                var calculation = AHP.Calculation(dictionarymaster);
                var obj         = new List <Object>();
                foreach (var f in calculation)
                {
                    var firstOrDefault = list.FirstOrDefault(x => x.ControlId == f.Key);
                    if (firstOrDefault == null)
                    {
                        continue;
                    }
                    firstOrDefault.Weight = Math.Round(f.Value, 6);
                    obj.Add(new { controlId = firstOrDefault.ControlId, value = firstOrDefault.Weight });
                }

                if (FormGeneratorComponent.Instance.FormEvaluationFacade.ModifyEvaluation(list, collection["LanguageId"]))
                {
                    ShowMessage("اطلاعات با موفقیت ثبت شد", "موفق", messageIcon: MessageIcon.Succeed);

                    return(Json(obj, JsonRequestBehavior.AllowGet));
                }
                ShowMessage("خطایی در ذخیره اطلاعات رخ داده است", "خطا", messageIcon: MessageIcon.Error);
                return(Json(obj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                ShowMessage("خطایی در ذخیره اطلاعات رخ داده است" + exception.Message, "خطا", messageIcon: MessageIcon.Error);
                return(Content("false"));
            }
        }