|
i am getting an error: unexpected end of file on the line that contains databaseKeyValue. Not sure why that is the case. Any help will be greatly appreciated.
private static bool addItemsToDrawing(
Visio.Page drawingPage)
{
bool itemsAdded = false;
Array shapeIDs;
addShapesToDrawing(drawingPage, out shapeIDs);
if (shapeIDs != null)
{
for (int index = shapeIDs.GetLowerBound(0);
index <= shapeIDs.GetUpperBound(0);
index++)
{
short shapeID = (short)(int)(shapeIDs.GetValue(index));
Visio.Shape newShape = drawingPage.Shapes.get_ItemFromID(shapeID);
int databaseKeyValue = newShape.get_Cells(_VisioPropCellPrefix + _IDColumn).get_ResultInt((short)Visio.VisUnitCodes.visNumber, 0);
_ItemShapeIndexMap.Add(databaseKeyValue, newShape.Index);
}
itemsAdded = true;
}
return itemsAdded;
}
|
|
|
|
|
I geuss you mean you get an Exception when running this code? Probably get_Cells() returns an empty result set.
|
|
|
|
|
int databaseKeyValue = newShape.get_Cells(_VisioPropCellPrefix + _IDColumn).get_ResultInt((short)Visio.VisUnitCodes.visNumber, 0);
That's too many statements on a single line. Call a single method per line, and step trough the code. It's probably not one of those methods that causes the exception, but a related event.
short shapeID = (short)(int)(shapeIDs.GetValue(index)); Why cast it to int, if you need a short?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i have designed a table as shown below. the are two literal controls as i am binding the datatable to the literal contol creating a tabular structre in the page load itself. The data is displayed correctly in default.aspx page. i want to export this aspx page to pdf . I using Itextsharp.dll.
On button click i have written code. The PDF is generated but it is getting distorted. Not getting generated as per the displayed aspx page.
Default.aspx and cs file is pasted below.
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div width="100%">
<asp:Panel ID="pnl" runat="server">
<table style="width:100%; border:1 solid black">
<tr>
<td align="center" style="width:100%" colspan="2" >
Customer Details
</td>
</tr>
<tr>
<td style="width:30%">
<asp:Literal ID="litvac" runat="server"></asp:Literal>
</td>
<td align="center" style="width:30%">
<asp:literal id="litsal" runat="server"></asp:literal>
</td>
</tr>
</table>
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
now the cs file is as below
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Qexp1 = "select * from emp";
string dconn = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
OracleConnection oraconn = new OracleConnection(dconn);
oraconn.Open();
OracleCommand oracmd = new OracleCommand("select * from emp", oraconn);
oracmd.CommandType = CommandType.Text;
DataTable dt = new DataTable();
OracleDataReader oda = oracmd.ExecuteReader();
dt.Load(oda);
litvac.Text = "<table cellspacing='0' cellpadding='0' width='50%' border='1'><tr><td colspan='8' class='td_bg' align='Center' style='border-color: #808080'><b>Value Of Account [Fig. are in lacs]</b>";
litvac.Text += "</td></tr><tr><td align='center' style='border:1 solid #808080'><b>EMP</b></td><td align='center' style='border:1 solid #808080'><b>Ename</b></td></tr>";
for (int k = 0; k <= dt.Rows.Count - 1; k++)
{
litvac.Text += "<tr><td align='center' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["empno"]) + "</td><td align='left' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["ename"]) + "</td></tr>";
}
litvac.Text += "</table>";
litsal.Text = "<table cellspacing='0' cellpadding='0' width='50%' border='1'><tr><td colspan='8' class='td_bg' align='Center' style='border-color: #808080'><b>Value Of Account [Fig. are in lacs]</b>";
litsal.Text += "</td></tr><tr><td align='center' style='border:1 solid #808080'><b>job</b></td><td align='center' style='border:1 solid #808080'><b>sal</b></td></tr>";
for (int k = 0; k <= dt.Rows.Count - 1; k++)
{
litsal.Text += "<tr><td align='center' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["job"]) + "</td><td align='left' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["sal"]) + "</td></tr>";
}
litsal.Text += "</table>";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}
|
|
|
|
|
I suspect iText is choking because of either invalid HTML, or all your nested tables are just too complicated for it. Post the final markup (view source) of your page so we can check it for known iText errors. One unclosed tag will mess it up bad.
|
|
|
|
|
I have a requirement where when a button is clicked the app connects to a remote pc and the user can browse to a folder on the c drive then copy a file to their pc (not on a LAN but a remote location)
When using Remote desktop connection the details are (for example)
Computer: abcd.dyndns.org:1234
Username: bob2\apple
Password: password
After doing a bit of research using WMI or Impersonation seems the best options. Here's where I'm at with the Impersonation approach..
[DllImport("advapi32.DLL", SetLastError=true)]
public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType,
int dwLogonProvider, ref IntPtr phToken);
private void button4_Click(object sender, EventArgs e)
{
WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
WindowsImpersonationContext wic = null;
try
{
IntPtr admin_token = new IntPtr();
if (LogonUser("bob2\apple", "abcd.dyndns.org:1234","password",9, 0, ref admin_token) != 0)
{
wic = new WindowsIdentity(admin_token).Impersonate();
File.Copy(@"", @"",
true);
MessageBox.Show("Copy Succeeded");
}
else
{
MessageBox.Show("Copy Failed");
}
}
catch(Exception se)
{
int ret = Marshal.GetLastWin32Error();
MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString());
MessageBox.Show(se.Message);
}
finally
{
if (wic != null)
wic.Undo();
}
}
thanks
Mat
|
|
|
|
|
Do you need file access to take place in the context of the actual user who is on the web site? Or, is this a situation where access to the web site means access to the files? If you need the Windows admins to control access to these files, then yes you need to use impersonation, but if you don't need that, it would be much easier to just stream the file back over HTTP. In that case file access would be done by the ASP_NET User, so you would only need to grant one user access to the folder. In the impersonation case, you have to add users to groups and whatnot to manage access to that folder.
Streaming a file back is super easy...
var file = File.Open(path);
Response.Clear();
Response.ContentType = "application\xml";
Response.WriteFile(file);
Response.Flush();
Response.Close();
Response.End();
|
|
|
|
|
matleeds wrote: I have a requirement where when a button is clicked the app connects to a remote pc and the user can browse to a folder on the c drive then copy a file to their pc (not on a LAN but a remote location)
Then hopefully there is also another requirement/assumption that states that the user must have remote access privileges on that computer sufficient to allow that.
|
|
|
|
|
please help me i want to create password for my win form and how can i manag it
|
|
|
|
|
The same way you create any form. Add a label and a text box that has the PasswordChar or UseSystemPasswordChar property. Then use ShowDialog to display the form at the beginning of the application.
Use the best guess
|
|
|
|
|
I think the answer you may be looking for is in the region of encryption and decryption.
Basically it boils down to never storing a clear text password - use something similar to the crypto class described here[^].
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
for examle:
I want to start IE with process.start method
and i want to get the text of address bar Is there any chance to do it
|
|
|
|
|
|
Thank u very much ,I don't know the key words for serching now I know
|
|
|
|
|
Member 10016142 wrote: I don't know the key words for serching That's part of the wonder of Microsoft.
Use the best guess
|
|
|
|
|
Hi all,
I'm creating an application that will allow me to draw lines with the mouse and then save them to a file in a graphical format. By dint of trying and trying I have come to the code.
The last problem that I can not solve is that I can only save the 'background' of the image but not the drawed shape.
The program consists of a PictureBox1 and a button1, drawing with the left mouse button, closes the shape with the right button and save the.
Thanks in advance to those who want to give me a tip.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Bitmap bm;
Graphics g;
GraphicsPath path = new GraphicsPath();
Pen redPen;
Pen blackPen1;
Pen blackPen2;
Pen orangePen;
public Form1()
{
InitializeComponent();
g = pictureBox1.CreateGraphics();
redPen = new Pen(Color.Red, 2);
blackPen1 = new Pen(Color.Black, 1);
blackPen2 = new Pen(Color.Black, 2);
orangePen = new Pen(Color.Orange, 1);
bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
Shown += Form1_Shown;
}
private void Form1_Shown(Object sender, EventArgs e)
{
}
private List<Point> polygonPoints = new List<Point>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
polygonPoints.Add(new Point(e.X, e.Y));
if (polygonPoints.Count > 1)
{
path.AddLine(polygonPoints[polygonPoints.Count - 2], polygonPoints[polygonPoints.Count - 1]);
g.DrawPath(redPen, path);
}
break;
case MouseButtons.Right:
if (polygonPoints.Count > 2)
{
path.CloseAllFigures();
g.DrawPath(redPen, path);
g.FillPath(new SolidBrush(Color.Orange), path);
}
break;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = Graphics.FromImage(bm);
for (int i = 0; i < pictureBox1.Width; i += 10) g.DrawLine(blackPen1, i, pictureBox1.Height, i, 0);
for (int i = 0; i < pictureBox1.Height; i += 10) g.DrawLine(blackPen1, 0, i, pictureBox1.Width, i);
g.DrawLine(blackPen2, 0, pictureBox1.Height - 90, pictureBox1.Width, pictureBox1.Height - 90);
e.Graphics.DrawImageUnscaled(bm, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
bm.Save("c:\\test.png", ImageFormat.Png);
}
}
}
|
|
|
|
|
Member 7921268 wrote: Thanks in advance to those who want to give me a tip.
Declared on top of the code;
Graphics g; A bit confusing, as you're also painting on "g" in the "_Paint" method. Are you drawing on the correct graphics-object? The reason I ask, is because there's two of them;
g = pictureBox1.CreateGraphics();
Graphics g = Graphics.FromImage(bm);
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You are right!, I'll investigate about it.
Thanks
|
|
|
|
|
If you want to save the drawing for later edits, it is usually better to save the points to a file, and not the image. Its more of a suggestion than anser but...
|
|
|
|
|
Thanks for your reply but I need to save the shape in image format for a successive 'shape matching' process.
Regards.
Lenny
|
|
|
|
|
Member 7921268 wrote: Thanks in advance to those who want to give me a tip.
Solved!, thanks all
Working release:
using System.Collections.Generic;
using System.Text;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool flgDraw = false;
Pen redPen;
Pen blackPen1;
Pen blackPen2;
Pen orangePen;
Bitmap drawing;
GraphicsPath path = new GraphicsPath();
private List<Point> polygonPoints = new List<Point>();
public Form1()
{
InitializeComponent();
redPen = new Pen(Color.Red, 2);
blackPen1 = new Pen(Color.Black, 1);
blackPen2 = new Pen(Color.Black, 2);
orangePen = new Pen(Color.Orange, 1);
panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
Shown += Form1_Shown;
drawing = new Bitmap(panel1.Width, panel1.Height, panel1.CreateGraphics());
Graphics.FromImage(drawing).Clear(Color.White);
}
private void Form1_Shown(Object sender, EventArgs e)
{
Grid();
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (flgDraw)
{
Graphics Gpanel = Graphics.FromImage(drawing);
panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
flgDraw = true;
Graphics Gpanel = Graphics.FromImage(drawing);
switch (e.Button)
{
case MouseButtons.Left:
polygonPoints.Add(new Point(e.X, e.Y));
if (polygonPoints.Count > 1)
{
path.AddLine(polygonPoints[polygonPoints.Count - 2], polygonPoints[polygonPoints.Count - 1]);
Gpanel.DrawPath(redPen, path);
}
break;
case MouseButtons.Right:
if (polygonPoints.Count > 2)
{
path.CloseAllFigures();
Gpanel.DrawPath(redPen, path);
Gpanel.FillPath(new SolidBrush(Color.Orange), path);
}
break;
}
panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
flgDraw = false;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(drawing, new Point(0, 0));
}
private void Grid()
{
Graphics Gpanel = Graphics.FromImage(drawing);
for (int i = 0; i < panel1.Width; i += 10)
Gpanel.DrawLine(blackPen1, i, panel1.Height, i, 0);
for (int i = 0; i < panel1.Height; i += 10)
Gpanel.DrawLine(blackPen1, 0, i, panel1.Width, i);
Gpanel.DrawLine(blackPen2, 0, panel1.Height - 90, panel1.Width, panel1.Height - 90);
panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
}
private void btnSave_Click(object sender, EventArgs e)
{
drawing.Save("c:\\test.png", ImageFormat.Png);
}
}
}
|
|
|
|
|
Here's a program which creates 100 million random numbers, then counts how many are divisible by seven using three different methods:
static void Main(string[] args)
{
Random r = new Random(Environment.TickCount);
int[] numbers = new int[100000000];
for (int index = 0; index < numbers.Length; index++)
{
numbers[index] = r.Next();
}
Stopwatch sw = Stopwatch.StartNew();
int count = 0;
foreach (int number in numbers) if (number % 7 == 0) count++;
Console.WriteLine("Simple Iteration {0} : {1}", count, sw.ElapsedMilliseconds);
sw = Stopwatch.StartNew();
var x = from g in numbers where g % 7 == 0 select g;
count = x.Count();
Console.WriteLine("LINQ Query {0} : {1}", count, sw.ElapsedMilliseconds);
sw = Stopwatch.StartNew();
int z = numbers.Count(g => g % 7 == 0);
Console.WriteLine("Count Query {0} : {1}", z, sw.ElapsedMilliseconds);
Console.ReadLine();
}
If you run it, you'll find that the Select query(2nd) takes almost exactly twice as long as basic iteration (1st), the count method (3rd) takes about three times as long.
This is a similar program to one I wrote when LINQ came out, and it rather put me off. Not only did the LINQ look more confusing, but it took twice as long to execute. It's also harder to debug, of course.
So, interested in views on this. Can anyone adjust the app so the performance becomes similar? Because, unless I'm missing something, half the performance is a serious issue in a real-time system and something to avoid everywhere else.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: If you run it, you'll find that the Select query(2nd) takes almost exactly twice as long as basic iteration (1st)
I'm not surprised. LINQ sacrifices speed for convenience. I'm using it a lot in my apps, and unless we're talking about a thight loop, it's not noticeable.
Rob Philpott wrote: half the performance is a serious issue in a real-time system One does not build real-time systems in a managed language. If speed is that much of an issue, you'd be better served with C++ or Delphi. Do an IntToStr in Delphi and in C#, and you'll have an equally large "problem".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: One does not build real-time systems in a managed language
I can assure you they do, I've worked on several such systems. And why not? Once the JIT is out the way calculations can be sometimes quicker than native code (I once had this in a C# vs C++ battle calculating prime numbers. The JIT can optimise for the installed processor, in my case an AMD chip and the managed code was quicker). The impact of things like array checking and garbage collection are usually negligible.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: The JIT can optimise for the installed processor It can, but it doesn't. Ok it does (it uses FISTTP and MOVQ), but not nearly enough.
Also, so can native code, although not as fully because it's not at runtime (it takes a lot of space and it will be frozen in time): CPU dispatch is a very common technique.
Rob Philpott wrote: the managed code was quicker) That just means the native code wasn't compiled right or the compiler sucked (MSVC sucks, except maybe the 2012 version) or both. There is no excuse for it otherwise.
|
|
|
|
|