|
If you needed help with something, why didn't you ask a question about what it is you needed help with??
|
|
|
|
|
I need to create Dialer using C# with 5 Data Modems, it`s code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.IO.Ports;
using System.Threading;
namespace ConsoleApplication4
{
class Program
{
[STAThread]
static void Main()
{
int Numero;
Numero = 37924300;
string classname = "Win32_POTSModem";
string strMachine = ".";
System.Management.ObjectQuery oQuery;
System.Management.ManagementScope oScope;
System.Management.ManagementObjectSearcher oSearcher;
string strSQL;
try
{
strSQL = "Select * from " + classname;
oQuery = new ObjectQuery(strSQL);
oScope = new ManagementScope(@"\\" + strMachine + @"\root\cimv2");
oSearcher = new ManagementObjectSearcher(oScope, oQuery);
foreach (ManagementObject oService in oSearcher.Get())
{
if (!oService.GetPropertyValue("DeviceID").ToString().Contains("Modem"))
{
Console.WriteLine(oService.GetPropertyValue("AttachedTo"));
Console.WriteLine(oService.GetPropertyValue("Name"));
Console.WriteLine(oService.GetPropertyValue("DeviceID"));
SerialPort modem1 = new SerialPort(oService.GetPropertyValue("AttachedTo").ToString(), 9600, Parity.None, 8, StopBits.One);
Console.Write("Try call on modem " + oService.GetPropertyValue("Name").ToString());
while (modem1.IsOpen)
{
modem1.Close();
Thread.Sleep(1000);
}
modem1.Open();
modem1.NewLine = "\n";
Console.WriteLine(modem1.ToString());
Console.WriteLine(modem1.PortName);
Console.WriteLine(modem1.NewLine.ToString());
Console.WriteLine(modem1.IsOpen.ToString());
Console.WriteLine(modem1.ReadExisting());
modem1.Open();
modem1.ReadTimeout = 100000;
modem1.NewLine = "\r";
modem1.WriteLine("ATZ");
Console.Write("reset the modem");
modem1.ReadTo("OK\r\n");
Console.Write("wait for OK from modem");
modem1.WriteLine("ATHDT " + Numero + "@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1@1");
Console.Write("Discando para o numero " + Numero);
string response = modem1.ReadTo("\r").Trim();
Console.Write("Read status modem " + response);
int i = 0;
while (i < 900000)
{
Console.WriteLine(modem1.ReadExisting());
i++;
}
modem1.Close();
Console.WriteLine();
Console.Write("Disconnect call " + modem1.PortName);
Console.ReadKey();
}
}
Console.WriteLine("Write call number");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
}
}
|
|
|
|
|
5 seperate lines, huh?? this code is never going to work.
I could descrbie how to rip all this out and convert it to it's own class so you could run multiple instances of it on seperate threads, but it would take FAR more than a few forum posts to do so. That's just not going to happen.
There's no way you're going to get this code to work with any efficiency at all.
|
|
|
|
|
I have a problem with the validation using Enterprise Library 5.0 & the integration with Window Presentation Foundation (WPF). I can't validate the enter of a string. I try with WindowForm and I have the results but with WPF is so impossible.
If exist any example in validation with EntLib & WPF using VS 2010. Please send me right here or at the email jhcastellanos@uci.cu
|
|
|
|
|
Hi all,
i'm looking for a possibilty, to fill/paint the Background of different classes / objects with one Method. My code / thoughts so far:
private void LangSelectWindow_Paint(object sender, PaintEventArgs e)
{
PaintForm(this, e, "#E4A458", "#F0D697", 90f);
}
private void PaintForm(Form sender, PaintEventArgs e, String Color1, String Color2, float Angle)
{
Graphics g = e.Graphics;
Rectangle rBackground = new Rectangle(0, 0,
sender.Width, sender.Height);
System.Drawing.Drawing2D.LinearGradientBrush bBackground
= new System.Drawing.Drawing2D.LinearGradientBrush(rBackground,
System.Drawing.ColorTranslator.FromHtml(Color1),
System.Drawing.ColorTranslator.FromHtml(Color2),
Angle);
g.FillRectangle(bBackground, rBackground);
bBackground.Dispose();
}
works like a charm. But if i have a label or other object, do i have to create a new "PaintForm" for everything ? i.e.
private void LangSelectWindow_Paint(object sender, PaintEventArgs e)
{
PaintLabel(this, e, "#E4A458", "#F0D697", 90f);
}
private void PaintLabel(Label sender, PaintEventArgs e, String Color1, String Color2, float Angle)
{
Graphics g = e.Graphics;
Rectangle rBackground = new Rectangle(0, 0,
sender.Width, sender.Height);
System.Drawing.Drawing2D.LinearGradientBrush bBackground
= new System.Drawing.Drawing2D.LinearGradientBrush(rBackground,
System.Drawing.ColorTranslator.FromHtml(Color1),
System.Drawing.ColorTranslator.FromHtml(Color2),
Angle);
g.FillRectangle(bBackground, rBackground);
bBackground.Dispose();
}
don't want do create a single "paint-method" for every object / class. Only the BOLD marked things changes...
Tom
modified 15-Feb-12 15:08pm.
|
|
|
|
|
You could do something like:
private void PaintControl(Control sender, PaintEventArgs e, String Color1, String Color2, float Angle)
{
Graphics g = sender.CreateGraphics();
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Not sure I understand what it really is you are aiming for, however I would consider:
1. replacing PaintForm(Form sender, ... by PaintForm(Control sender, ...
2. wiring LangSelectWindow_Paint() to every Control's Paint event where relevant.
I also would create bBackground only once, and keep it alive in a class member.
|
|
|
|
|
Setting the background colour to Transparent on all but the base form should help you.
|
|
|
|
|
I am trying to use the SQLCommandBuilder to auto-generate the insert command, but I am getting is null. Please tell me what I am doing wrong. I have tried to use just a datatable and a dataset and neither has worked. I am starting with a table that has no records and then copying another table to it. I have tested the table copy and I know that it works. Here is my code:
private void CopyData(DataTable table, string tablename)
{
SqlDataAdapter da = new SqlDataAdapter("select * from " + tablename, cLocalConnect);
SqlCommandBuilder cBuilder = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
DataTable dt = new DataTable("table1");
ds.Tables.Add(dt);
da.Fill(ds, "table1");
dt = table.Copy();
da.Update(ds);
}
|
|
|
|
|
kruegs35 wrote: but I am getting is null.
Which means what exactly?
Are you getting null reference exception?
Are you getting a null entry in the database?
This last is maybe what you meant. Since you don't have any column data it would of course be null.
|
|
|
|
|
Could it be, that you forget the Call to cBuilder ? Maybe try this:
private void CopyData(DataTable table, string tablename)
{
SqlDataAdapter da = new SqlDataAdapter("select * from " + tablename, cLocalConnect);
SqlCommandBuilder cBuilder = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
DataTable dt = new DataTable("table1");
ds.Tables.Add(dt);
da.Fill(ds, "table1");
dt = table.Copy();
cBuilder.GetUpdateCommand();
da.Update(ds);
}
|
|
|
|
|
What I meant by the null, is the Insert, Update, & Delete commands are null for the data adapter. I called the GetUpdateCommand as Thomas suggested and I got an error:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
My table that I am trying to update is completely empty, which I guess is the problem.
|
|
|
|
|
kruegs35 wrote: that does not return any key column information
It's even telling you what the problem is. Include the primary key in your select statement.
|
|
|
|
|
I am using SqlBulkCopy to get what I need now.
|
|
|
|
|
how can add crystal report with web application with asp.net,C# with the help of procedure
|
|
|
|
|
There[^] you go. The 4th link looks particularly promising.
|
|
|
|
|
Agree with Pete. You should have searched Google before asking here.
Anyway check my past answer
Crystal report with Stored procedure[^]
thatrajaNobody remains a virgin, Life screws everyone
|
|
|
|
|
HI,
I have a problem. I put my code which i want to do below. I have a website which is in Share point. I need to active a email alert but not using Share point. I want to create a server scheduler and this application will get information from my website about the task lists. if some tasks deadline is near then my scheduler will send email to the specific user. This console application will help me to get list items from my share point website. I also want to fetch List guids from share point web application. In short i can say i need to fetch all list items and want to store them in the form of array. Later on i will use this information and will put a flag to check if the due date is close. If the due date is coming soon then i will send an automatic email to that specific user. If you see my code which i share in my post you will find some information about this. Please let me know if you need further information.
If there is some other way to active automatic email but without using share point workflow or alert. Because share point alert are always needed to be closed manually every time if we put some schedule on them. So please anyone who has a solution please let me know..
Thanks in Advance for your help
namespace Email
{
class Program
{
static string siteUrl = "";
static void Main(string[] args)
{
try
{
using (SPSite testSite = new SPSite(siteUrl))
{
Console.WriteLine("site url: " + testSite.Url);
using (SPWeb ourWeb = testSite.OpenWeb(new Guid("e94c0a67-7408-4413-a4d2-4f26275008ac")))
{
SPList ourList = ourWeb.Lists[new Guid("DEB874E1-8BE7-4AD5-A507-EE6C8DF27FDC")];
foreach (SPListItem ourItem in ourList.Items)
{
if (checkForRemind(ourItem))
Console.WriteLine("Remind!");
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("OOps: " + ex.Message);
}
}
static bool checkForRemind(SPListItem ourItem)
{
bool remindIsSet = false;
foreach (SPField ourField in ourItem.Fields)
{
Console.WriteLine("Field name: " + ourField.StaticName);
}
return remindIsSet;
}
}
}
|
|
|
|
|
Hi everyone. I'm trying to draw text of string on a panel control outside the Paint event but surprisingly, nothing is being drawn. I actually cannot figure out what is wrong with my code. I decided to create a small application to test that and again nothing is being drawn. The small code I wrote to test it is shown below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DrawText();
}
private void DrawText()
{
Graphics grfx = panel.CreateGraphics();
grfx.DrawString("Problem drawing text on Panel", panel.Font, Brushes.Black, 50, 50);
grfx.Dispose();
}
}
}
The variable 'panel' is an object of Panel which has been placed on the form with a Dock property 'Fill'. After compiling the text is not drawn. I don't know what I am doing wrong. Please help.
|
|
|
|
|
The most obvious thing here is that your form hasn't actually finished loading yet, and you are attempting to draw the text once and once only (before the form is actually rendered). What you need to do is draw the string in the Paint event handler.
As you are drawing this in a panel, you would hook into the paint event handler on the panel like this:
private void panel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("Problem drawing text on panel", panel.Font, Brushes.Black, 50, 50);
}
modified 15-Feb-12 7:21am.
|
|
|
|
|
Thanks Hanlon! Looks like I cannot avoid Paint handling for the Panel control for it to work. I will try that.
|
|
|
|
|
It's best to hang your painting code in the Paint event. Windows will tell you when to paint your form as that can be at any time, even you don't expect it in your code.
It's far better to do it that way instead of trying to figure out why it appears as though your painting code work most of the time, but not at others.
For example, in your original code, your painting code would draw the text on the panel, but when the user drags another window over the top of the panel and then removes it, your text will be gone.
Windows will tell you that your forms and controls need to be repainted via the Paint event. If you don't hang your drawing code from there, you'll end up with all kinds of painting issues you can't figure out.
|
|
|
|
|
In actual fact the text is getting drawn, but every time the panel is repainted it is going to clear it out (and this will happen as soon as the form is loaded). You say you want to do this outside the Paint event, but this is where this sort of thing should be handled. You should just call the panel's Invalidate method every time the text is updated. Something like this:-
string text;
public Form1()
{
InitializeComponent();
text = "No problem drawing in paint method!";
panel.Invalidate();
}
private void panel_Paint(object sender, PaintEventArgs e)
{
Graphics grfx = e.Graphics;
grfx.DrawString(text, panel.Font, Brushes.Black, 50, 50);
grfx.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
text = "Changed with the click of a button !";
panel.Invalidate();
}
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
As Pete says, this specific case is because you're drawing on the panel before the form finishes loading, and therefore before the panel hits the screen and repaints itself, so anything you are doing may work but you'll never see it. (Actually I'm a bit surprised CreateGraphics doesn't throw an exception at that stage.)
Why do you think you need to paint stuff outside a Paint event handler? There are a few specialist cases where that can be useful, but for 99% of all custom painting you want to do it in Paint, and I would expect that you should also be doing it there.
|
|
|
|
|
I was drawing the text outside the Paint event because the Panel is created in a different class while the function that draws the text is found in another class in the application I am writing (Not the example shown as a test). But I think I should do it in a Paint event. I want to install a Paint event for the Panel in the class within which the function that draws the text is implemented. Yet to do it but I hope that will work. Thanks.
|
|
|
|