WebBrowser Not Firing LoadComplete, but Navigating Firing - c#

I have userControl(wpf)
public WebBrowserControl()
{
InitializeComponent();
_Browser = new WebBrowser();
_pipeClient = new NamedPipeClient<WebMessage>("TestPipe");
_pipeClient.ServerMessage += PipeClientOnServerMessage;
_pipeClient.Error += PipeClientOnError;
_pipeClient.Start();
InternetExplorerBrowserEmulation.SetBrowserEmulationMode();
SuppressScriptErrors(_Browser, false);
SetWebBrowserFeatures();
GridBrrw.Children.Add(_Browser);
_Browser.ObjectForScripting = new ObjectForScripting(_pipeClient);
_Browser.LoadCompleted += new LoadCompletedEventHandler(_Browser_OnLoadCompleted);
_Browser.Navigating += _Browser_OnNavigating;
var th = new Thread(ExecuteInForeground);
th.Start();
}
private void ExecuteInForeground()
{
int i = 0;
while (i<=9)
{
Thread.Sleep(1000);
_pipeClient.PushMessage(new WebMessage() {Actions = "allo"});
i++;
}
}
private void _Browser_OnNavigating(object sender, NavigatingCancelEventArgs e)
{
if (IsClick)
{
var mes = new WebMessage { Actions = "OpenUrl" };
mes.Url = e.Uri.AbsoluteUri;
_pipeClient.PushMessage(mes);
e.Cancel = false;
}
return;
e.Cancel = false;
}
private void _Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
{
try
{
var br = sender as WebBrowser;
if (br?.Source != null && br.Source.AbsoluteUri != e.Uri.AbsoluteUri)
{
MessageBox.Show($"Source = {br.Source.AbsoluteUri},\r\n AbsoluteUri = {e.Uri.AbsoluteUri}");
return;
}
Document = (HTMLDocument)br.Document;
if (!string.IsNullOrEmpty(FindElement))
{
var node = HtmlNode.CreateNode(FindElement);
while (GetElement(node) == null)
{
System.Windows.Forms.Application.DoEvents();
}
}
if (WaitAjax)
{
ConnectToAjax();
return;
}
if (Sleep > 0)
{
var time = TimeSpan.FromSeconds(Sleep);
Thread.Sleep(time);
}
var mes = new WebMessage { Actions = "Load" };
mes.Title = Document.title;
mes.Url = br.Source.AbsoluteUri;
mes.Domain = br.Source.Host.Replace("http", "").Replace("http://", "").Replace("https://", "").Replace("https", "");
mes.Fovicon = $"http://www.google.com/s2/favicons?domain={mes.Domain}";
if (Document != null)
{
var htmls = Document.getElementsByTagName("html");
if (htmls != null && htmls.length > 0)
{
var html = htmls.item(0) as IHTMLElement;
mes.Html = html.outerHTML;
}
}
_pipeClient.PushMessage(mes);
}
catch (Exception ex)
{
throw ex;
}
}
Event Navigating firing, ExecuteInForeground sends messages, but LoadCompleted event is not firing. Could this be due to the settings window - Property = "ResizeMode" Value = "NoResize". What am I doing wrong?

Related

Release used memory after closing a form

