|
will there be any change with C#
because i am doing every thing on C#
|
|
|
|
|
It should be the same for a C# app.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi kiranreddy123
I understand that you want to learn and all that, but before you can start asking someone what is what , you have to make a research your self.You see, you cannot be a Good Programmer if you dont research. try to buy a Book and there are some E-books that you can get for free that i can share too. but please Google first before you post because if you google your question, you will find a lot of asnwers.
Hope this Helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hi,
I want to create a Windows Media Services Publising Point using C#, with only RTSP stream.
I have the file path, and publising point name input by user.
Also how can we chaek if the Publising point is exisiting or not, and also to check that is a certain publishing point is started or not.
Plzzzz Help.
Thanks.
Deepak Surana
|
|
|
|
|
Did you ever figure this out? I need to do the same thing, and it's been a pain.
Thanks....
|
|
|
|
|
Hi all,
Can i use override void OnPaintBackground in custom user control?My purpose to use this method in custom user control is because i will draw the base line (grid) as image in the drawing area at the initiate state, but after that, i don't want to repaint again the background(image) when i draw some line on it. Thus, i need to override the OnPaintBackground method and disable it to fulfill my purpose. I can done it in Component,but how about in custom user control?
Any tips are welcome.
regards
cocoonwls
|
|
|
|
|
Hi,
you can override OnPaintBackground, I haven't have any problem with that so far. If you want to draw over default background, be sure to call base.OnPaintBackground as a first thing in your override method. If you want to draw your background completely by yourself, don't call base.OnPaintBackground at all.
hope this helps
|
|
|
|
|
hi Michal Martinka,
Thanks for your hlep.i will try it out
|
|
|
|
|
Hi, i'm new in this forum.
I am currently developing a Pocket Application using C# & SQL CE. Now, everything was working fine until just now. When I do any type of operations in the database (insert, update & delete) running the application in the device everything goes right, no errors. But When I check the database, no changes has been made. It seems that everything is working but I do not know if I'm missing something. I didn't noticed this until i was testing my RDA functions, when i realized that the tables didn't have any data of the SQL Server, any idea of how to solve this?
this class creates connections to the SQL CE database.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
using System.Windows;
using System.IO;
using CAPocket.Clases;
namespace CAPocket.Clases
{
class Data
{
String cadenaCon;
public Data()
{
cadenaCon = @"Data Source =\Program Files\CAPocket\Sistema.sdf;SSCE:Database Password='pam653045';";
}
public SqlCeConnection GetConnection()
{
SqlCeConnection con = new SqlCeConnection(cadenaCon);
try
{
con.Open();
return con;
}
catch (SqlCeException ex)
{
return null;
}
}
public SqlCeDataAdapter getAdapter(String s_sql)
{
SqlCeDataAdapter adp;
try
{
adp = new SqlCeDataAdapter(s_sql, cadenaCon);
return adp;
}
catch (SqlCeException ex)
{ return null; }
}
}
}
This code block of a class allows the administrator to add, delete or get all the users registered in the application:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
using System.Windows;
using System.IO;
using System.Data;
using CAPocket.Clases;
namespace CAPocket
{
class GestionUsuarios
{
public GestionUsuarios()
{
}
Data cex;
SqlCeConnection cnn;
SqlCeCommand cmd;
public bool NuevoUsuario(String user, String pass, String tipo)
{
cex = new Data();
cnn = cex.GetConnection();
if (cnn != null)
{
String sql = "insert into Usuarios values ('" + user + "','" + pass + "', '" + tipo + "')";
cmd = new SqlCeCommand(sql, cnn);
try
{
cmd.ExecuteNonQuery();
return true;
}
catch (SqlCeException ex)
{ return false; }
finally
{ cnn.Close(); }
}
else
{ return false; }
}
public bool Existe(String user, String pass)
{
cex = new Data();
cnn = cex.GetConnection();
String sql = "select * from Usuarios where Usuario='" + user + "'";
if (cnn != null)
{
cmd = new SqlCeCommand(sql, cnn);
try
{
SqlCeDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
return true;
}
else
{
return false;
}
}
catch(SqlCeException ex)
{ return false; }
finally
{ cnn.Close(); }
}
else
{ return false; }
}
public DataSet getAllUsers()
{
DataSet ds = new DataSet();
cex = new Data();
SqlCeDataAdapter adp = cex.getAdapter("Select Usuario, TipoUsuario from Usuarios order by TipoUsuario");
adp.Fill(ds, "Usuarios");
return ds;
}
public bool EliminarUsuario(String user)
{
cex = new Data();
cnn = cex.GetConnection();
String sql = "delete from Usuarios where Usuario='" + user + "'";
if (cnn != null)
{
cmd = new SqlCeCommand(sql, cnn);
try
{
cmd.ExecuteNonQuery();
return true;
}
catch (SqlCeException ex)
{ return false; }
finally
{ cnn.Close(); }
}
else { return false; }
}
}
}
the next code is from the form where you add, delete and show all the users.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
using System.Windows;
using System.IO;
using CAPocket.Clases;
namespace CAPocket
{
public partial class frmUsuarios : Form
{
public frmUsuarios()
{
InitializeComponent();
}
public DataSet dset;
GestionUsuarios gu;
public void RefreshGrid()
{
gu = new GestionUsuarios();
dset = new DataSet();
dset.Clear();
dset = gu.getAllUsers();
dataGrid1.DataSource = dset.Tables["Usuarios"];
dataGrid1.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Usuarios";
DataGridColumnStyle cUsuario = new DataGridTextBoxColumn();
cUsuario.HeaderText = "Usuario";
cUsuario.MappingName = "Usuario";
cUsuario.Width = 75;
ts.GridColumnStyles.Add(cUsuario);
DataGridColumnStyle cTipoUsuario = new DataGridTextBoxColumn();
cTipoUsuario.HeaderText = "Tipo de Usuario";
cTipoUsuario.MappingName = "TipoUsuario";
cTipoUsuario.Width = 100;
ts.GridColumnStyles.Add(cTipoUsuario);
dataGrid1.TableStyles.Add(ts);
}
private void frmUsuarios_Load(object sender, EventArgs e)
{
RefreshGrid();
}
private void btAgregar_Click(object sender, EventArgs e)
{
GestionUsuarios gu = new GestionUsuarios();
bool resultado = gu.Existe(txtUsuario.Text, txtPassword.Text);
if (resultado == false)
{
if (radioButton1.Checked == true)
{ resultado = gu.NuevoUsuario(txtUsuario.Text, txtPassword.Text, "Usuario"); }
if (radioButton2.Checked == true)
{ resultado = gu.NuevoUsuario(txtUsuario.Text, txtPassword.Text,"Administrador"); }
if (resultado == true)
{
MessageBox.Show("Usuario agregado exitosamente", "Resultados");
RefreshGrid();
}
else
{ MessageBox.Show("Error al guardar","Errores"); }
}
else
{
MessageBox.Show("El usuario ya existe","Errores");
}
txtUsuario.Text = "";
txtPassword.Text = "";
}
private void datagrid1_Click(object sender, EventArgs e)
{
dataGrid1.Select(dataGrid1.CurrentRowIndex);
textBox1.Text = dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString();
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
dataGrid1.Select(dataGrid1.CurrentRowIndex);
textBox1.Text = dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString();
}
private void btEliminar_Click(object sender, EventArgs e)
{
gu = new GestionUsuarios();
bool resultado = gu.EliminarUsuario(textBox1.Text);
if (resultado == true)
{
MessageBox.Show("Usuario eliminado", "Resultados");
RefreshGrid();
}
else
{ MessageBox.Show("Error al eliminar", "Error"); }
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Hope anyone can help me!
|
|
|
|
|
Put break points and step into to the code.
three.leaf wrote: "select * from Usuarios where Usuario='" + user + "'";
three.leaf wrote: "insert into Usuarios values ('" + user + "','" + pass + "', '" + tipo + "')";
Ahh , SQL injection. Read this[^]
|
|
|
|
|
I put the break points, and step into the code but still, not working. While I run it in the emulator, it adds the data to the mobile database, but after i stop the debugging and restart the application, the data is lost.
Any other idea?
|
|
|
|
|
I created a client-server application. So far I created 3 Projects from visual studio C#.. First project is the Server project, second project is the Client Project, and the Third Project is the connector project. The connector project is responsible for linking the client and the server together. Here's the problem, the connector project produces a DLL file when compiled which will be imported into the client and into the server so that they can communicate with each other. So this time after importing the DLL file to the client project and server project, I compiled them and beside the produced executable file of the 2 projects you can find the DLL file that has been imported. The problem is without the DLL(beside the executable) the program doesn't work. What I was expecting is that during the compilation of the 2 projects(client and server) the DLL is somehow integrated on the executable file and I could just copy the EXE file and run it on any computer. Do you have any idea how I can do this?
|
|
|
|
|
You can't. You obvioulsy misunderstood what a dll is. It's a seperate file. You can write a ton of code to fail gracefully, but the point of a dll is to be seperate. If you want it all in the exe, move the code into the main project.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
|
Hello,
I have a console application the runs every few minutes and processes some files.
I am using the timer to do that.
However, I want the console window to disappear when my code is done processing all the files, then to reappear after the specific time has elapsed.
I dont know how to do this.
Thanks.
|
|
|
|
|
The simple way is to run it via a Scheduled Task instead.
|
|
|
|
|
Thanks PIEBALD. I think thats a great idea.
|
|
|
|
|
This p/invoke works
[DllImport("Kernel32.dll")]
public static extern int AllocConsole();
[DllImport("Kernel32.dll")]
public static extern int FreeConsole();
...
System.Threading.Thread.Sleep(3000);
FreeConsole();
System.Threading.Thread.Sleep(3000);
AllocConsole();
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So, in the example - its going to allocate the console for 3 sec and then free it for 3 sec?
In my Main - I have the following:
<br />
Timer myTimer = new Timer();<br />
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );<br />
myTimer.Interval = 900000;<br />
myTimer.Start();<br />
while (Console.Read() != 'q')<br />
{<br />
;<br />
} <br />
How do I incorporate System.Threading.Thread.Sleep here. I'd have to get rid of the timer?
Thanks.
|
|
|
|
|
The Sleep(3000) in my example just demonstrated it -
in my case I was testing from a console app so the console
was already open when the sample code was hit.
I let it show for 3 seconds, hide it for three seconds,
then show it again.
You could use the same code in a GUI app but you'd need to
call AllocConsole() first to show the console window.
The Sleep() was to demonstrate that it works - you shouldn't be using
Sleep() - you have a timer
AllocConsole() shows the console, FreeConsole() hides it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, Great - Mark.
In my while loop, I called the AllocConsole and FreeConsole, but my console still stays.
Also, I was actually trying to synchronize it with the processing. So, its like -
1) After 15 seconds has elapsed, the console pops up - the program does the processing.
2) As soon as the processing completes - the console goes away.
3) Repeat.
Thanks for all your help.
|
|
|
|
|
Ekjon wrote: In my while loop, I called the AllocConsole and FreeConsole
Then what's the timer for?
Ekjon wrote: After 15 seconds has elapsed,
Is that controlled by the timer? If I did the math
correctly, your timer is at 15 MINUTE intervals, not 15 seconds.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thats right.
The reason is - I was testing it and didn't want to wait for 15 minutes every time, so I set it to 90000 which is 1.5 minute.
So, the problem is: the console just stays, while it should go away when the FreeConsole() is called.
Thanks.
|
|
|
|
|
hmm I'm not sure what's happening. Without your code it's tough to debug
All I know is I tested the code I posted in a C# console app.
If you make a C# console app that does the following, does it work?
[DllImport("Kernel32.dll")]
public static extern int AllocConsole();
[DllImport("Kernel32.dll")]
public static extern int FreeConsole();
static void Main(string[] args)
{
Console.WriteLine("Hi from the first console");
System.Threading.Thread.Sleep(3000);
FreeConsole();
System.Threading.Thread.Sleep(3000);
AllocConsole();
Console.WriteLine("Hi from the second console");
Console.WriteLine("\r\n\r\n");
Console.WriteLine("Press Enter to end...");
Console.ReadLine();
}
If that works, then what are you doing different in your code?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I did the following and it's working fine now.
[DllImport("Kernel32.dll")]public static extern int AllocConsole();<br />
[DllImport("Kernel32.dll")]public static extern int FreeConsole();<br />
static void Main(string[] args)<br />
{<br />
System.Timers.Timer myTimer = new System.Timers.Timer();<br />
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );<br />
myTimer.Interval = 90000;<br />
myTimer.Start();<br />
while (true)<br />
{ <br />
;<br />
}<br />
}<br />
public static void DisplayTimeEvent( object source, ElapsedEventArgs e )<br />
{<br />
AllocConsole();<br />
FreeConsole();<br />
}<br />
Before...I was trying to call them in the wrong place.
Thanks so much.
|
|
|
|
|