Dear Friends,
I tried Application.DoEvents() and it worked fine. But it is very
slow. Is there a better way? What is "some state-object"? follwoing is
my complete code:
private Hashtable ImportOrganization(string sheetName,
ExcelUtility excelUtility)
{
Hashtable result = new Hashtable();
const int nameCol = 1;
const int orgIdCol = 2;
const int telCol = 3;
const int faxCol = 4;
const int addressCol = 5;
excelUtility.LoadWorksheet(sheetName);
int rowIndex = startingRow;
string rowIdentifier = excelUtility.ReadCell(rowIndex,
startingCol);
while (!String.IsNullOrEmpty(rowIdentifier))
{
Global.AddMessage(rtbCount, rowIndex);
Faraconesh.BusinessFramework.Common.Organization
organization = new Faraconesh.BusinessFramework.Common.Organization();
organization.Name = excelUtility.ReadCell(rowIndex,
startingCol + nameCol);
organization.OrgId = excelUtility.ReadCell(rowIndex,
startingCol + orgIdCol);
organization.Tel = excelUtility.ReadCell(rowIndex,
startingCol + telCol);
organization.Fax = excelUtility.ReadCell(rowIndex,
startingCol + faxCol);
organization.Address = excelUtility.ReadCell(rowIndex,
startingCol + addressCol);
if (result.ContainsKey(rowIdentifier))
throw new Exception("duplicate row number");
else
{
organization.RuntimeState =
Faraconesh.ApplicationFramework.Common.RuntimeState.Added;
Faraconesh.BusinessFramework.Common.CommonService.Instance.UpdateOrganization(organization);
result.Add(rowIdentifier, organization);
}
rowIdentifier = excelUtility.ReadCell(++rowIndex,
startingCol);
Application.DoEvents();
}
return result;
}
internal static void AddMessage(RichTextBox rtb, int intParam)
{
AddMessage(rtb, intParam.ToString());
}
internal static void AddMessage(RichTextBox rtb, string
stringParam)
{
const int maxLength = 4;
rtb.Text += stringParam + "\n";
if (rtb.Lines.Length > maxLength)
{
string[] oldLines = rtb.Lines;
string[] newLines = new string[maxLength];
for (int i = 0; i < maxLength; i++)
newLines = oldLines[i + 1];
rtb.Lines = newLines;
}
}
}
thanks,
afshar