I have ribbon form that contain DevExpress Tabbed View.
When I start the program in the task manager, I am getting 118.6 MB of used memory
Now when I open new form "FrmWeldingProduction" on Tabbed View
I get these results (Used Memory) when I open and close form "FrmWeldingProduction"
First open 274.4 MB First close 272.1 MB
Second open 403.9 MB Second close 401.6 MB
Third open 564.9 MB Third close 562.2 MB
This is the code behind the form
public partial class FrmWeldingProduction : XtraForm, IDisposable
{
readonly CLS_Welding welding = new();
readonly CLS_User us = new();
private RepOptionsFirstLastTime firstLastTime = new();
private readonly CultureInfo cultureInfo = CultureInfo.CurrentCulture;
private readonly string WeldingProduction = Application.StartupPath + "\\WeldingProduction.xml";
private readonly string LayoutWeldingProduction = "LayoutWeldingProduction";
private readonly int IDScreen = 19;
public FrmWeldingProduction() { InitializeComponent(); }
private async Task Permission()
{
using(DataTable Dt = await us.ApplayPermission(Program.UserID, IDScreen).ConfigureAwait(true))
{
if(Dt.Rows[0][1].ToString() == "False" || string.IsNullOrEmpty(Dt.Rows[0][1].ToString()))
{
repItemCreationDate.ReadOnly = true;
}
if(Dt.Rows[0][2].ToString() == "False" || string.IsNullOrEmpty(Dt.Rows[0][2].ToString()))
{
btnDelete.Enabled = false;
btnDeleteNoir.Enabled = false;
}
}
}
private void FrmWeldingProduction_FormClosed(object sender, FormClosedEventArgs e)
{
workspaceManager1.CaptureWorkspace(LayoutWeldingProduction, true);
workspaceManager1.SaveWorkspace(LayoutWeldingProduction, WeldingProduction, true);
DisposeFrm();
}
public void DisposeFrm()
{
us.Dispose();
firstLastTime.Dispose();
this.Load -= FrmWeldingProduction_Load;
gridView1.FocusedRowChanged -= gridView1_FocusedRowChanged;
repItemCreationDate.DrawItem -= RepItemCreationDate_DrawItem;
btnRefresh.Click -= btnRefresh_Click;
this.KeyDown -= FrmWeldingProduction_KeyDown;
btnProductionProject.ItemClick -= btnProductionProject_ItemClick;
gridView1.CellValueChanged -= GridView1_CellValueChanged;
Dispose(true);
GC.SuppressFinalize(this);
}
private async void gridView1_FocusedRowChanged(
object sender,
DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
if(e.FocusedRowHandle > 0)
{
using(DataTable EmployeeWeldingByProduction = await welding.GetEmployeeWeldingByProduction(
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "FK_ShiftTime"), cultureInfo),
Convert.ToDateTime(
gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Date de fabrication"),
cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo),
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "FK_idPartShip"), cultureInfo),
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OrderNumber"), cultureInfo))
.ConfigureAwait(true))
{
gridControl2.DataSource = EmployeeWeldingByProduction;
}
}
}
private async void btnRefresh_Click(object sender, EventArgs e)
{
using(DataTable WeldingProduction = await welding.GetWeldingProduction().ConfigureAwait(true))
{
gridControl1.DataSource = WeldingProduction;
}
using(DataTable WeldingPaintProduction = await welding.GetWeldingPaintProduction().ConfigureAwait(true))
{
gridControl3.DataSource = WeldingPaintProduction;
}
using(DataTable WeldingPaintFabRest = await welding.GetWeldingPaintFabRest().ConfigureAwait(true))
{
gridControl4.DataSource = WeldingPaintFabRest;
}
using(DataTable WeldingPaintStatusCHProject = await welding.GetWeldingPaintStatusCHProject()
.ConfigureAwait(true))
{
gridControl5.DataSource = WeldingPaintStatusCHProject;
}
using(DataTable ProductionCharpent = await welding.GetProductionCharpent().ConfigureAwait(true))
{
gridControl6.DataSource = ProductionCharpent;
}
using(DataTable StatusSupportsBS = await welding.GetStatusSupportsBS().ConfigureAwait(true))
{
gridControl7.DataSource = StatusSupportsBS;
}
if(gridView1.FocusedRowHandle > 0)
{
using(DataTable EmployeeWeldingByProduction = await welding.GetEmployeeWeldingByProduction(
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "FK_ShiftTime"), cultureInfo),
Convert.ToDateTime(
gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Date de fabrication"),
cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo),
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "FK_idPartShip"), cultureInfo),
Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OrderNumber"), cultureInfo))
.ConfigureAwait(true))
{
gridControl2.DataSource = EmployeeWeldingByProduction;
}
}
}
private async void FrmWeldingProduction_Load(object sender, EventArgs e)
{
KeyPreview = true;
btnRefresh_Click(sender, e);
foreach(GridColumn columnDateEdit in gridView1.Columns)
columnDateEdit.OptionsColumn.AllowEdit = false;
gridView1.Columns["Date de fabrication"].OptionsColumn.AllowEdit = true;
//pivotGridControl1.DataSource = await welding.GetProductionCharpent().ConfigureAwait(true);
workspaceManager1.TargetControl = this;
workspaceManager1.SaveTargetControlSettings = true;
if(workspaceManager1.LoadWorkspace(LayoutWeldingProduction, WeldingProduction, true))
workspaceManager1.ApplyWorkspace(LayoutWeldingProduction);
await Permission().ConfigureAwait(true);
}
private bool IsHoliday(DateTime dt)
{
//the specified date is a Holiday
if(dt.DayOfWeek == DayOfWeek.Friday)
return true;
//New Year's Day
if(dt.Day == 1 && dt.Month == 1)
return true;
//Independence Day
if(dt.Day == 5 && dt.Month == 7)
return true;
//VAlgerian War of Independence
if(dt.Day == 1 && dt.Month == 11)
return true;
//Employees Day
if(dt.Day == 1 && dt.Month == 5)
return true;
return false;
}
private void RepItemCreationDate_DrawItem(
object sender,
DevExpress.XtraEditors.Calendar.CustomDrawDayNumberCellEventArgs e)
{
if(e.View != DevExpress.XtraEditors.Controls.DateEditCalendarViewType.MonthInfo)
return;
//return if a given date is not a holiday
//in this case the default drawing will be performed (e.Handled is false)
if(!IsHoliday(e.Date))
return;
//highlight the selected and hot-tracked dates
bool isHotTracked = e.State == DevExpress.Utils.Drawing.ObjectState.Hot;
if(e.Selected || isHotTracked)
{
e.Graphics.FillRectangle(e.Style.GetBackBrush(e.Cache), e.Bounds);
}
//the brush for painting days
Brush brush = (e.Inactive ? Brushes.LightPink : Brushes.Red);
//specify formatting attributes for drawing text
using(StringFormat strFormat = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
})
{
//draw the day number
e.Graphics.DrawString(e.Date.Day.ToString(), e.Style.Font, brush, e.Bounds, strFormat);
}
//no default drawing is required
e.Handled = true;
}
private void FrmWeldingProduction_KeyDown(object sender, KeyEventArgs e)
{
try
{
if(e.KeyCode == Keys.F5)
{
btnRefresh_Click(sender, e);
}
} catch
{
}
}
private void btnProductionProject_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if(firstLastTime == null || firstLastTime.IsDisposed)
firstLastTime = new RepOptionsFirstLastTime();
firstLastTime.Show();
firstLastTime.OK.Click += ProductionProject_Click;
}
private async void ProductionProject_Click(object sender, EventArgs e)
{
using(RepWeldingProductionSumm report = new())
{
// Create a new parameter.
Parameter param1 = new();
Parameter param2 = new();
Parameter param3 = new();
// Specify required properties.
param1.Name = "FirstDatepara1";
param1.Type = typeof(DateTime);
param1.Visible = false;
param1.Value = Convert.ToDateTime(firstLastTime.FirstDate.EditValue, cultureInfo)
.ToString("dd/MM/yyyy", cultureInfo);
param2.Name = "lastDatepara2";
param2.Type = typeof(DateTime);
param2.Visible = false;
param2.Value = Convert.ToDateTime(firstLastTime.LastDate.EditValue, cultureInfo)
.ToString("dd/MM/yyyy", cultureInfo);
param3.Name = "shifttime";
param3.Type = typeof(string);
param3.Visible = false;
param3.Value = firstLastTime.cmbShiftTime.Text;
report.Parameters.Add(param1);
report.Parameters.Add(param2);
report.Parameters.Add(param3);
if(firstLastTime.cmbShiftTime.Text == Resources.allDay ||
string.IsNullOrEmpty(firstLastTime.cmbShiftTime.Text))
{
report.DataSource = await welding.RepWeldingProductionSumm(
Convert.ToDateTime(firstLastTime.FirstDate.EditValue, cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo),
Convert.ToDateTime(firstLastTime.LastDate.EditValue, cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo))
.ConfigureAwait(true);
firstLastTime.Close();
report.ShowRibbonPreviewDialog();
} else
{
report.DataSource = await welding.RepWeldingProductionShiftTimeSumm(
Convert.ToDateTime(firstLastTime.FirstDate.EditValue, cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo),
Convert.ToDateTime(firstLastTime.LastDate.EditValue, cultureInfo)
.ToString("MM/dd/yyyy", cultureInfo),
Convert.ToInt32(firstLastTime.cmbShiftTime.EditValue, cultureInfo))
.ConfigureAwait(true);
firstLastTime.Close();
report.ShowRibbonPreviewDialog();
}
}
}
private async void GridView1_CellValueChanged(
object sender,
DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
await Permission().ConfigureAwait(true);
if(e.Column.FieldName == "Date de fabrication")
{
await welding.UpdtaeCreationDateWeldingProduction(
Convert.ToInt32(gridView1.GetRowCellValue(e.RowHandle, "id"), cultureInfo),
Convert.ToDateTime(e.Value))
.ConfigureAwait(true);
XtraMessageBox.Show(
Resources.operationAccomplishedSuccessfully,
Resources.Confirmation,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}

Unable to check all check boxes in a GridView

I am using grid view check box to select all the values in the grid view when i click the check box, but the problem i am facing is it is selecting the only the first page value how ever i have coded to bring all the values in but in design it is not working out
this is the image
i want all the check box to checked in design when i press the all check button.
protected void gvBatch_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Pager)
{
DropDownList ddlcountry1 = (DropDownList)e.Row.FindControl("ddlcountry");
populateLocationValues(ddlcountry1);
{
ArrayList checkboxvalues = (ArrayList)Session["BP_PrdId"];
//string Bp_Id = "";
if (checkboxvalues != null && checkboxvalues.Count > 0)
{
string strBp_Id = ((HiddenField)e.Row.FindControl("hf_ProductLblId")).Value.ToString();
if (checkboxvalues.Contains(strBp_Id))
{
CheckBox myCheckBox = (CheckBox)e.Row.FindControl("chkPLPSltItem");
myCheckBox.Checked = true;
}
}
}
DataSet dsaccess = MenuRestriction();
DataRow dr = null;
string sView = "";
string sEdit = "";
string sInsert = "";
string sDeactive = "";
if (dsaccess.Tables.Count > 0)
{
if (dsaccess.Tables[0].Rows.Count > 0)
{
dr = dsaccess.Tables[0].Rows[0];
sView = dr["MnuRgts_View"].ToString();
sEdit = dr["MnuRgts_Edit"].ToString();
sInsert = dr["MnuRgts_Insert"].ToString();
sDeactive = dr["MnuRgts_DeActivate"].ToString();
if (sInsert == "Y" && sDeactive == "Y")
{
BtnDelete.Visible = true;
imgNew.Visible = true;
}
else
{
BtnDelete.Visible = false;
imgNew.Visible = false;
if (sInsert == "Y")
{
imgNew.Visible = true;
}
if (sDeactive == "Y")
{
BtnDelete.Visible = true;
}
}
}
}
}
}
catch (Exception ex)
{
log.Error("gvBatch_RowDataBound", ex);
}
}
protected void gvBatch_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
RememberOldValues();
gvBatch.PageIndex = e.NewPageIndex;
//RetrieveValues();
BindGrid();
LoadLocation();
//RePopulateValues();
}
private void RememberOldValues()
{
ArrayList checkboxvalues = new ArrayList();
string strBp_Id = "";
foreach (GridViewRow row in gvBatch.Rows)
{
//index = (int)gvBatch.DataKeys[row.RowIndex].Value;
strBp_Id = ((HiddenField)row.FindControl("hf_ProductLblId")).Value.ToString();
bool result = ((CheckBox)row.FindControl("chkPLPSltItem")).Checked;
// Check in the Session
if (Session["BP_PrdId"] != null)
checkboxvalues = (ArrayList)Session["BP_PrdId"];
if (result)
{
if (!checkboxvalues.Contains(strBp_Id))
checkboxvalues.Add(strBp_Id);
}
else
{
if (checkboxvalues.Contains(strBp_Id))
checkboxvalues.Remove(strBp_Id);
}
}
if (checkboxvalues != null && checkboxvalues.Count > 0)
Session["BP_PrdId"] = checkboxvalues;
}
protected void gvBatch_PreRender(object sender, EventArgs e)
{
try
{
if (gvBatch.TopPagerRow != null)
{
((Label)gvBatch.TopPagerRow.FindControl("lbCurrentPage")).Text = (gvBatch.PageIndex + 1).ToString();
((Label)gvBatch.TopPagerRow.FindControl("lbTotalPages")).Text = gvBatch.PageCount.ToString();
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnFirst")).Visible = gvBatch.PageIndex != 0;
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnPrev")).Visible = gvBatch.PageIndex != 0;
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnNext")).Visible = gvBatch.PageCount != (gvBatch.PageIndex + 1);
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnLast")).Visible = gvBatch.PageCount != (gvBatch.PageIndex + 1);
DropDownList ddlist = (DropDownList)gvBatch.TopPagerRow.FindControl("ddlPageItems");
ddlist.SelectedIndex = ddlist.Items.IndexOf(ddlist.Items.FindByValue(ViewState["DropDownPageItems"].ToString()));
gvBatch.AllowPaging = true;
gvBatch.TopPagerRow.Visible = true;
}
}
catch (Exception ex)
{
}
}
protected void gvBatch_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "EDIT")
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
string strAgentName = ((HiddenField)row.FindControl("hf_loginName")).Value.ToString();
if (strAgentName != "")
{
Response.Redirect("CustomerDetails.aspx?Name=" + strAgentName, false);
}
}
}
catch (Exception ex)
{
log.Error("gvAgentRowcommand_AgentSummary", ex);
}
}
You can keep a boolean field in your code and set its value to true whenever the select all is clicked. When loading new pages, you can check that field to automatically display all checked. The same can be done when exporting the grid also.
you can modify and use the following Method
private void selectAllChecksInDAtaGrid()
{
foreach (DataGridViewRow item in myDataGrid.Rows)
{
if (Convert.ToBoolean(item.Cells["Column_Name"].Value) == false)
{
item.Cells["Column_Name"].Value = true;
}
}
}
the 'Column_name' is the name of the checkbox column. if you haven'nt named it yet you can also use the index number .
in your case its 0
private void selectAllChecksInDAtaGrid()
{
foreach (DataGridViewRow item in myDataGrid.Rows)
{
if (Convert.ToBoolean(item.Cells[0].Value) == false)
{
item.Cells[0].Value = true;
}
}
}
You should update (ArrayList)Session["BP_PrdId"] to include all the "Id"s of datasource of gridview. then bind data again.

