|
|
i've found a solution , i have an ImageGrid with only Image Created at runtime :
foreach (Image ctrl in imageGrid.Children)
{
if (ctrl.GetType() == typeof(Image))
{
if (((Image)ctrl).Name == "Image1")
((Image)ctrl).Source = new BitmapImage(new Uri("pack://application:,,,/MyApplication/aleroot.png"));
}
}
with this code i change the image source for my Image Created at runtime .
Thanks anyway.
|
|
|
|
|
Firstly, I have this working in development, however when I publish to the production webserver, instead of generating the report, it asks me for login credentials again.
Here is a snapshot of my entire code behind file:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if ((ViewState["ParametersShown"] != null) &&
(ViewState["ParametersShown"].ToString() == "True"))
{
ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() +
myListing.GetReportFileName(Session["Report"].ToString()));
}
}
protected void btnBuild_Click(object sender, EventArgs e)
{
CrystalReportViewer1.ParameterFieldInfo.Clear();
DateTime startDate = DateTime.Parse(Session["FromDate"].ToString());
DateTime endDate = DateTime.Parse(Session["ToDate"].ToString());
ParameterFields paramFields = new ParameterFields();
ParameterField crStartDate = new ParameterField();
ParameterField crEndDate = new ParameterField();
crStartDate.Name = "@StartDate";
crEndDate.Name = "@EndDate";
ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue();
dcrStartDate.Value = startDate;
dcrEndDate.Value = endDate;
crStartDate.CurrentValues.Add(dcrStartDate);
crEndDate.CurrentValues.Add(dcrEndDate);
paramFields.Add(crStartDate);
paramFields.Add(crEndDate);
ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() +
myListing.GetReportFileName(Session["Report"].ToString()));
CrystalReportViewer1.ParameterFieldInfo = paramFields;
ViewState["ParametersShown"] = "True";
ViewState["ReportName"] = Session["Report"].ToString();
}
private void BindReport(string FilePath)
{
ReportDocument Report = new ReportDocument();
Report.Load(FilePath);
SetTableLocation(Report.Database.Tables);
CrystalReportViewer1.ReportSource = Report;
}
private void SetTableLocation(Tables tables)
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString();
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString();
connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString();
connectionInfo.Password = ConfigurationManager.AppSettings["ReportDBPassword"].ToString();
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
}
}
As detailed above, running from a local machine it works fine it is only when published to production server it asks for login details. Login details are stored in the web.config file and are correct.
Please help!
Thanks
|
|
|
|
|
Hello experts,
imagine an abstract base class CBase and two derived classes CChildOne and CChildTwo. The children represent some kinds of devices. They inherit all the stuff they have in common from CBase.
What I'm trying is to use CBase as often as possible to prevent lots of case differentiations.
I need the class at hand to tell me which icon to draw for an instance of that class. I would like CBase to have a property DeviceIcon, which is static. That way I wouldn't have to create an instance every time I need the icon. And I also would like to override that property in CChildOne and CChildTwo to always get the correct icon.
Visual Studio tells me that a property cannot use both abstract and static keywords. Anyone an idea how to get that going?
Or will I have to bite the bullet and forget about the static part?
Ciao,
luker
|
|
|
|
|
lukeer wrote: cannot use both abstract and static keywords
On the class or the field?
Either way, that wouldn't make sense. An abstract class may have a static field, but it would be shared by all its children. Are you trying to avoid that?
Do you want each child class to have its own icon to be shared among the instances of that child class?
You could probably use a static Dictionary<Type,Icon> to do that. And there may be other techniques as well.
|
|
|
|
|
PIEBALDconsult wrote: Do you want each child class to have its own icon to be shared among the instances of that child class?
That's exactly what I'm trying.
Ciao,
luker
|
|
|
|
|
something like this:
abstract class BaseClass
{
protected static readonly Icon BaseIcon = new Icon("...");
public abstract Icon DisplayIcon
{
get;
}
}
class ChildClassOne : BaseClass
{
static readonly Icon ChildIcon = new Icon("...");
public override Icon DisplayIcon
{
get { return ChildClassOne.ChildIcon; }
}
}
class ChildClassTwo : BaseClass
{
public override Icon DisplayIcon
{
get { return BaseClass.BaseIcon; }
}
}
|
|
|
|
|
Hi,
I would use a static member holding the icon for the class, and an instance member holding the actual icon for the instance, like so:
public class Base {
private static Icon baseIcon=...;
protected Icon myIcon=baseIcon;
...
}
public class Child : Base {
private static Icon childIcon=...;
public Child() {
myIcon=childIcon;
}
...
}
|
|
|
|
|
Here's a way to do it with generics -- I used strings to save time working it up.
(I think it's a bit kludgey.)
public class Base<T>
{
protected static string icon ;
public string
Icon
{
get
{
return ( icon ) ;
}
}
}
public class Child1 : Base<Child1>
{
static Child1
(
)
{
icon = "Child1" ;
return ;
}
}
public class Child2 : Base<Child2>
{
static Child2
(
)
{
icon = "Child2" ;
return ;
}
}
|
|
|
|
|
What's up with the syntax colouring?
|
|
|
|
|
the PRE tags says lang="TEXT" which disables all syntax coloring.
|
|
|
|
|
Syntax doesn't have colour.
|
|
|
|
|
Thanks a lot to everyone.
I finally added a static icon variable to each of the child classes.
The base class got an abstract Image GetDeviceIcon() method that each child class overrides returning its own child class icon. That way the icon is shared between all instances of a child class and can differ between sibling classes.
The drawback is, I have to create an instance of each class once to display the possible icons. But as I said, it's only once.
Thanks again,
luker
Ciao,
luker
|
|
|
|
|
Hi all,
I am communicating to a COM port where I send a string to the device and it returns a string. A button event triggers a string to be written and a text box is populated with the read value.
What I ultimately am trying to do is to have the text box automatically update with the returned value from the device.
I initially thought a timer event should be employed, but I'm not sure if this would be the most robust way to do this.
Thanks.
|
|
|
|
|
The same TextBox? What if the user is typing in it when the result comes along?
I would wrap the serial port in a class that provides an event for response and update the TextBox when the event fires.
(Being me, I'd write a class that I can use with my CommScript[^].)
If it's one TextBox, I might also disable the TextBox and Button when the Button is clicked, and re-enable them when the event fires.
|
|
|
|
|
I'll be using a label instead. Sorry for the confusion. Presently there is a text box, but I won't be allowing text input in the application. The device will require that a string be written to it as it doesn't transmit continuously.
|
|
|
|
|
Well, at least this gives me an excuse to write a SerialCommunicator...
|
|
|
|
|
I have pasted below the code that I am now using. As I am new to this, I thought a timer could be relatively easy to implement instead of the btnStart_Click event. Also, I know timing could really mess things up, but not sure how to deal with that either...
private void btnStart_Click(object sender, EventArgs e)
{
try
{
if (!sp1.IsOpen)
sp1.Open();
sp1.Write("*X01\r");
}
catch (Exception ex)
{
MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
}
}
private void Form1_Load(object sender, EventArgs e)
{
sp1 = new SerialPort("COM1", 9600, Parity.Odd, 7, StopBits.One);
sp1.Handshake = Handshake.None;
sp1.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
sp1.ReadTimeout = 500;
sp1.WriteTimeout = 500;
sp1.Open();
}
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(100);
string data = sp1.ReadExisting();
this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
}
private void si_DataReceived(string data)
{
char[] charsToTrim = {'X','0','1'};
textBox1.Text = data.TrimStart(charsToTrim);
}
|
|
|
|
|
If it's woking that way, then leave it alone.
But now I'm confused as to what you're writing and how.
|
|
|
|
|
The device I am using (a Newport meter) requires a string *X01\r in order to return the value that is on the display. When the button is clicked, it writes that string to the com port and then returns a series of characters, some of which are the actual value on the display. The problem is the button needs to be clicked. I want to have a start button and a stop button that begins and ends a thread used for automatically reading and writing to the com port, displaying the read value in a form label. Since I'm just learning C#, this is not an easy task. If anyone has any pointers, that would be greatly appreciated.
Thanks,Mike
|
|
|
|
|
I would likely use a System.Timers.Timer; the Elapsed event handler would handle the writing, the code you have above would deal with the incoming data.
|
|
|
|
|
I tried that without success. If I move the button click event to a timer tick event, nothing happens. I have even set the timer tick time to be >>Timer.Sleep (100) to make sure that there are no timing issues, but still nothing happens. However, if it did "work", seems that there would be a better way than a Timer.Sleep method....., but I'd take a successful timer function, if it would work. Thoughts?
|
|
|
|
|
I've never had trouble with timers.
You start the timer?
And set it to AutoReset?
Does it elapse at least once?
|
|
|
|
|
I checked the timer again.....Would help if it were enabled. Sometimes I wonder.
Seems that a stopwatch, as Rajesh suggest, may be the better way to handle this?
|
|
|
|
|
mprice214 wrote: enabled
Yes, but that's what Start does anyway.
I prefer the Timer Elapsed handler for sending and the event handler for receiving.
|
|
|
|