Exemplo n.º 1
0
        public Dictionary <object, string> GenerateFormControlWithHtml(IConnectionHandler connectionHandler, Guid formId, string culture)
        {
            var dictionary = new Dictionary <object, string>();
            var byGridId   = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);

            foreach (var control in byGridId.Controls.GetWithoutValidations())
            {
                WriteControlInDictiononary(ref dictionary, (Control)control, byGridId.Controls);
            }
            return(dictionary);
        }
Exemplo n.º 2
0
        public bool GenrateNewControl(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, Guid formId, string culture, object obj, int?order)
        {
            var form = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);

            this.GenerateControls(formId, form.Controls, obj, order);
            form.Controls.Add(obj);
            if (!this.ModifyStructure(connectionHandler, filemanagerconnectionHandler, form, culture))
            {
                throw new Exception("خطایی در ذخیره فرم وجود دارد");
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool UpdateControl(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, Guid formId, string culture, string Id, object obj, string validation, string items)
        {
            var form    = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);
            var control = form.Controls.FindControl(Id);

            if (control == null)
            {
                return(false);
            }
            form.Controls.Remove(control);
            this.SetValidator(validation, (Control)obj, form.Controls, formId);
            this.FillListItems(items, obj);
            form.Controls.Add(obj);
            if (!this.ModifyStructure(connectionHandler, filemanagerconnectionHandler, form, culture))
            {
                throw new Exception("خطایی در ذخیره فرم وجود دارد");
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool CustomeSwap(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, Guid formId, string culture, string Id, int getorder)
        {
            var form = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);

            var control = (Control)form.Controls.FindControl(Id);

            if (control == null)
            {
                return(false);
            }
            var enumerable = form.Controls.Where(x => x.GetType().BaseType != typeof(ValidatorControl)).Cast <Control>();
            var orDefault  = enumerable.FirstOrDefault(control1 => control1.Order >= getorder);

            if (orDefault != null)
            {
                var controlorder = orDefault.Order;
                foreach (Control variable in enumerable.Where(control1 => control1.Order >= getorder))
                {
                    variable.Order++;
                    var downvalidators = form.Controls.FindValidationControls(variable.Id);
                    foreach (var validator in downvalidators)
                    {
                        validator.Order++;
                    }
                }
                control.Order = controlorder;
                var list = form.Controls.FindValidationControls(control.Id);
                foreach (var validator in list)
                {
                    validator.Order = controlorder;
                }
            }
            if (!this.ModifyStructure(connectionHandler, filemanagerconnectionHandler, form, culture))
            {
                throw new Exception("خطایی در ذخیره فرم وجود دارد");
            }



            return(true);
        }
Exemplo n.º 5
0
        public bool DeleteControl(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, Guid formId, string culture, string Id)
        {
            var form = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);
            var item = (Control)form.Controls.FindControl(Id);

            if (item == null)
            {
                return(false);
            }
            form.Controls.Remove(item);
            new FormEvaluationBO().DeleteByControlId(connectionHandler, item.Id);
            var order = item.Order;

            var firstOrDefault = form.Controls.FindValidationControl(Id);

            if (firstOrDefault != null)
            {
                form.Controls.Remove(firstOrDefault);
            }
            var enumerable = form.Controls.GetWithoutValidations();

            foreach (Control variable in enumerable.Where(control => ((Control)control).Order > order))
            {
                variable.Order--;
                var downvalidators =
                    form.Controls.FindValidationControls(variable.Id);
                foreach (var validator in downvalidators)
                {
                    validator.Order--;
                }
            }
            if (!this.ModifyStructure(connectionHandler, filemanagerconnectionHandler, form, culture))
            {
                throw new Exception("خطایی در ذخیره فرم وجود دارد");
            }
            return(true);
        }