How to Return QuickBooks Report Results to WPF DataGrid Items?

I'm querying QuickBooks Desktop for transactions within a specific date range. I'm using boilerplate, or what seems to be, code to assign the report data to a Transaction class and adding the properties of the Transaction class to a WPF DataGrid for review by the end user.
My AllItemsDataGrid is instantiated inside the user control from the XAML below:
<DataGrid Name="AllItemsDataGrid" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True" Loaded="EntriesDataGrid_OnLoaded">
</DataGrid>
I create the report request, response, a report return and populate transactions into the DataGrid as follows:
private void EntriesDataGrid_OnLoaded(object sender, RoutedEventArgs e)
{
try
{
if (WalkReportRet != null)
{
var transactions = new List<Transaction>();
var transaction = new Transaction
{
TxnType = transaction.TxnType.ToString(),
TxnNumber = transaction.TxnNumber.ToString(),
TxnDate = transaction.TxnDate.Date(),
TxnName = transaction.TxnName.ToString(),
GLAccount = transaction.GLAccount.ToString(),
TxnAmount = transaction.TxnAmount.ToString(),
TxnCleared = transaction.TxnCleared.ToString(),
TxnSplit = transaction.TxnSplit.ToString()
};
}
return;
AllItemsDataGrid.ItemsSource = transactions;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
public void RunQuery(object sender, RoutedEventArgs e)
{
bool sessionBegun = false;
bool connectionOpen = false;
QBSessionManager sessionManager = null;
try
{
//Create Session Manager
sessionManager = new QBSessionManager();
//Create the request to obtain the Profit and Loss Summary Report
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
BuildGeneralDetailReportQueryRq(requestMsgSet);
//Connect to QB Desktop and begin a Session
sessionManager.OpenConnection(
#"C:\Users\Public\Public Documents\Intuit\QuickBooks\Company Files\MyCompany.QBW",
"MyCompany");
connectionOpen = true;
sessionManager.BeginSession("", ENOpenMode.omDontCare);
sessionBegun = true;
IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
sessionManager.EndSession();
sessionBegun = false;
sessionManager.CloseConnection();
connectionOpen = false;
WalkGeneralDetailReportQueryRs(responseMsgSet);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
finally
{
if (sessionBegun)
{
sessionManager.EndSession();
}
if (connectionOpen)
{
sessionManager.CloseConnection();
}
}
}
void BuildGeneralDetailReportQueryRq(IMsgSetRequest requestMsgSet)
{
IGeneralDetailReportQuery txQuery = requestMsgSet.AppendGeneralDetailReportQueryRq();
txQuery.GeneralDetailReportType.SetValue(ENGeneralDetailReportType.gdrtTxnListByDate);
txQuery.DisplayReport.SetValue(true);
txQuery.ORReportPeriod.ReportPeriod.FromReportDate.SetValue(StartDate.Value);
txQuery.ORReportPeriod.ReportPeriod.ToReportDate.SetValue(EndDate.Value);
}
void WalkGeneralDetailReportQueryRs(IMsgSetResponse responseMsgSet)
{
if (responseMsgSet == null) return;
IResponseList responseList = responseMsgSet.ResponseList;
if (responseList == null) return;
//if we sent only one request, there is only one response, we'll walk the list for this sample
for (int i = 0; i < responseList.Count; i++)
{
IResponse response = responseList.GetAt(i);
//check the status code of the response, 0=ok, >0 is warning
if (response.StatusCode >= 0)
{
//the request-specific response is in the details, make sure we have some
if (response.Detail != null)
{
//make sure the response is the type we're expecting
ENResponseType responseType = (ENResponseType) response.Type.GetValue();
if (responseType == ENResponseType.rtGeneralDetailReportQueryRs)
{
//upcast to more specific type here, this is safe because we checked with response.Type check above
IReportRet ReportRet = (IReportRet) response.Detail;
WalkReportRet(ReportRet);
}
}
}
}
}
void WalkReportRet(IReportRet ReportRet)
{
if (ReportRet == null) return;
if (ReportRet.ReportData != null)
{
if (ReportRet.ReportData.ORReportDataList != null)
{
for (int i35 = 0; i35 < ReportRet.ReportData.ORReportDataList.Count; i35++)
{
IORReportData ORReportData = ReportRet.ReportData.ORReportDataList.GetAt(i35);
if (ORReportData.DataRow != null)
{
if (ORReportData.DataRow != null)
{
if (ORReportData.DataRow.RowData != null)
{
}
if (ORReportData.DataRow.ColDataList != null)
{
for (int i36 = 0; i36 < ORReportData.DataRow.ColDataList.Count; i36++)
{
IColData ColData = ORReportData.DataRow.ColDataList.GetAt(i36);
}
}
}
}
if (ORReportData.TextRow != null)
{
if (ORReportData.TextRow != null)
{
}
}
if (ORReportData.SubtotalRow != null)
{
if (ORReportData.SubtotalRow != null)
{
if (ORReportData.SubtotalRow.RowData != null)
{
}
if (ORReportData.SubtotalRow.ColDataList != null)
{
for (int i37 = 0; i37 < ORReportData.SubtotalRow.ColDataList.Count; i37++)
{
IColData ColData = ORReportData.SubtotalRow.ColDataList.GetAt(i37);
}
}
}
}
if (ORReportData.TotalRow != null)
{
if (ORReportData.TotalRow != null)
{
if (ORReportData.TotalRow.RowData != null)
{
}
if (ORReportData.TotalRow.ColDataList != null)
{
for (int i38 = 0; i38 < ORReportData.TotalRow.ColDataList.Count; i38++)
{
IColData ColData = ORReportData.TotalRow.ColDataList.GetAt(i38);
}
}
}
}
}
}
}
}
How do I evaluate if the report results are null, and if they are not pass them into my AllItemsDataGrid.ItemSource? Am I better off creating a TransactionQuery instead?

c# webbrowser viewer control takes time to dispose

When closing Form containing a WebBrowser control with a Pdf document open in the webbrowser, the form takes some 10 seconds to close. I tracked the issue down to Dispose method of the webbrowser.
private void advBandedGridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
if (advBandedGridView1.GetFocusedDataRow() != null)
{
string wordno = advBandedGridView1.GetFocusedDataRow()["wordno"].ToString();
string itemcd = advBandedGridView1.GetFocusedDataRow()["itemcd"].ToString();
for (int i = 0; i < _caseCount; i++)
{
ButtonColoring(wordno, _seqkindCode[i]);
}
LoadPDF(itemcd);
gridControl2.DataSource = null;
gridControl2.RefreshDataSource();
}
}
Control Event
private void LoadPDF(string itemcd)
{
try
{
ReturnPacket rp;
rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = 'EYE'", false);
if (rp.DataTables.Count > 0 && rp.DataTables[0].Rows.Count == 0)
{
rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = '1'", false);
}
if (rp.DataTables[0].Rows.Count > 0)
{
string dockind = string.Empty;
dockind = rp.DataTables[0].Rows[0]["code"].ToString();
ParameterCollection paramCol = new ParameterCollection();
paramCol.Add("p_itemcd", itemcd);
paramCol.Add("p_dockind", dockind);
PdfFileInfo temp_fileInfo = biz.SelectInspectionStandards(paramCol);
if (temp_fileInfo != null)
{
if (_fileInfo != null && temp_fileInfo.FileNm == _fileInfo.FileNm)
{
WebBrowserPdf.Visible = true;
return;
}
_fileInfo = null;
_fileInfo = temp_fileInfo;
PDF_FILE_PATH = FilePath + _fileInfo.FileNm;
DirectoryInfo di = new DirectoryInfo(FilePath);
if (di.Exists == false)
{
di.Create();
}
if (!File.Exists(PDF_FILE_PATH))
File.WriteAllBytes(PDF_FILE_PATH, _fileInfo.FileData);
if (!PDF_FILES.Contains(PDF_FILE_PATH))
{
PDF_FILES.Add(PDF_FILE_PATH);
}
WebBrowserPdf.Navigate(PDF_FILE_PATH + "?#zoom=" + _zoomFactor + "%", false);
WebBrowserPdf.Visible = true;
simpleButtonOpenPOPUP.Enabled = true;
}
else
{
WebBrowserPdf.Visible = false;
simpleButtonOpenPOPUP.Enabled = false;
}
}
}
catch (Exception ex)
{
UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Alert, true);
}
}
it is Load Method
private void w_pcmu081_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
WebBrowserPdf.Dispose();
Process[] Pro = Process.GetProcessesByName("osk");
if (Pro.GetLength(0) > 0)
Pro[0].Kill();
}
catch(Exception ex)
{
UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Info, true, null, true);
}
}
Closing
The same situation happened to me.
Adobe has done something wrong in the latest version of Acrobat Reader DC (15.023.20056).
If you uncheck option Enable Protected Mode at startup in Edit -> Preferences -> Security (Enhanced), everything will be back to normal.
On my case it is not a solution.
More info here: https://forums.adobe.com/thread/2267688

