private void UploadData(VouchersClient selectedItem) { var fileExt = selectedItem.Fileextension; var cwUpdateFile = new CWUpdateFile(fileExt, Uniconta.ClientTools.Localization.lookup("Voucher")); cwUpdateFile.Closed += async delegate { if (cwUpdateFile.DialogResult == true) { if (cwUpdateFile.Contents != null) { byte[] buffer = cwUpdateFile.Contents; if (buffer != null && selectedItem.RowId != 0) { selectedItem._Data = buffer; VoucherCache.SetGlobalVoucherCache(selectedItem); busyIndicator.IsBusy = true; await api.Update(selectedItem); busyIndicator.IsBusy = false; } } else { UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("ViewerFailed"), Uniconta.ClientTools.Localization.lookup("Error"), MessageBoxButton.OK); return; } } }; cwUpdateFile.Show(); }
void SaveAttachment(GLTransClient selectedItem, VouchersClient doc) { CWForAllTrans cwconfirm = new CWForAllTrans(); cwconfirm.Closing += async delegate { if (cwconfirm.DialogResult == true) { if (selectedItem._DocumentRef != 0) { VoucherCache.RemoveGlobalVoucherCache(selectedItem.CompanyId, selectedItem._DocumentRef); } busyIndicator.IsBusy = true; var errorCodes = await postingApiInv.AddPhysicalVoucher(selectedItem, doc, cwconfirm.ForAllTransactions, cwconfirm.AppendDoc); busyIndicator.IsBusy = false; if (errorCodes == ErrorCodes.Succes) { BindGrid(); } else { UtilDisplay.ShowErrorCode(errorCodes); } } }; cwconfirm.Show(); }
private void InitMaster(UnicontaBaseEntity corasauMaster, bool setFocus) { if (corasauMaster == null) { return; } int RowId = VoucherCache.GetDocumentRowId(corasauMaster); if (RowId == 0) { NoVoucherLoadMessage(); return; } if (this.voucherClient != null && this.voucherClient.RowId == RowId) { return; // we have found the same as shown. Lets not redraw it. } voucherClient = VoucherCache.GetGlobalVoucherCache(corasauMaster.CompanyId, RowId); _LoadInitMaster(corasauMaster, voucherClient, RowId, setFocus); }
async void MoveToVoucherAtIndex(int index, bool setFocus = false) { if (index < 0 || envelopes == null || index > envelopes.Length - 1) { return; } btnPrev.IsEnabled = btnNext.IsEnabled = true; if (selectedIndex == 0) { btnPrev.IsEnabled = false; } if (selectedIndex == envelopes.Length - 1) { btnNext.IsEnabled = false; } this.documentViewer.Children.Clear(); currentBlk.Text = NumberConvert.ToString(index + 1); try { VouchersClient vClient = envelopes[selectedIndex]; if (vClient._Data != null) { VoucherCache.SetGlobalVoucherCache(vClient); } else { await UtilDisplay.GetData(vClient, api); } this.documentViewer.Children.Add(UtilDisplay.LoadControl(vClient, false, setFocus)); } catch (Exception ex) { brdMetaInfo.Visibility = System.Windows.Visibility.Visible; this.documentViewer.Children.Add((UtilDisplay.LoadDefaultControl(string.Format("{0}. \n{1} : {2}", Uniconta.ClientTools.Localization.lookup("InvalidDocSave"), Uniconta.ClientTools.Localization.lookup("ViewerFailed"), ex.Message)))); } SetMetaInfo(voucherClient); }
async void SaveIn2Steps() { // This here will first save the record without attachment. Then it will update with attachement. // The update will be done without await, so it will be done in the background. // This way it is fast to upload a document, since the user will not have to wait. var multiVouchers = this.multiVouchers; if (multiVouchers != null && browseControl.IsMultiSelect) { int l = multiVouchers.Length; if (l > 1) { var buffers = new byte[l][]; for (int i = 0; (i < l); i++) { var voucher = multiVouchers[i]; if (voucher._Data != null) { #if !SILVERLIGHT if (voucher._Fileextension == FileextensionsTypes.JPEG) { var imageBytes = FileBrowseControl.ImageResize(voucher._Data, ".jpg"); if (imageBytes != null) { voucher._Data = imageBytes; } } #endif buffers[i] = voucher._Data; voucher._Data = null; } } var err = await api.Insert(multiVouchers); if (err != ErrorCodes.Succes) { for (int i = 0; (i < l); i++) { multiVouchers[i]._Data = buffers[i]; } ClearBusy(); UtilDisplay.ShowErrorCode(err); } else { Utility.UpdateBuffers(api, buffers, multiVouchers); ClosePage(4); // full refresh and clearBusy inside CloseDockItem(); } return; } voucherClientRow = multiVouchers[0]; } byte[] buf = null; if (LoadedRow == null) { buf = voucherClientRow._Data; #if !SILVERLIGHT if (buf != null && voucherClientRow._Fileextension == FileextensionsTypes.JPEG) { buf = FileBrowseControl.ImageResize(buf, ".jpg"); if (buf != null) { voucherClientRow._Data = buf; } else { buf = voucherClientRow._Data; } } #endif if (buf != null && buf.Length > 200000) { voucherClientRow._Data = null; } else { buf = null; } } await saveForm(); ClearBusy(); if (buf != null) { if (voucherClientRow.RowId != 0) { Utility.UpdateBuffers(api, new[] { buf }, new[] { voucherClientRow }); } else { voucherClientRow._Data = buf; } } else { VoucherCache.SetGlobalVoucherCache(voucherClientRow); } }
async private void _LoadInitMaster(UnicontaBaseEntity corasauMaster, VouchersClient voucherClient, int RowId, bool setFocus) { try { if (voucherClient == null) { if (RowId != 0) { voucherClient = new VouchersClient(); voucherClient.SelectRowId(RowId); // we will now enter api.read } else { busyIndicator.IsBusy = true; var voucher = await api.Query <VouchersClient>(corasauMaster); voucherClient = voucher?.FirstOrDefault(); if (voucherClient?._Data != null) { VoucherCache.SetGlobalVoucherCache(voucherClient); } } } if (voucherClient._Data == null) { busyIndicator.IsBusy = true; var result = await UtilDisplay.GetData(voucherClient, api); if (result != 0) { busyIndicator.IsBusy = false; UtilDisplay.ShowErrorCode(result); return; } } this.documentViewer.Children.Clear(); brdMetaInfo.Visibility = Visibility.Visible; if (voucherClient._Envelope) { btnPrev.IsEnabled = false; busyIndicator.IsBusy = true; var dapi = new DocumentAPI(api); envelopes = (VouchersClient[])await dapi.GetEnvelopeContent(voucherClient, true); gridPrevNext.Visibility = Visibility.Visible; if (envelopes != null && envelopes.Length > 0) { totalBlk.Text = NumberConvert.ToString(envelopes.Length); MoveToVoucherAtIndex(selectedIndex, setFocus); /* * currentBlk.Text = NumberConvert.ToString(selectedIndex + 1); * var doc = envelopes[selectedIndex]; * this.documentViewer.Children.Add(UtilDisplay.LoadControl(doc.Buffer, doc._Fileextension, false, setFocus)); */ } else { totalBlk.Text = "0"; currentBlk.Text = "0"; } busyIndicator.IsBusy = false; } else { busyIndicator.IsBusy = false; this.documentViewer.Children.Add(UtilDisplay.LoadControl(voucherClient, false, setFocus)); } } catch (Exception ex) { brdMetaInfo.Visibility = Visibility.Visible; this.documentViewer.Children.Add((UtilDisplay.LoadDefaultControl(string.Format("{0}. {1} : {2}", Uniconta.ClientTools.Localization.lookup("InvalidDocSave"), Uniconta.ClientTools.Localization.lookup("ViewerFailed"), ex.Message)))); busyIndicator.IsBusy = false; } SetMetaInfo(voucherClient); }