Exemplo n.º 6
0
        public bool SwapControl(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, Guid formId, string culture, string Id, string type)
        {
            var form = new FormStructureBO().GetByCulture(connectionHandler, formId, culture);

            var item = (Control)form.Controls.FindControl(Id);

            if (item == null)
            {
                return(false);
            }
            var enumerable = form.Controls.GetWithoutValidations();

            switch (type)
            {
            case "Up":
                var orDefaultdown =
                    enumerable.OrderByDescending(x => ((Control)x).Order)
                    .FirstOrDefault(control => ((Control)control).Order < item.Order);
                if (orDefaultdown == null)
                {
                    return(false);
                }
                var orderdown = item.Order;
                item.Order = ((Control)orDefaultdown).Order;
                ((Control)orDefaultdown).Order = orderdown;
                var upvalidators =
                    form.Controls.FindValidationControls(((Control)orDefaultdown).Id);
                var validatorControls =
                    form.Controls.FindValidationControls(item.Id);
                foreach (var validatorControl in upvalidators)
                {
                    validatorControl.Order = ((Control)orDefaultdown).Order;
                }
                foreach (var validatorControl in validatorControls)
                {
                    validatorControl.Order = item.Order;
                }
                break;

            case "Down":
                var orDefault =
                    enumerable.FirstOrDefault(control => ((Control)control).Order > item.Order);
                if (orDefault == null)
                {
                    return(false);
                }
                var order = item.Order;
                item.Order = ((Control)orDefault).Order;
                ((Control)orDefault).Order = order;
                var controls =
                    form.Controls.FindValidationControls(((Control)orDefault).Id);
                var downvalidators =
                    form.Controls.FindValidationControls(item.Id);
                foreach (var validator in downvalidators)
                {
                    validator.Order = item.Order;
                }
                foreach (var validator in controls)
                {
                    validator.Order = ((Control)orDefault).Order;
                }
                break;
            }
            if (!this.ModifyStructure(connectionHandler, filemanagerconnectionHandler, form, culture))
            {
                throw new Exception("خطایی در ذخیره فرم وجود دارد");
            }
            return(true);
        }
Exemplo n.º 7
0
        public DataTable ReportFormDataForExcel(IConnectionHandler connectionHandler, Guid formId, string culture)
        {
            try
            {
                var table = new DataTable();

                var generatorBo = new GeneratorBO();
                var byCulture   = new FormStructureBO().Get(connectionHandler, formId);
                byCulture.FormState = FormState.ReportMode;
                var formStructure = generatorBo.GenerateForm(connectionHandler, byCulture);
                if (formStructure == null)
                {
                    return(table);
                }
                byCulture = formStructure;
                foreach (Control control in byCulture.Controls)
                {
                    if (control == null)
                    {
                        continue;
                    }
                    if (control.GetType() == typeof(Label) || control.GetType() == typeof(FileUploader))
                    {
                        continue;
                    }
                    var columnName = control.GetCaption();
                    if (!table.Columns.Contains(columnName))
                    {
                        table.Columns.Add(columnName, control.DisplayValue != null ? control.DisplayValueType : typeof(string));
                    }
                }
                if (culture == "fa-IR")
                {
                    var ordinal = table.Columns.Count - 1;

                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        table.Columns[0].SetOrdinal(ordinal);
                        ordinal--;
                    }
                }
                var @where = Where(connectionHandler, x => x.StructureId == formId);
                foreach (var formData in @where)
                {
                    var row          = table.NewRow();
                    var stringWriter = new StringWriter();
                    var writer       = new Html32TextWriter(stringWriter);
                    var list         = Extentions.GetControlData(formData.Data);
                    foreach (Control control in formStructure.Controls)
                    {
                        if (control.GetType() == typeof(Label) || control.GetType() == typeof(FileUploader))
                        {
                            continue;
                        }
                        control.Writer    = writer;
                        control.FormState = FormState.DetailsMode;
                        if (list != null)
                        {
                            control.Value = list.ContainsKey(control.Id) ? list[control.Id] : null;
                        }
                        control.Generate();
                        var columnName = control.GetCaption();
                        row[columnName] = control.DisplayValue != null?control.DisplayValue.ToString() : string.Empty;
                    }
                    table.Rows.Add(row);
                }


                return(table);
            }
            catch (KnownException ex)
            {
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
        }