Unable to move files into devexpress file treelist

I have created a file treelist in my WinForms application. The files and folders are displayed in a correct way. But when I try to drag a file from my pc (for ex. from my desktop) to the application the draggednode and the target node are null. Moving folders within my application works fine. How to change my application that I can drag files into the folders in the application?
Code:
class FileListHelper
{
string rootPath;
TreeList Tree;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn1;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn2;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn3;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn4;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn5;
TreeListMenu folderMenu;
public FileListHelper(TreeList tree)
{
Tree = tree;
InitColumns();
Tree.BeforeExpand += new DevExpress.XtraTreeList.BeforeExpandEventHandler(this.treeList1_BeforeExpand);
Tree.AfterExpand += new DevExpress.XtraTreeList.NodeEventHandler(this.treeList1_AfterExpand);
Tree.AfterCollapse += new DevExpress.XtraTreeList.NodeEventHandler(this.treeList1_AfterCollapse);
Tree.CalcNodeDragImageIndex += new DevExpress.XtraTreeList.CalcNodeDragImageIndexEventHandler(this.treeList1_CalcNodeDragImageIndex);
Tree.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeList1_DragDrop);
Tree.DoubleClick += new System.EventHandler(this.treeList1_DoubleClick);
Tree.PopupMenuShowing += new PopupMenuShowingEventHandler(Tree_PopupMenuShowing);
Tree.DragEnter += new DragEventHandler(this.treeList1_DragEnter); //added shows icons
tree.CellValueChanged += new CellValueChangedEventHandler(tree_CellValueChanged);
InitData();
folderMenu = new TreeListMenu(Tree);
folderMenu.Items.Add(new DXMenuItem("Create New Folder",MenuAddClick));
folderMenu.Items.Add(new DXMenuItem("Delete", MenuDeleteClick));
}
#region DragEnter
void treeList1_DragEnter(object sender,DragEventArgs e)
{
if (e.Data.GetDataPresent("FileGroupDescriptor"))
{
e.Effect = DragDropEffects.All;
}
else if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
//ensure FileGroupDescriptor is present before allowing drop
}
else if (e.Data.GetDataPresent("RenPrivateMessages"))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.Move;
}
}
#endregion DragEnter
#region Rename
void tree_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
if (e.Column.Caption =="Name")
{
if (e.Node["Type"] == "Folder")
{
DirectoryInfo di = e.Node["Info"] as DirectoryInfo;
di.MoveTo(di.Parent.FullName+"//"+e.Value);
}
else
{
FileInfo fi = e.Node["Info"] as FileInfo;
fi.MoveTo(fi.Directory.FullName + "//" + e.Value);
}
}
}
#endregion
#region Popup Menu
void Menu_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
void Tree_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
TreeListNode node = Tree.CalcHitInfo(e.Point).Node;
if (node != null)
{
e.Menu = folderMenu;
e.Menu.Tag = node;
//e.Menu.Items.Add(new DXMenuItem("Create New Folder"));
}
}
void MenuAddClick(object sender, EventArgs e)
{
DirectoryInfo di;
int ParentId = -1;
TreeListNode curentNode = folderMenu.Tag as TreeListNode;
TreeListNode folderParentNode;
if (curentNode["Type"] == "Folder")
folderParentNode = curentNode;
else
folderParentNode = curentNode.ParentNode;
if (folderParentNode == null)
{
di = new DirectoryInfo(rootPath);
}
else
{
ParentId = folderParentNode.Id;
di=folderParentNode["Info"] as DirectoryInfo;
}
DirectoryInfo newDirectory = Directory.CreateDirectory(di.FullName + "\\New Folder");
if (newDirectory != null)
{
Tree.FocusedNode = Tree.AppendNode(new object[] { newDirectory.FullName, newDirectory.Name, "Folder", null, newDirectory }, ParentId);
}
Tree.FocusedColumn = Tree.Columns["Name"];
Tree.ShowEditor();
}
void MenuDeleteClick(object sender, EventArgs e)
{
TreeListNode curentNode = folderMenu.Tag as TreeListNode;
(curentNode["Info"] as FileSystemInfo).Delete();
Tree.DeleteNode(curentNode);
}
#endregion
#region Initializing TreeList
void InitColumns()
{
this.treeListColumn1 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn2 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn3 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn4 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn5 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn1.Caption = "FullName";
this.treeListColumn1.FieldName = "FullName";
this.treeListColumn2.Caption = "Name";
this.treeListColumn2.FieldName = "Name";
this.treeListColumn2.VisibleIndex = 0;
this.treeListColumn2.Visible = true;
this.treeListColumn2.SortOrder = SortOrder.Ascending;
this.treeListColumn2.SortIndex = 1;
this.treeListColumn3.Caption = "Type";
this.treeListColumn3.FieldName = "Type";
this.treeListColumn3.VisibleIndex = 1;
this.treeListColumn3.Visible = true;
this.treeListColumn3.SortOrder = SortOrder.Descending;
this.treeListColumn3.SortIndex = 0;
this.treeListColumn3.OptionsColumn.AllowEdit = false;
this.treeListColumn4.AppearanceCell.Options.UseTextOptions = true;
this.treeListColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
this.treeListColumn4.Caption = "Size(Bytes)";
this.treeListColumn4.FieldName = "Size";
this.treeListColumn4.VisibleIndex = 2;
this.treeListColumn4.Visible = true;
this.treeListColumn4.OptionsColumn.AllowEdit = false;
this.treeListColumn5.Caption = "treeListColumn5";
this.treeListColumn5.FieldName = "Info";
this.treeListColumn5.Name = "treeListColumn5";
Tree.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
this.treeListColumn1,
this.treeListColumn2,
this.treeListColumn3,
this.treeListColumn4,
this.treeListColumn5});
}
private void InitData()
{
//int currentIncidentId=2;
//rootPath = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
rootPath = "C:\\Data\\98-ProgrammData\\Maintenance\\Dossier\\"/*+currentIncidentId*/;
InitFolders(rootPath, null);
}
private void InitFolders(string path, TreeListNode pNode)
{
Tree.BeginUnboundLoad();
TreeListNode node;
DirectoryInfo di;
try
{
string[] root = Directory.GetDirectories(path);
foreach (string s in root)
{
try
{
di = new DirectoryInfo(s);
node = Tree.AppendNode(new object[] { s, di.Name, "Folder", null, di }, pNode);
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);
if (node.HasChildren)
node.Tag = true;
}
catch { }
}
}
catch { }
InitFiles(path, pNode);
Tree.EndUnboundLoad();
}
private void InitFiles(string path, TreeListNode pNode)
{
TreeListNode node;
FileInfo fi;
try
{
string[] root = Directory.GetFiles(path);
foreach (string s in root)
{
fi = new FileInfo(s);
node = Tree.AppendNode(new object[] { s, fi.Name, "File", fi.Length, fi }, pNode);
node.StateImageIndex = 1;
node.HasChildren = false;
}
}
catch { }
}
private void treeList1_FilterNode(object sender, DevExpress.XtraTreeList.FilterNodeEventArgs e)
{
TreeList tree = sender as TreeList;
if (string.IsNullOrEmpty(tree.FindFilterText)) return;
e.Node.Visible = IsNodeVisible(e.Node);
e.Handled = true;
}
private bool IsNodeVisible(TreeListNode node)
{
if (node.ParentNode == null)
{
foreach (TreeListColumn column in node.TreeList.VisibleColumns)
{
object val = node[column.FieldName];
if (val != null && val.ToString().ToUpper().Equals(node.TreeList.FindFilterText.ToUpper()))
return true;
}
return false;
}
return IsNodeVisible(node.ParentNode);
}
private bool HasFiles(string path)
{
string[] root = Directory.GetFiles(path);
if (root.Length > 0) return true;
root = Directory.GetDirectories(path);
if (root.Length > 0) return true;
return false;
}
private void treeList1_BeforeExpand(object sender, DevExpress.XtraTreeList.BeforeExpandEventArgs e)
{
if (e.Node.Tag != null)
{
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
InitFolders(e.Node.GetDisplayText("FullName"), e.Node);
e.Node.Tag = null;
Cursor.Current = currentCursor;
}
}
private void treeList1_AfterExpand(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
if (e.Node.StateImageIndex != 1) e.Node.StateImageIndex = 2;
}
private void treeList1_AfterCollapse(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
if (e.Node.StateImageIndex != 1) e.Node.StateImageIndex = 0;
}
#endregion
#region Dragging
private void treeList1_CalcNodeDragImageIndex(object sender, DevExpress.XtraTreeList.CalcNodeDragImageIndexEventArgs e)
{
if (e.Node[treeListColumn3].ToString() == "Folder")
{
e.ImageIndex = 0;
}
if (e.Node[treeListColumn3].ToString() == "File")
{
if (e.Node.ParentNode == Tree.FocusedNode.ParentNode)
{
e.ImageIndex = -1;
return;
}
if (e.ImageIndex == 0)
if (e.Node.Id > Tree.FocusedNode.Id)
e.ImageIndex = 2;
else
e.ImageIndex = 1;
}
}
private void treeList1_DragDrop(object sender, DragEventArgs e)
{
TreeListNode draggedNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
TreeListNode tagretNode = Tree.ViewInfo.GetHitTest(Tree.PointToClient(new Point(e.X, e.Y))).Node;
if (tagretNode == null || draggedNode == null) return;
if (tagretNode[treeListColumn3].ToString() == "File")
{
if (tagretNode.ParentNode == draggedNode.ParentNode)
return;
MoveInFolder(draggedNode, tagretNode.ParentNode);
}
else
{
MoveInFolder(draggedNode, tagretNode);
}
e.Effect = DragDropEffects.None;
}
void MoveInFolder(TreeListNode sourceNode, TreeListNode destNode)
{
Tree.MoveNode(sourceNode, destNode);
if (sourceNode == null) return;
FileSystemInfo sourceInfo = sourceNode[treeListColumn5] as FileSystemInfo;
string sourcePath = sourceInfo.FullName;
string destPath;
if (destNode == null)
destPath = rootPath + sourceInfo.Name;
else
{
DirectoryInfo destInfo = destNode[treeListColumn5] as DirectoryInfo;
destPath = destInfo.FullName + "\\" + sourceInfo.Name;
}
if (sourceInfo is DirectoryInfo)
Directory.Move(sourcePath, destPath);
else
File.Move(sourcePath, destPath);
sourceNode[treeListColumn5] = new DirectoryInfo(destPath);
}
#endregion
#region Executing
private void treeList1_DoubleClick(object sender, EventArgs e)
{
if ((sender as TreeList).FocusedNode[treeListColumn3].ToString() == "File")
Process.Start(((sender as TreeList).FocusedNode[treeListColumn5] as FileSystemInfo).FullName, null);
}
#endregion
}
These two lines are null:
TreeListNode draggedNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
TreeListNode tagretNode = Tree.ViewInfo.GetHitTest(Tree.PointToClient(new Point(e.X, e.Y))).Node;
How to fix this?

Categories