Sunday, July 18, 2010

Use of role in SQL

CREATE USER u_asst_gm identified by asst_gm;
CREATE USER u_operator identified by operator;

//here create two users u_asst_gm and u_operator



CREATE ROLE r_asst_gm;
CREATE ROLE r_operator;
GRANT CREATE SESSION,CREATE TABLE,UNLIMITED TABLESPACE to r_asst_gm;
GRANT CREATE SESSION,UNLIMITED TABLESPACE to r_operator;

//here creates the role and grant privileges to the role


GRANT r_asst_gm to u_asst_gm;
GRANT r_operator to u_operator;

//here grant role to users


GRANT SELECT,INSERT,DELETE,UPDATE on customer to u_asst_gm;
GRANT SELECT,INSERT,DELETE,UPDATE on bill to u_asst_gm;
GRANT SELECT,INSERT,DELETE,UPDATE on payee to u_asst_gm;
GRANT SELECT,INSERT,UPDATE on bill to u_operator;
commit;

//grant table accessing privileges to users.


Enjoy SQL

Tuesday, July 6, 2010

How to define global variable in c# windows form

It is easy to use global like variable in web based application but quite hard to use it in windows form. Here the solution:

Add a new class.cs file to the project and then
static class GlobalClass
{
private string m_globalVar = "";
public static string GlobalVar
{
get { return m_globalVar; }
set { m_globalVar = value; }
}
}

Use it anywhere like this
GlobalClass.GlobalVar = "the_value_you_waant_to_put";
Access it anywhere like this
myFormLabel.Text = GlobalClass.GlobalVar;

Enjoy C#

Monday, July 5, 2010

Text to speech conversion in C#

In visual studio
Add reference: System.Speech
then header
system.speech.synthesizer;

then inside the button_click:

SpeechSynthesizer s = new SpeechSynthesizer();
s.Speak("The speech goes here whatever you like");

or,
you can use a textbox. Suppose it is textBox1 then,

s.Speak(textBox1.Text);


Enjoy C#

How to generate captcha in C#

The code below generates randomly captcha. You can access it in another page using session in C#.

Add using System.IO
the code is :

protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Bitmap objBmp = new System.Drawing.Bitmap(90, 25); System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp); objGraphics.Clear(System.Drawing.Color.Green); objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; System.Drawing.Font objFont = new System.Drawing.Font("Acoustic Light", 11, System.Drawing.FontStyle.Bold);
string strRandom = "";
string[] strArray = new string[36];
strArray = new string[] { "a", "b", "c" , "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A","R","S","F"};
Random autoRand = new Random();
int x;
for (x = 0; x < i =" Convert.ToInt32(autoRand.Next(0,">
}
Session.Add("strRandom", strRandom);
objGraphics.DrawString(strRandom, objFont, System.Drawing.Brushes.White, 3, 3); Response.ContentType = "image/GIF";
objBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); objFont.Dispose(); objGraphics.Dispose(); objBmp.Dispose();
}

Enjoy C#