Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, October 5, 2018

Use whatsApp link in desktop application in C#

Code 

private void barButtonItem55_ItemClick(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://web.whatsapp.com/");
        }


Color mixer in C# application by using Devexpress

Code:

private void barButtonItem36_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

           using (DevExpress.XtraEditors.ColorWheel.ColorWheelForm f = new DevExpress.XtraEditors.ColorWheel.ColorWheelForm())
            {
                f.ShowDialog(this);
            }
        }

Thursday, October 4, 2018

Send email with multiple attachment by using yahoo server in C# code


 try
                {
                    var message = new MailMessage(txtsenderEmail.Text, txtrecEmail.Text);
                    message.Subject = txtSubject.Text;
                    message.Body = rboxBody.Text;
                    if (txtattachement.TextLength > 0)
                        message.Attachments.Add(new Attachment(txtattachement.Text));
                    if (textattechment2.TextLength > 0)
                        message.Attachments.Add(new Attachment(textattechment2.Text));
                    if (txtattech3.TextLength > 0)
                        message.Attachments.Add(new Attachment(txtattech3.Text));
                    using (SmtpClient mailer = new SmtpClient("smtp.mail.yahoo.com", 587))
                    {
                        mailer.Credentials = new NetworkCredential(txtsenderEmail.Text, txtPassword.Text);
                        mailer.EnableSsl = true;
                        mailer.Send(message);

                    }
                    txtattachement.Text = null;
                    txtSubject.Text = null;
                    txtrecEmail.Text = null;
                    rboxBody.Text = null;
                    MessageBox.Show("Email succesfull sent", "Message");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex, "Message");
                }
            }

How to send email by using yahoo server in C# code

 try
                {
                    var message = new MailMessage(txtsenderEmail.Text, txtrecEmail.Text);
                    message.Subject = txtSubject.Text;
                    message.Body = rboxBody.Text;
                   
                    using (SmtpClient mailer = new SmtpClient("smtp.mail.yahoo.com", 587))
                    {
                        mailer.Credentials = new NetworkCredential(txtsenderEmail.Text, txtPassword.Text);
                        mailer.EnableSsl = true;
                        mailer.Send(message);

                    }
                   
                    MessageBox.Show("Email succesfull sent", "Message");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex, "Message",);
                }
            }

How to restore database from backup file in C#

To Download Click here..
Note : use CircularProgressBar.dll for percentage

How to create backup of a database in C# and connect circular bar with it

To Download Code Click here...
Note : use CircularProgressBar.dll for percentage

How to get Processor ID in C#

var mbs = new ManagementObjectSearcher("Select ProcessorID From Win32_processor");
            var mbsList = mbs.Get();

            foreach (ManagementObject mo in mbsList)
            {
               string cpuid = mo["ProcessorID"].ToString();
            }

Wednesday, October 3, 2018

How to get Mac Address in C#

 public string GetMACAddress()
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            String sMacAddress = string.Empty;
            foreach (NetworkInterface adapter in nics)
            {
                if (sMacAddress == String.Empty)// only return MAC Address from first card
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    sMacAddress = adapter.GetPhysicalAddress().ToString();
                }
            }
            return sMacAddress;
        }

How to insert image in database in C#

using System;
namespace CarShowRoom
{
    public partial class frmSale : DevExpress.XtraEditors.XtraForm
    {
        SqlConnection con = CString.con;
        MemoryStream ms;
        byte[] photo_aray;
        public frmSale()
        {
            InitializeComponent();
        }
 public void btnInsert()
        {
            string query;
          
            if (pictureEdit1.Image != null)
            {
                query = "INSERT INTO Sale(ID,Image) VALUES (@txtID,@photo)";
            }
            else
            {
            "INSERT INTO Sale(ID) VALUES (@txtID)";
            }
            try
            {
                using (SqlCommand command = new SqlCommand(query, con))
                {
                    command.Parameters.AddWithValue("@txtID", txtID.EditValue);
                  
                    if (pictureEdit2.Image != null)
                    {

                        ms = new MemoryStream();
                    pictureEdit2.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        byte[] photo_aray = new byte[ms.Length];
                        ms.Position = 0;
                        ms.Read(photo_aray, 0, photo_aray.Length);
                        command.Parameters.AddWithValue("@photo", photo_aray);
                    }
                    con.Open();
                    int result = command.ExecuteNonQuery();

                    // Check Error
                    if (result < 0)
                        XtraMessageBox.Show("Error");

                    con.Close();

                }

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("ITEM" + ex.Message);
            }
}
}
}
       


Transaction Scope in C#

  
we can define transaction scope by using transaction library. 
using (TransactionScope scope = new TransactionScope())
            {
               int a=5,b=10,sum=0;
                sum=a+b;
                scope.Complete();
                XtraMessageBox.Show("Record Add");
            }

How to load data in datagridview or gridControl in C#

 private void LoadRecord()
        {
            string sql = "SELECT * FROM SaleInvoice";

            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            con.Open();
            dataadapter.Fill(ds, "Authors_table");
            con.Close();
            gridControl1.DataSource = ds;
            gridControl1.DataMember = "Authors_table";

        }

Monday, October 1, 2018

Insert query in C#

   string query = "INSERT INTO  History (Name,Code,) VALUES (@HName,@HCode, )"
                using (SqlCommand command = new SqlCommand(query, con))
                {  
                    command.Parameters.AddWithValue("@HName", txtAccount.Text);
                    command.Parameters.AddWithValue("@HCode", txtAccount.EditValue);
 
                    con.Open();
                    int result = command.ExecuteNonQuery();

                    // Check Error
                    if (result < 0)
                        MessageBox.Show("Error");
                  
                    con.Close();
                   }

Clear image on picturebox in C#

   private void btnRemove_Click(object sender, EventArgs e)
        {
            if (pictureEdit1.Image != null)
            {
                pictureEdit1.Image.Dispose();
                pictureEdit1.Image = null;
            }
        }

How to upload image in picturebox by OpenFileDialog in c#

 private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
            DialogResult res = openFileDialog1.ShowDialog();
            if (res == DialogResult.OK)
            {
                pictureEdit1.Image = Image.FromFile(openFileDialog1.FileName);
            }
        }

Friday, September 28, 2018

How to add two integers in C# program?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=5, b=10, sum=0;
            sum = a + b;
            Console.Write("Sum = "+sum);
          

           
            Console.Read();
        }
    }
}

How to print integers from 1 to 10 in C#?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
          
            for (int i = 0; i <= 10; i++)
            {
                Console.WriteLine(i);
            }
            Console.ReadLine();
        }
    }
}

Thursday, September 27, 2018

C# Introduction

C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java.
.NET framework, Microsoft included a new language called C# (pronounced C Sharp). C# is designed to be a simple, modern, general-purpose, object-oriented programming language, borrowing key concepts from several other languages, most notably Java.
C# could theoretically be compiled to machine code, but in real life, it’s always used in combination with the .NET framework. Therefore, applications written in C#, requires the .NET framework to be installed on the computer running the application. While the .NET framework makes it possible to use a wide range of languages, C# is sometimes referred to as THE .NET language, perhaps because it was designed together with the framework.