EXIT CODE

Featured by

INTRODUCTION TO C#

Microsoft’s .NET and C# opens a whole New World of possibilities. There are many people in the industry, which see a great future to the .NE...

22/01/2018

Searching from a textbox

try
            {

                string Query = "select * from ellie_nhcpms.user;";
                MySqlCommand cmd = new MySqlCommand(Query, connection);
                connection.Open();
                DataSet ds = new DataSet();
                string commandString = "select * from ellie_nhcpms.user where username= '" + UserName.Text + "'";
                MySqlCommand sqlCmd = new MySqlCommand(commandString, connection);
                MySqlDataReader read = sqlCmd.ExecuteReader();


                if (read.Read() == true)
                {
                    lblhos.Text = read["hospitalname"].ToString();
                    label11.Text = read["empid"].ToString();

                   


                }
                else
                {
                    lblhos.Text = "";
                    label11.Text = "";

                  
                }

                                connection.Close();
            }

            catch (Exception)
            {
                //MessageBox.Show(es.Message);
            }

ExIT Codes in C#

if (MessageBox.Show(" Are you sure you want to Exit?", "closing session ?", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                //e.Cancel = true;  
            }
            else
            {
                btnexit.Focus();
           
                Application.Exit();
              
            }

C# login codes


Login Codes

try
            {
              

                MySqlCommand cmd = new MySqlCommand("Select * from k2sales.user where usertype=@usertype and username=@username and password=@password", connection);

                cmd.Parameters.AddWithValue("@usertype", comboBox1.Text);
                cmd.Parameters.AddWithValue("@username", UserName.Text);
                cmd.Parameters.AddWithValue("@password", Password.Text);
                connection.Open();
                MySqlDataAdapter adapt = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adapt.Fill(ds);
                connection.Close();
                int count = ds.Tables[0].Rows.Count;
                //If count is equal to 1, than show frmMain form
                if (count == 1)
                {
                    timer2.Start();
                    progressBar1.Show();
                    label7.Show();
                  

                }
                else
                {
                    label8.Show();
                    label10.Show();
                  
                    MessageBox.Show("  Login Failure..!!!! please select correct Usertype with corresponding username and password..thank you ", "login error!! ");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

18/12/2017

Export Data to Excel in VB.net

VB.net Codes


How to export Data from your datagridview to Excel in Vb.net

 If DataGridView1.RowCount = Nothing Then
            MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf & "Please retrieve data in datagridview", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
        Dim rowsTotal, colsTotal As Short
        Dim I, j, iC As Short
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
        Dim xlApp As New Excel.Application
        Try
            Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
            Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
            xlApp.Visible = True

            rowsTotal = DataGridView1.RowCount - 1
            colsTotal = DataGridView1.Columns.Count - 1
            With excelWorksheet
                .Cells.Select()
                .Cells.Delete()
                For iC = 0 To colsTotal
                    .Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
                Next
                For I = 0 To rowsTotal - 1
                    For j = 0 To colsTotal
                        .Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
                    Next j
                Next I
                .Rows("1:1").Font.FontStyle = "Bold"
                .Rows("1:1").Font.Size = 12

                .Cells.Columns.AutoFit()
                .Cells.Select()
                .Cells.EntireColumn.AutoFit()
                .Cells(1, 1).Select()
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            'RELEASE ALLOACTED RESOURCES
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
            xlApp = Nothing
        End Try

12/10/2016

How to login in visual studio 2010


'select from the database and connections to the database using mysql'

Try
            Dim myConnection As String = "datasource=localhost;password=;database=pis;username=root;"
            Dim mycon As MySqlConnection = New MySqlConnection(myConnection)
            Dim SelectCommand As MySqlCommand = New MySqlCommand("Select * from  pis.user where usertype='" & TextBox2.Text & "' and PassWord='" & TextBox1.Text & "';", mycon)
            Dim myReader As MySqlDataReader
            mycon.Open()
            myReader = SelectCommand.ExecuteReader()
            Dim mozzy As String = Status(TextBox2.Text, TextBox1.Text)
            If mozzy = "Admin" Then
                Timer1.Start()
                ProgressBar1.Show()
                Label22.Show()
            ElseIf mozzy = "Doctor" Then
                Timer3.Start()
                ProgressBar1.Show()
                Label22.Show()
            Else
                Timer2.Start()
                ProgressBar1.Show()
                Label22.Show()
            End If
            mycon.Close()
        Catch ex As Exception
        End Try
    End Sub
'function that gets the inputs that the user inputs and matches it with data in the database'
    Function Status(ByVal usertype As String, ByVal password As String)
        Dim status1 As String = Nothing
        Dim CurrentRow As Integer = 0
        Try
            Dim constring As String = "datasource=localhost;port=3306;username=root;database=pis;"
            Dim conDatabase As MySqlConnection = New MySqlConnection(constring)
            Dim cmdDatabase As MySqlCommand = New MySqlCommand("SELECT *FROM `user` WHERE `usertype` ='" & usertype & "' AND `password` = '" & password & "';", conDatabase)
            Dim sda As MySqlDataAdapter = New MySqlDataAdapter()
            sda.SelectCommand = cmdDatabase
            Dim db As DataTable = New DataTable()
            sda.Fill(db)
            status1 = db.Rows(CurrentRow)("usertype")

            conDatabase.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Return status1
    End Function

26/08/2016

Reasons for C# programing in the Field of Technology

To learn the C# language, I had to refer to all available material – books, articles on the net, discussion groups. As I studied the C# language, I kept making notes. I felt the need of a single repository where individuals could go to and know everything about a particular topic in C# – this repository became the Study Notes. Please appreciate, that this is not a book on C#.

INTRODUCTION TO C#

Microsoft’s .NET and C# opens a whole New World of possibilities. There are many people in the industry, which see a great future to the .NET. We now have .NET, a new and exciting technology that finally addresses issues we’ve been grappling with for years.

WHAT IT MEANS TO START C#
To build and run your C# programs, you will need Windows 2000, IE 5.5, Microsoft .NET SDK (Beta 1), an optional Visual Studio .NET (available for MSDN Universal Subscribers) and an optional free C# IDE – Sharp Develop. The C# IDE is available from http://www.icsharpcode.net/OpenSource/SD/Download/default.asp . The .NET SDK can be downloaded from http://msdn.microsoft.com/net It’s an 80MB download. The C# compiler (csc.exe) currently ships with the .NET beta. Do not get confused by this, because as of today we have the Beta 1 version of .NET, the PDC version and the pre Beta 2 version. The use of Visual Studio.NET has been intentionally avoided, to focus on the language and runtime environment and not place any restrictions on your particular development environment. Therefore, all the sample codes in these notes will compile and run from the command line.

17/08/2016

CODES FOR Android:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import example.david.R;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class Viewall extends Activity {
    String JsonResult;
    ListView vx;
    JSONArray Rdetails;
    ArrayList<HashMap<String, String>>registerList;
private String URLRetrievedetails ="http://10.0.2.2/nanyonga/retrive.php";
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewall);
        vx=(ListView)findViewById(R.id.va);
        registerList=new ArrayList<HashMap<String, String>>();
        getData();

}
private class JsonReaddetails extends AsyncTask<String, Void, String> {
       
          @Override
          protected String doInBackground(String... params) {
             
           HttpClient httpclient = new DefaultHttpClient();
           HttpPost httppost = new HttpPost(params[0]);
           try {
            HttpResponse response = httpclient.execute(httppost);
            JsonResult = inputStreamToString(
              response.getEntity().getContent()).toString();
           }
       
           catch (ClientProtocolException e) {
            e.printStackTrace();
           } catch (IOException e) {
            e.printStackTrace();
           }
           return null;
          }
       
          private StringBuilder inputStreamToString(InputStream is) {
           String rLine = "";
           StringBuilder answer = new StringBuilder();
           BufferedReader rd = new BufferedReader(new InputStreamReader(is));
       
           try {
            while ((rLine = rd.readLine()) != null) {
             answer.append(rLine);
            }
           }
       
           catch (IOException e) {
            // e.printStackTrace();
            Toast.makeText(getApplicationContext(),"Error..." + e.toString(), Toast.LENGTH_LONG).show();
           }
           return answer;
          }
       
          @Override
          protected void onPostExecute(String result) {
              ShowResult();
          }
         }
         // end async task
       
         public void getData() {
             JsonReaddetails pdetails = new JsonReaddetails();
          // passes values for the urls string array
          pdetails.execute(new String[] { URLRetrievedetails });
         }
       
         // build hash set for list view
         public void ShowResult() {
             // either you can call ArrayList here or in the method
    //personalList = new ArrayList<HashMap<String, String>>();
          try {
           JSONObject jsonResponse = new JSONObject(JsonResult);
           Rdetails = jsonResponse.getJSONArray("Register");
         // here we are looping
           for (int i = 0; i < Rdetails.length(); i++) {
              
            JSONObject y = Rdetails.getJSONObject(i);
            String first= y.getString("FirstName");
           String last = y.getString("LastName");
           String tel = y.getString("Telephone");
           String uname = y.getString("Username");
           String pass = y.getString("Password");
            String outPut ="\n\n"  +"FName=:"+" "+first+"\n"+"LName=:"+" "+last+"\n"+"Tel=:"+" "+tel+"\n"+"UserN=:"+" "+uname+"\n"+"PasswOrd=:"+pass+"\n";
            registerList.add(CreateRegister("registerdetails", outPut));
           }
          } catch (JSONException e) {
           Toast.makeText(getApplicationContext(), "Error" + e.toString(),
             Toast.LENGTH_SHORT).show();
          }
       
          SimpleAdapter simpleAdapter = new SimpleAdapter(this, registerList,android.R.layout.simple_list_item_1,
            new String[] { "registerdetails" }, new int[] { android.R.id.text1 });
          vx.setAdapter(simpleAdapter);
         }
         // this definies the table.You can use all field or you can use afew
         private HashMap<String, String> CreateRegister(String  firsname, String lastname) {
          HashMap<String, String> registerList = new HashMap<String, String>();
          registerList.put(firsname, lastname);
          return registerList;
         }
    //===============================================================================================
         // the view /display codes endes here
         //==========================================================================================
       


Most people tend to lose hope if any part of their machines has got any fault but trust us  this is not as difficult as we think because anyone either me or you can fix any basic fault on your machine and this is as simple as eating a piece of cake.so in any case your machine is doing some thing you don't know please don't hesitate to ask help from our team .If you also  have any system that you would like to come up with or you need any  team to design for you a particular system for any of your business.also contact Ian's IT consultancy.





if your not well informed about the basics of a computer and you need prior knowledge about the functions and also how most times machines are assembled please visit this blog for  help or contact me at crudiossegawa@gmail.com