internal FormStructure GenerateForm(IConnectionHandler connectionHandler, FormStructure formStructure, string culture = null) { if (formStructure == null || !formStructure.Enable) { return(null); } if (!string.IsNullOrEmpty(formStructure.RefId) && formStructure.GetFormControl != null) { var firstOrDefault = new FormDataBO().GetFormData(connectionHandler, formStructure.Id, formStructure.RefId, formStructure.ObjectName, culture); if (firstOrDefault != null) { if (firstOrDefault.StructureId == formStructure.Id) { var list = Extentions.GetControlData(firstOrDefault.Data); foreach (var controlvalueModel in list) { if (!formStructure.GetFormControl.ContainsKey(controlvalueModel.Key)) { formStructure.GetFormControl.Add(controlvalueModel.Key, controlvalueModel.Value); } } } } } if (string.IsNullOrEmpty(formStructure.RefId) && formStructure.FormState == FormState.DataEntryMode) { formStructure.FormState = FormState.FirstLoadMode; } return(formStructure); }
public FormData GetWithoutGridFormData(IConnectionHandler connectionHandler, FormStructure formStructure, string refId, string objname, string culture) { if (!string.IsNullOrEmpty(refId)) { var controls = formStructure.Controls.Where(x => x.GetType().Name != typeof(ControlFactory.Controls.Grid).Name && string.IsNullOrEmpty(((Control)x).GridId)).ToList(); var formDatas = new FormDataBO().Where(connectionHandler, x => x.RefId.ToLower() == refId.ToLower() && x.ObjectName.ToLower() == objname.ToLower() && x.StructureId == formStructure.Id); if (formDatas == null || !formDatas.Any()) { return(null); } new FormDataBO().GetLanuageContent(connectionHandler, culture, formDatas); FormData setformData = null; foreach (var formData in formDatas) { var list = Extentions.GetControlData(formData.Data); foreach (var control in controls) { if (!list.ContainsKey(((Control)control).Id)) { continue; } if (!formData.GetFormControl.ContainsKey(((Control)control).Id)) { formData.GetFormControl.Add(((Control)control).Id, list[((Control)control).Id]); } setformData = formData; } if (setformData != null) { return(setformData); } } } return(null); }
public IEnumerable <string> Search(FormStructure formStructure) { try { var outlist = new List <string>(); if (formStructure == null) { return(outlist); } var list = new FormDataBO().Where(this.ConnectionHandler, x => x.StructureId == formStructure.Id); var dictionary = formStructure.GetFormControl; foreach (var model in list) { var deSerialize = Extentions.GetControlData(model.Data); foreach (var key in dictionary.Keys) { if (!deSerialize.ContainsKey(key)) { continue; } var value = dictionary[key]; var sourcevalue = deSerialize[key]; if (string.IsNullOrEmpty(sourcevalue.ToString()) || string.IsNullOrEmpty(value.ToString())) { continue; } if (key.Contains("TextBox")) { if (sourcevalue.ToString().ToLower().Contains(value.ToString().ToLower())) { if (outlist.Any(x => x == model.RefId)) { continue; } outlist.Add(model.RefId); } } else if (sourcevalue.ToString() == value.ToString()) { if (outlist.Any(x => x == model.RefId)) { continue; } outlist.Add(model.RefId); } } } return(outlist); } 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); } }
public bool Update(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnectionHandler, FormStructure formPostModel, FormData frm) { var fileTransactionalFacade = FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnectionHandler); var controlData = Extentions.GetControlData(frm.Data); foreach (var source in formPostModel.GetFormControl.Where(x => x.Key.Contains(typeof(FileUpload).Name)).ToList()) { var keyValuePair = new KeyValuePair <string, object>(); if (controlData != null) { keyValuePair = controlData.FirstOrDefault(x => x.Key == source.Key); } if (source.Value != null && !Equals(source.Value, "")) { if (source.Value.GetType() == typeof(HttpPostedFileWrapper)) { if (keyValuePair.Value != null && !Equals(keyValuePair.Value, "")) { fileTransactionalFacade.Delete(((string)keyValuePair.Value).ToGuid()); } formPostModel.GetFormControl[source.Key] = fileTransactionalFacade.Insert((HttpPostedFileBase)source.Value).ToString(); } } else { if (keyValuePair.Value != null && !Equals(keyValuePair.Value, "")) { fileTransactionalFacade.Delete(((string)keyValuePair.Value).ToGuid()); } } } frm.CurrentUICultureName = formPostModel.CurrentUICultureName; frm.StructureId = formPostModel.Id; frm.Data = Extentions.GetFormData(formPostModel.GetFormControl); if (!this.Update(connectionHandler, frm)) { throw new Exception("خطایی در ویرایش اطلاعات فرم وجود دارد"); } return(true); }
public List <FormData> GetGridDataSource(IConnectionHandler connectionHandler, FormStructure formStructure, string objactname, string refId, string gridId, string culture) { var datas = new List <FormData>(); if (!string.IsNullOrEmpty(refId)) { var controls = formStructure.Controls.Where(x => x.GetType().Name != typeof(Grid).Name && ((Control)x).GridId == gridId).ToList(); var formDatas = new FormDataBO().Where(connectionHandler, x => x.RefId.ToLower() == refId.ToLower() && x.ObjectName.ToLower() == objactname.ToLower() && x.StructureId == formStructure.Id); if (formDatas == null || !formDatas.Any()) { return(null); } new FormDataBO().GetLanuageContent(connectionHandler, culture, formDatas); foreach (var formData in formDatas) { var list = Extentions.GetControlData(formData.Data); bool add = false; foreach (var control in controls) { if (!list.ContainsKey(((Control)control).Id)) { continue; } add = true; if (!formData.GetFormControl.ContainsKey(((Control)control).Id)) { formData.GetFormControl.Add(((Control)control).Id, list[((Control)control).Id]); } } if (add) { datas.Add(formData); } } } return(datas); }
internal FormEvaluation GeneratEvaluationHtml(IConnectionHandler connectionHandler, FormEvaluation formEvaluation, bool withoutahp, bool newgenerate) { List <KeyValuePair <string, object> > list = new List <KeyValuePair <string, object> >(); if (!string.IsNullOrEmpty(formEvaluation.DataFileId)) { var file = FileManagerComponent.Instance.FileFacade.Get(formEvaluation.DataFileId); if (file != null) { list = Extentions.GetControlData(StringUtils.Unzip(file.Content)).ToList(); } } if (!withoutahp) { foreach (var controlvalueModel in list) { if (!formEvaluation.GetFormControl.ContainsKey(controlvalueModel.Key)) { formEvaluation.GetFormControl.Add(controlvalueModel.Key, controlvalueModel.Value); } } if (newgenerate) { formEvaluation.Controls.Clear(); if (formEvaluation.MinScale != null && formEvaluation.MaxScale != null) { formEvaluation.OpinionCount = (int)(formEvaluation.OpinionCount * (formEvaluation.MaxScale - formEvaluation.MinScale)); } for (int i = 1; i <= formEvaluation.OpinionCount; i++) { var textBox = new TextBox { Id = "EV-" + formEvaluation.ControlId + "-" + i, Name = "EV-" + formEvaluation.ControlId + "-" + i, Order = i, }; textBox.Caption = string.Format("نظر {0}", textBox.Order); formEvaluation.Controls.Add(textBox); } } } else { if (!list.Any()) { var textBox = new TextBox { Id = "EV-" + formEvaluation.ControlId + "-" + 1, Name = "EV-" + formEvaluation.ControlId + "-" + 1, Order = 1, Caption = "نظر ", }; formEvaluation.Controls.Add(textBox); } else { foreach (var controlvalueModel in list) { if (!formEvaluation.GetFormControl.ContainsKey(controlvalueModel.Key)) { formEvaluation.GetFormControl.Add(controlvalueModel.Key, controlvalueModel.Value); } } } } return(formEvaluation); }
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); } }
internal DataTable ReportUserForms(IConnectionHandler connectionHandler, Guid formId, Guid homaId, string culture) { try { var table = new DataTable(); var userList = new UserBO().Where(connectionHandler, x => x.CongressId == homaId); var list = FormGeneratorComponent.Instance.FormDataFacade.Where(x => x.StructureId == formId && x.ObjectName == typeof(UserForms).Name); var formStructure = FormGeneratorComponent.Instance.FormStructureFacade; var form = formStructure.Get(formId); table.Columns.Add(Resources.Congress.Username); foreach (Control control in form.Controls) { if (control == null) { continue; } if (control.GetType() == typeof(Label) || control.GetType() == typeof(FileUploader)) { continue; } var columnName = control.GetCaption(); 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--; } } foreach (var user in userList) { var firstOrDefualt = list.FirstOrDefault(c => c.RefId == user.Id.ToString()); var dictionary = firstOrDefualt != null?Extentions.GetControlData(firstOrDefualt.Data) : null; var row = table.NewRow(); var stringWriter = new StringWriter(); var writer = new Html32TextWriter(stringWriter); row[Resources.Congress.Username] = user.Username; foreach (Control control in form.Controls) { if (control.GetType() == typeof(Label) || control.GetType() == typeof(FileUploader)) { continue; } control.Writer = writer; control.FormState = FormState.DetailsMode; control.Value = dictionary != null && dictionary.ContainsKey(control.Id) ? dictionary[control.Id] : string.Empty; 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); } }