VSTO 2010 for MS Project - c#

I am using VSTO 2010 for MS Project.Iam loading tasks from sql server.Which will be loading data row by row.It slows the performance as it is loading task one by one.has Everyone any idea about how to load data in one go.
Thanks in Advance.

don't load row by row. Load it table by table... Let your SQL-server do all the hard work-its designed to.

I am using something like below:
MSProject.Tasks mspTask = Globals.ThisAddIn.Application.ActiveProject.Tasks;
for (int i = 0; i < dsTaskList.Tables[0].Rows.Count; i++)
{
DataRow drTask = dsTaskList.Tables[0].Rows[i];
short outLevel = Convert.ToInt16(drTask["TASK_OUTLINE_LEVEL"]);
if (outLevel == 0)
{
continue;
}
mspTask.Add();
Utility.Save_UID.Add(drTask["TASK_UID"].ToString());
Utility.editText9Bycode = true;
mspTask[k].Text9 = drTask["TASK_UID"].ToString();
string strAss = "";
DataSet dsAss = WebServiceCall.GetAssignments(drTask["TASK_UID"].ToString());
}

Related

Iterating over all hyperlinks in an excel sheet using OpenXML doesn't return all hyperlinks

I am observing a very weird behavior here. I have an excel document (.xlsx) and My goal is to edit all the hyperlinks that meet a certain criteria.
The first time I iterate, I am able to edit most of the links. There are 4 links that still remain. Then I run the program again. Now 2 remain. Then I run the program yet again, and finally all links are replaced.
Here is the snippet:
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(FilePath, true))
{
WorkbookPart wbPart = doc.WorkbookPart;
// Replace hyperlink targets
foreach (var worksheet in wbPart.WorksheetParts)
{
var hyperLinkRelations = worksheet.HyperlinkRelationships;
for (int i = 0; i < hyperLinkRelations.Count(); i++)
{
var link = hyperLinkRelations.ElementAt(i);
try
{
if (link != null && link.Uri != null && Utils.IsToBeReplaced(link.Uri.AbsoluteUri))
{
string relationId = link.Id;
string destUrl = GetReplacementUrl(link.Uri.AbsoluteUri);
if (destUrl != null)
{
worksheet.DeleteReferenceRelationship(link);
worksheet.AddHyperlinkRelationship(new Uri(destUrl, UriKind.Absolute), true, relationId);
}
}
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
}
}
I have checked the utility methods "IsToBeReplaced()" and "GetReplacementUrl()" are functioning normally. I put a break point and discovered that the URLs that don't get replaced, simply do not show up in the "HyperlinkRelationships" collection.
Here is the excel file that I am working with: https://app.box.com/s/j3ulbxfafzxgcqiaep148a8yq4iy37ow
I would guess your indexing is throwing it off.
As a first attempt I would try working backwards.
ie something like:
var hcount = hyperLinkRelations.Count();
for (int i = hcount - 1; i >= 0; i--)
Otherwise, after you delete then add the relationship your i variable updates but the collection has been renumbered / shifted up by one so i will have skipped an element.

Load an excel file that contains charts and insert new column using Infragistics.Documents.Excel

I would like to insert a new column in an existing file that contains charts.
It doesn't work, visual studio keeps running forever. I noticed that if I delete the charts that are in the loaded file it works just fine. A new column with data is inserted. I just don't know If I can conclude that it's because of existing charts that new columns can't be inserted.
Here is what I did :
private static void Main()
{
string outputFile = "metrics.xlsx";
Workbook workbook = Workbook.Load(outputFile);
Workbook temporary = SetIndicatorsWorkbook();
var values = new List<int>();
for(int j=0; j<12; j++)
{
values.Add((int)temporary.Worksheets["Unit & Integration Tests"].Rows[j].Cells[0].Value);
}
var worksheet = workbook.Worksheets["Unit Testing"];
var k = 9;
var count = worksheet.Rows[14].Cells.Count(cell => cell.Value!=null);
worksheet.Columns.Insert(count+1);
foreach (var value in values)
{
worksheet.Rows[k].Cells[count+1].Value = value;
k++;
}
workbook.Save(outputFile);
}
Your code seems fine, I used a random excel file that had a chart on the sheet and the code executed fine without errors. I will be able to assist further if you provide the metrics.xlsx file.

How to set database name dynamically for a crystal report using C#?

I have a C# windows application in which there are many crystal reports.I call and show them using the following piece of code :
rptDDCollection rpt = new rptDDCollection();
rpt.SetDatabaseLogon(Connect.sDatabaseUserName, DLL.Connect.sDatabasePassword, "", Connect.sCurrentDatabase);
rpt.RecordSelectionFormula = "";
frmReports frm = new frmReports();
frm.crViewer1.DisplayGroupTree = false;
frm.crViewer1.ReportSource = rpt;
frm.crViewer1.SelectionFormula = rpt.RecordSelectionFormula;
frm.crViewer1.Show();
frm.Show();
Now, the issue is that I have 2 databases to work on.Things work fine with one database.I have to use the same report but very often I need to view data from the other database.The database engine is SQL server.While searching on the net and on stack overflow, I found suggestions to set the database name dynamically through code.What should be done to achieve what I want in this case?
I worked this around by setting database name for the tables in the report.I made one change in the actual code above.I created a method called ApplyLogonInfo and passed the report object to it.Inside the method I wrote the code for setting database name for the report tables dynamically.This is the modified code:
rptDDCollection rpt = new rptDDCollection();
rpt.SetDatabaseLogon(Connect.sDatabaseUserName, DLL.Connect.sDatabasePassword, "", Connect.sCurrentDatabase);
ApplyLogOnInfo(rpt);
rpt.RecordSelectionFormula = "";
frmReports frm = new frmReports();
frm.crViewer1.DisplayGroupTree = false;
frm.crViewer1.ReportSource = rpt;
frm.crViewer1.SelectionFormula = rpt.RecordSelectionFormula;
frm.crViewer1.Show();
frm.Show();
Below is the newly created method:
public static void ApplyLogOnInfo(ReportClass rpt)
{
TableLogOnInfo info = new TableLogOnInfo();
info.ConnectionInfo.DatabaseName = Connect.sCurrentDatabase;
for (int i = 0; i < rpt.Database.Tables.Count; i++)
{
rpt.Database.Tables[i].ApplyLogOnInfo(info);
}
}
sCurrentDatabase is the name of the database that has been currently selected for viewing.
This enabled me to set the database name dynamically, and now I can work with 2 (or in general multiple) databases and view the data from whichever database I wish to see.

How to Upload XML File to TomCat?

I have a TomCat server running a couple of webapps.
I would like to upload an XML file onto my TomCat server so I can access and download the file with a program I am developing in C#.
I've done a lot of searching and I have no solid leads, so how do I upload a file to a Tomcat server so it can be accessed?
For example, I want my program to be able to use this:
get file from(http://tomcat-ip:port/example/data.xml)
Thank you.
Figured out the solution: Place the file in webapps/root and you will be able to access the file from hostname:port/filename
If you are running your tomact server in XAMPP you can put your xml file in C:\xampp\htdocs
code:
URL oracle = new URL("http://localhost/data.xml);
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
while ((inputLine = in.readLine()) != null)
{
Sysetm.out.println(inputLine);
}
in.close();
If you have html table too you can make array:
Document doc = Jsoup.parse(inputLine);
Elements tables = doc.select("table");
for (Element table : tables) {
Elements trs = table.select("tr");
String[][] trtd = new String[trs.size()][];
for (int i = 0; i < trs.size(); i++) {
Elements tds = trs.get(i).select("td");
trtd[i] = new String[tds.size()];
for (int j = 0; j < tds.size(); j++) {
trtd[i][j] = tds.get(j).text();
}
}
// trtd now contains the desired array for this table
System.out.println(trtd[column][row]);
}

Linq2SQL not updating record on SQL Azure

I am experimenting with Azure and am running into an issue I cannot seem to find an answer to.
I am running a linq query to update Azure Database with changes to a record but for some reason the changes are not being noted or submitted to the database. The code I am running is as follows:
DataClasses1DataContext update = new DataClasses1DataContext();
Company extra = update.Companies.Single(p => p.ID == Convert.ToInt32(Request.QueryString["ID"]));
extra.companyName = txtCompanyName.Text;
extra.address1 = txtAddress1.Text;
extra.address2 = txtAddress2.Text;
extra.address3 = txtAddress3.Text;
extra.address4 = txtAddress4.Text;
extra.town = txtTown.Text;
extra.county = txtCounty.Text;
extra.postCode = txtPostCode.Text;
extra.billingEmail = txtBillingEmail.Text;
extra.facebook = txtFacebook.Text;
extra.fax = txtFaxNumber.Text;
extra.faxArea = txtFaxArea.Text;
extra.faxCountry = txtFaxCountry.Text;
extra.linkedIn = txtLinkedIn.Text;
extra.mainEmail = txtMainEmail.Text;
extra.mainPhone = txtMainLineNumber.Text;
extra.mainPhoneArea = txtMainLineArea.Text;
extra.mainPhoneCountry = txtMainLineCountry.Text;
if (drpMarketing.Text == "No")
{
extra.marketingYesNo = 0;
}
else
{
extra.marketingYesNo = 1;
}
extra.salesEmail = txtSalesEmail.Text;
extra.twitter = txtTwitter.Text;
extra.website = txtWebsite.Text;
update.SubmitChanges();
What I am noticing by setting break points is that if I load the page and then change some data then the new data is not being reflected when this code is called (it is in a btnUpdate_Click event)
So When the submitChanges() is used then the new data is not present to submit. Any help appreciated.... I think I have looked at this for so long it needs some fresh eyes lol.
Are you sure you are not repopulating your form OnPostback with the original data (re-selected from the database) so that the linq update actually works, but you are always submitting the most recent database data back to the database.
In other words are you sure you are only populating your form
if(!Page.IsPostback)
{
//populate the form
}
this will preserve user amends when a postback happens.
Have you tried to wrap the SubmitChanges in a try block? Maybe it is throwing an exception. Here is how it is documented to do updates which is very similar to what you are doing:
http://msdn.microsoft.com/en-us/library/bb399339.aspx
Also, does this work against a local SQL Server database or SQL Express database?

Categories