private async Task GetFileData(EbMobileControl ctrl, MobileTable table, MobileTableRow row) { if (ctrl is EbMobileFileUpload fup) { table.Files.Add(ctrl.Name, fup.GetValue <List <FileWrapper> >()); } else if (ctrl is EbMobileDisplayPicture || ctrl is EbMobileAudioInput) { await SendAndFillFupPersisant(ctrl, row); } }
public Grid GetGridObject(string parent, FormMode FormMode, NetworkMode NetWorkType, EbDataRow Context) { Grid grid = new Grid() { ColumnSpacing = 0, RowSpacing = 0 }; List <EbMobileTableCell> tr0 = this.CellCollection.FindAll(tr => tr.RowIndex == 0); Dictionary <int, int> widthMap = tr0.Distinct().ToDictionary(item => item.ColIndex, item => item.Width); for (int r = 0; r < this.RowCount; r++) { grid.RowDefinitions.Add(new RowDefinition()); } for (int i = 0; i < this.ColumCount; i++) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(widthMap[i], GridUnitType.Star) }); } for (int i = 0; i < this.CellCollection.Count; i++) { EbMobileTableCell cell = this.CellCollection[i]; if (cell.ControlCollection.Count > 0) { EbMobileControl tbctrl = cell.ControlCollection[0]; tbctrl.Parent = parent; View controlView; if (Context == null) { controlView = tbctrl.Draw(FormMode, NetWorkType); } else { controlView = tbctrl.Draw(FormMode, NetWorkType, Context); } if (i % this.ColumCount > 0 && controlView is StackLayout layout) { layout.Padding = new Thickness(0, layout.Padding.Top, layout.Padding.Right, layout.Padding.Bottom); } grid.Children.Add(controlView, i % this.ColumCount, i / this.ColumCount); } } return(grid); }
private async Task SendAndFillFupPersisant(EbMobileControl ctrl, MobileTableRow row) { List <FileWrapper> Files = ctrl.GetValue <List <FileWrapper> >(); if (!Files.Any()) { return; } try { List <ApiFileData> resp = await FormService.Instance.SendFilesAsync(Files); if (resp.Any()) { MobileTableColumn column = ctrl.GetMobileTableColumn(); List <int> refIds = (from item in resp where item.FileRefId > 0 select item.FileRefId).ToList(); if (refIds.Count > 0) { string uploadedRefs = string.Join <int>(",", refIds); if (ctrl is EbMobileAudioInput audio && audio.MultiSelect) { if (audio.OldValue != null) { uploadedRefs = audio.OldValue.ToString() + CharConstants.COMMA + uploadedRefs; } } column.Value = uploadedRefs; row.Columns.Add(column); } } } catch (Exception ex) { EbLog.Error("error occured when sending persistant fup controls values"); EbLog.Error(ex.Message + ", STACKTRACE:" + ex.StackTrace); } }
private async Task <MobileFormData> GetFormData(int RowId) { MobileFormData formData = new MobileFormData(this.TableName); MobileTable table = formData.CreateTable(); MobileTableRow row = table.CreateRow(RowId); foreach (KeyValuePair <string, EbMobileControl> pair in this.ControlDictionary) { EbMobileControl ctrl = pair.Value; if (ctrl is IFileUploadControl) { await this.GetFileData(ctrl, table, row); } else if (ctrl is EbMobileDataGrid dataGrid) { formData.Tables.Add(dataGrid.GetValue <MobileTable>()); } else { MobileTableColumn Column = ctrl.GetMobileTableColumn(); if (Column != null) { row.Columns.Add(Column); } } } if (RowId <= 0) { row.AppendEbColValues(NetworkType == NetworkMode.Offline, true); } ; return(formData); }
public DbTypedValue GetDbType(string name, object value, EbDbTypes type) { DbTypedValue TV = new DbTypedValue(name, value, type); EbMobileControl ctrl = ControlDictionary.ContainsKey(name) ? ControlDictionary[name] : null; if (ctrl != null) { TV.Type = ctrl.EbDbType; TV.Value = ctrl.SQLiteToActual(value); } else { if (TV.Type == EbDbTypes.Date) { TV.Value = Convert.ToDateTime(value).ToString("yyyy-MM-dd"); } else if (TV.Type == EbDbTypes.DateTime) { TV.Value = Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss"); } } return(TV); }
public DbTypedValue GetDbType(string name, object value, EbDbTypes type) { DbTypedValue TV = new DbTypedValue(name, value, type); EbMobileControl ctrl = ChildControls.Find(item => item.Name == name); if (ctrl != null) { TV.Type = ctrl.EbDbType; TV.Value = ctrl.SQLiteToActual(value); } else { if (type == EbDbTypes.Date) { TV.Value = Convert.ToDateTime(value).ToString("yyyy-MM-dd"); } else if (type == EbDbTypes.DateTime) { TV.Value = Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss"); } } return(TV); }
public async Task <bool> Print(int rowId) { bool success = false; try { if (this.PrintDocs?.Count > 0) { PdfService PdfService = new PdfService(); List <Param> param = new List <Param>(); if (this.RenderAsFilterDialog) { foreach (KeyValuePair <string, EbMobileControl> pair in this.ControlDictionary) { EbMobileControl ctrl = pair.Value; if (ctrl is IFileUploadControl || ctrl is EbMobileDataGrid) { continue; } param.Add(new Param { Name = ctrl.Name, Type = ((int)ctrl.EbDbType).ToString(), Value = Convert.ToString(ctrl.GetValue()) }); } } else { param.Add(new Param { Name = "id", Type = ((int)EbDbTypes.Int32).ToString(), Value = rowId.ToString() }); } ReportRenderResponse r = null; if (NetworkType == NetworkMode.Online) { if (!Utils.IsNetworkReady(this.NetworkType)) { Utils.Alert_NoInternet(); return(false); } r = await PdfService.GetPdfOnline(this.PrintDocs[0].ObjRefId, JsonConvert.SerializeObject(param)); } else if (NetworkType == NetworkMode.Offline) { r = PdfService.GetPdfOffline(this.PrintDocs[0].ObjRefId, JsonConvert.SerializeObject(param)); } if (r?.ReportBytea != null) { INativeHelper helper = DependencyService.Get <INativeHelper>(); string root = App.Settings.AppDirectory; string path = helper.NativeRoot + $"/{root}/{AppConst.SHARED_MEDIA}/{App.Settings.Sid.ToUpper()}/PDF{(DateTime.UtcNow.ToString("yyyyMMddHHmmss"))}.pdf"; File.WriteAllBytes(path, r.ReportBytea); IAppHandler handler = DependencyService.Get <IAppHandler>(); string res = await handler.PrintPdfFile(path); if (res != "success") { await Launcher.OpenAsync(new OpenFileRequest { File = new ReadOnlyFile(path) }); } success = true; } } } catch (Exception ex) { Utils.Toast("Error: " + ex.Message); EbLog.Error("Error in [EbMobileForm.Print] " + ex.Message + " " + ex.StackTrace); } return(success); }