public decimal ValidateVoidVoucher(string ticketNumber, int userNo, ref int?nResult) { decimal dAmount = 0; try { // is tis printed ticket if (VoucherHelper.IsTISPrintedTicketPrefix(ticketNumber)) { // if the tis printed ticket available in local db bool isTISTicketAvailable = VoucherHelper.IsTISPrintedTicket(ticketNumber); if (!isTISTicketAvailable) { // wait worst case 10 secs to get the response from TIS int count = 10; string message = "Waiting for receiving data from TIS..."; WPFExtensions.ShowAsyncDialog(null, message, null, 1, count, (o) => { IAsyncProgress2 o2 = o as IAsyncProgress2; // failure case - hit the tis communication interface and get the ticket try { o2.UpdateStatusProgress(5, message); VoucherHelper.SendTISRedeemTicketQuery(ticketNumber, userNo); o2.UpdateStatusProgress(10, message); } catch (Exception ex) { ExceptionManager.Publish(ex); } }); } } // Success/failure case - ok proceed with voiding foreach (var obj in this.ValidateVoidVoucher(ticketNumber, ref nResult)) { dAmount = Convert.ToDecimal(obj.iAmount) / 100; } } catch (Exception ex) { ExceptionManager.Publish(ex); } return(dAmount); }
protected virtual object[,] _ReadInternal(IAsyncProgress2 o, ExternalExcelRangeInfo rangeInfo) { int rows = rangeInfo.EndRow - rangeInfo.StartRow + 1; int cols = rangeInfo.EndColumn - rangeInfo.StartColumn + 1; int[] lowerBounds = new int[] { 1, 1 }; int[] lengths = new int[] { rows, cols }; object[,] values = (object[, ])Array.CreateInstance(typeof(object), lengths, lowerBounds); int totalRows = rows; int row = rangeInfo.StartRow; int count = 1; if (o != null) { o.InitializeProgress(1, totalRows); } for (int i = values.GetLowerBound(0); i <= values.GetUpperBound(0); i++) { if (o != null && o.ExecutorService.IsShutdown) { break; } int col = rangeInfo.StartColumn; for (int j = values.GetLowerBound(1); j <= values.GetUpperBound(1); j++) { values[i, j] = this.Cell(row, col).Value; if (o != null) { Thread.Sleep(1); } col++; } if (o != null) { int proPerc = (int)(((float)(i) / (float)totalRows) * 100.0); o.UpdateStatusProgress((count), "Reading value from excel . . . : " + (count) + " of " + totalRows.ToString() + " (" + proPerc + "%)"); } row++; count++; if (o != null) { Thread.Sleep(1); } } return(values); }
protected virtual bool _WriteInternal(IAsyncProgress2 o, object[,] values, ExternalExcelRangeInfo rangeInfo) { int totalRows = values.GetUpperBound(0) + 1; int row = rangeInfo.StartRow; int count = 1; if (o != null) { o.InitializeProgress(1, totalRows); } for (int i = values.GetLowerBound(0); i <= values.GetUpperBound(0); i++) { if (o != null && o.ExecutorService.IsShutdown) { break; } int col = rangeInfo.StartColumn; for (int j = values.GetLowerBound(1); j <= values.GetUpperBound(1); j++) { this.Cell(row, col).Value = values[i, j].ToString(); if (o != null) { Thread.Sleep(1); } col++; } if (o != null) { int proPerc = (int)(((float)(i) / (float)totalRows) * 100.0); o.UpdateStatusProgress((count), "Writing value to excel . . . : " + (count) + " of " + totalRows.ToString() + " (" + proPerc + "%)"); } row++; count++; if (o != null) { Thread.Sleep(1); } } return(true); }
public bool Write <C, R>(IAsyncProgress2 o, object source, bool writeHeaders, IEnumerable columns, GetExcelWriteColumnName <C> getColumnName, IEnumerable items, GetExcelWriteRowItemValue <C, R> getItemValue, Action <ExternalExcelRangeFormatInfo> modifyRange) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Write"); bool result = default(bool); if (source == null || items == null || columns == null) { return(false); } try { int rows = 0; int cols = 0; o.CrossThreadInvoke(new Action(() => { rows = (writeHeaders ? items.GetCollectionCount <R>() + 1 : items.GetCollectionCount <R>()); cols = columns.GetCollectionCount <C>(); })); int rowIndex = 1, rowIndex0 = 0; int colIndex = 1, colIndex0 = 0; object[,] values = Extensions.CreateArray(rows, cols, 1, 1); if (o != null) { o.InitializeProgress(1, rows); } ExternalExcelRangeFormatInfo rangeInfo = new ExternalExcelRangeFormatInfo(1, 1, rows, cols); if (modifyRange != null) { modifyRange(rangeInfo); } if (writeHeaders) { if (o != null) { o.UpdateStatusProgress(rowIndex, "Preparing row : " + rowIndex.ToString()); } colIndex0 = 0; foreach (C col in columns.OfType <C>()) { o.CrossThreadInvoke(new Action(() => { values[rowIndex, colIndex] = getColumnName(col, colIndex0); })); using (ExternalExcelRangeFormatInfo rangeInfo2 = new ExternalExcelRangeFormatInfo(rowIndex, colIndex, rowIndex, colIndex)) { rangeInfo2.BackColor = Color.Blue; rangeInfo2.ForeColor = Color.White; rangeInfo2.HorizontalAlignment = ExternalExcelCellHAlign.AlignLeft; rangeInfo2.VerticalAlignment = ExternalExcelCellVAlign.AlignCenter; this.FormatRange(rangeInfo2); } colIndex++; colIndex0++; } using (ExternalExcelRangeFormatInfo rangeInfo2 = new ExternalExcelRangeFormatInfo(rowIndex, 1, rowIndex, cols)) { rangeInfo2.AutoFilter = true; this.FormatRange(rangeInfo2); } rowIndex++; } IEnumerable items2 = null; o.CrossThreadInvoke(new Action(() => { items2 = items.OfType <R>(); })); IEnumerator enumerator = items2.GetEnumerator(); if (enumerator != null) { bool hasNext = true; while (hasNext) { o.CrossThreadInvoke(new Action(() => { hasNext = enumerator.MoveNext(); })); if (hasNext && enumerator.Current != null) { R dr = (R)enumerator.Current; if (rowIndex > rows) { break; } colIndex = 1; colIndex0 = 0; foreach (C col in columns) { o.CrossThreadInvoke(new Action(() => { values[rowIndex, colIndex] = getItemValue(dr, rowIndex0, col, colIndex0); })); colIndex++; colIndex0++; } if (o != null) { if (o.ExecutorService != null && o.ExecutorService.IsShutdown) { break; } o.UpdateStatusProgress(rowIndex, "Preparing row : " + rowIndex.ToString()); } rowIndex++; rowIndex0++; Thread.Sleep(1); } } } // excel writing result = this.Write(o, values, rangeInfo); // excel formatting o.UpdateStatus("Formatting..."); this.FormatRange(rangeInfo); } catch (Exception ex) { Log.Exception(PROC, ex); } return(result); }
private void DataBind(int pageIndex) { ModuleProc PROC = new ModuleProc("", "Method"); GridViewAfterDataBoundEventArgs args = new GridViewAfterDataBoundEventArgs(); lock (_lockGrid) { try { dgvRows.ClearSelection(); dgvRows.Rows.Clear(); _pageIndex = pageIndex; int start = (_pageIndex - 1) * this.RowsPerPage; int end = (_pageIndex * this.RowsPerPage) - 1; if (end > (_totalRows - 1)) { end = _totalRows - 1; } int records = (end - start + 1); int availRecords = Math.Min(records, this.RowsPerPage); args.Start = start + 1; args.End = start + availRecords; args.Total = _totalRows; lblPageInfo.Text = string.Format("{0:D} - {1:D} ({2:D})", args.Start, args.End, args.Total); object[] query = this.GridDataSource .AsQueryable() .OfType <Object>() .Skip(start) .Take(availRecords).ToArray(); if (this.ManualDataBinding && query != null && query.Length > 0) { if (_asyncActive != null) { try { _asyncActive.InitializeProgress(1, query.Length); } catch { } } int i = 1; foreach (var item in query) { if (_asyncActive != null) { try { if (_asyncActive.ExecutorService != null && _asyncActive.ExecutorService.IsShutdown) { break; } } catch { } } int rowIndex = dgvRows.Rows.Add(); DataGridViewRow row = dgvRows.Rows[rowIndex]; row.Tag = item; if (_asyncActive != null) { try { _asyncActive.UpdateStatusProgress(i, string.Empty); } catch { } } ManualRowBindEventArgs e = new ManualRowBindEventArgs() { Row = row, RowNumber = (start + rowIndex + 1), GridRowNumber = (rowIndex + 1), DataObject = item }; this.OnManualRowBind(e); e = null; i++; } } else { dgvRows.DataSource = query; } } catch (Exception ex) { Log.Exception(PROC, ex); } } try { if (dgvRows.Rows.Count > 0) { dgvRows.Rows[0].Selected = true; } this.dgvRows_SelectionChanged(dgvRows, EventArgs.Empty); this.OnAfterDataBound(args); } catch (Exception ex) { Log.Exception(PROC, ex); } finally { _asyncActive = null; } }