Saturday, May 12, 2012

Project Layers




Any project should consist of three layer, Dataabase, Classes and forms layer. Each one of these layer contain objects that need to create and develop.

Application Life cycle developing components

Database Layer, Contains objects such as Database files, tables, View, Functions and Stored procedures. Programmer will create and develop each of these objects.

Database Layer Components.

1-DatabaseFiles: that will store all objects of the project.
2- Tables: tables created to storing row data and normalize it.
3-Stored Procedures: SPs or Stored Procedures keeps the actions that needed to be fired when project want.
4- Functions: Keeps all answers for all questions needed to be answered for project.
5- Views: project needs Views for displaying Reports.
After finishing Database layer, programmer needs to call these objects from application. To do that, programmer need to developing Classes Layer.
Classes Layer, created in the application development environment by Classes files. Each of class refer to one object in the database Layer.
For example, Emp_Tbl is a table object in the database layer. For manipulate with this object its need to create Class with name Cls_Emp, and so on with all tables in the database.

Classes Layer Components.

Create Class file for each table in the Database. Each class will contain blocks of code that will work with Store Procedures and Functions that associated with specific table.
ID
Database Layer
Classes Layer

Table Name
Associated Objects
(Store Procedures, Functions)
Blocks of code in Class
(Methods)
Class Name
1
Dep_Tbl
Dep_Insert_SP
Dep_Insert
Cls_Dep
Dep_Update_SP
Dep_Update
Dep_Delete_SP
Dep_Delete
Dep_SelectALL_Fun
Dep_SelectALL
Dep_GetInfo_Fun
Dep_GetInfo
Dep_GetMax_Fun
Dep_GetMax
2

On the other hand, Working with Forms layer need first finish the previous layer in order to avoid errors, change Requests issues and Work around.
Forms Layer, means Working with User interface of the project and how to let the application interface to communicate with database layer throw classes layer. Forms layer contains a set of files. Each file consists of set of controls that will display for user to let him interacting with data of project.

Forms layer Components.

One or more classes in the class's layer will be act with one form in the forms layer.
ID
Table Name
Class Name
From Name
Form Search
1
Dep_Tbl
Cls_Dep
Frm_Dep
Frm_Dep_Search
2

Friday, March 23, 2012

Microsoft Day Presentation.

I prepare This presentation for new products of Microsoft. in fact it's a fast show, but it's important to know that is new about new products, and that is new trend of Microsoft in the near future about describing life !

i will let you now with Microsoft, Microsoft can show and describe it self  :)







































delegate in C#


delegate void MyDelegate(string s);

    class MyClass
    {
        public static void Hello(string s)
        {
            Console.WriteLine("  Hello, {0}!", s);
        }

        public static void Goodbye(string s)
        {
            Console.WriteLine("  Goodbye, {0}!", s);
        }

        public static void Main()
        {
            MyDelegate a, b, c, d;

            // Create the delegate object a that references
            // the method Hello:
            a = new MyDelegate(Hello);
            // Create the delegate object b that references
            // the method Goodbye:
            b = new MyDelegate(Goodbye);
            // The two delegates, a and b, are composed to form c:
            c = a + b;
            // Remove a from the composed delegate, leaving d,
            // which calls only the method Goodbye:
            d = c - a;

            Console.WriteLine("Invoking delegate a:");
            a("A");
            Console.WriteLine("Invoking delegate b:");
            b("B");
            Console.WriteLine("Invoking delegate c:");
            c("C");
            Console.WriteLine("Invoking delegate d:");
            d("D");
        }
    }

Sunday, September 11, 2011

Sending E-Mail by C#.NET, Simple steps

Step 1 : Design Preparation.

we need the following design in windows application project.



the above forms for SMTP Configuration form and Sending Mail form.

Step 2 : Add the SMTP configuration class

add the following class in you project in order to make a SMTP configuration for your mail that we need to send.

public class cls_smtpConfiguration 
    {
        public static string host;
        public static int port;
        public static int timeout;
        public static bool enable_ssl;
        public static string username_account;
        public static string password_account;
    }

this class has a values from SMTP Configuration form and will get it for Sending Mail form.


Step 3 : In the SMTP Configuration form
Add the following code in the button Save Setting in the SMTP Configuration form

            cls_smtpConfiguration.host = textBox1.Text;
            cls_smtpConfiguration.port = Convert.ToInt32(textBox2.Text);
            cls_smtpConfiguration.timeout = Convert.ToInt32(textBox4.Text);
            if (radioButton1.Checked == true)
            {
                cls_smtpConfiguration.enable_ssl = true;
            }
            else 
            {
                cls_smtpConfiguration.enable_ssl = false;
            }
            cls_smtpConfiguration.username_account = textBox6.Text;
            cls_smtpConfiguration.password_account = textBox5.Text;
            this.Close();


The above code try to setting values from controls of form to members of cls_smtpConfiguration Class

Step 4 : In the 
Sending Mail form

follow the following steps under the Send mail button

  • Define the following line

  1. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
  2. System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(cls_smtpConfiguration.host, cls_smtpConfiguration.port);
  3. System.Net.Mail.Attachment attach;
message object : for setting values (from, to, body ....)
smtp object : for setting smtp configuration about from mail
attach object : for setting the attachement files that is required to be attached with mail .

  • Try to validate [mail from] and [mail to]
  • if (ValidateEmail(textBox2.Text) == true) { message.To.Add(textBox2.Text); } else { MessageBox.Show("not valid mail");return; }
    if (ValidateEmail(textBox1.Text) == true) {message.From = new System.Net.Mail.MailAddress(textBox1.Text); } else { MessageBox.Show("not valid mail"); return; }
  • Setting the following values
  1. message.Subject = textBox3.Text;
  2. message.Body = richTextBox1.Text;
  3. smtp.Timeout = cls_smtpConfiguration.timeout;
  4. smtp.EnableSsl = cls_smtpConfiguration.enable_ssl;
  5. smtp.Credentials = new System.Net.NetworkCredential(cls_smtpConfiguration.username_account, cls_smtpConfiguration.password_account);
  • the following code for setting [attach] object all attachement that is exist in listbox1
  • if (listBox1.Items.Count > 0) { for (int i = 0; i < listBox1.Items.Count; i++) { attach = new System.Net.Mail.Attachment(listBox1.Items[i].ToString()); message.Attachments.Add(attach); } }
  • Final Step, sending mail
  • smtp.Send(message); MessageBox.Show("message sended !!");
follow the following steps under the SMTP configure button

Form2 x = new Form2();
x.ShowDialog();


follow the following steps under the Select button

OpenFileDialog x = new OpenFileDialog();
x.ShowDialog();
listBox1.Items.Add(x.FileName);



How to validate E-mail by C#, Simple Steps

Step 1: type the following reference in above your class form

using System.Text.RegularExpressions;

Step 2: Insert the following method in your application.


 public bool ValidateEmail(string sEmail)
        {
            Regex exp = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
            Match m = exp.Match(sEmail);
            if (m.Success && m.Value.Equals(sEmail))
            {
                return true;
            }
            else 
            {
                return false;
            }
        }


Step 3 : Call above method in any pace you want .

if (ValidateEmail(textBox2.Text) == true)
    {
         MessageBox.Show("valid mail");
     }
else { MessageBox.Show("not valid mail"); }