Exemple #1
0
        //public static List<Customers> ReadAllClients()
        //{
        //    List<Customers> xxClients = new List<Customers>();
        //    if (File.Exists(filePath))
        //    {
        //        StreamReader sr = new StreamReader(filePath);
        //        string line = sr.ReadLine();
        //        while (line != null)
        //        {
        //            string[] index = line.Split(',');
        //            Customers xx = new Customers();
        //            xx.ClientName = index[0];
        //            xx.ClientAddress = index[1];
        //            xx.ClientCity = index[2];
        //            xx.PostalCode = index[3];
        //            xx.ClientPhone = index[4];
        //            xx.ClientCredit = Convert.ToInt32(index[5]);
        //            xxClients.Add(xx);
        //            line = sr.ReadLine();
        //        }
        //        sr.Close();
        //    }
        //    if (xxClients.Count() <= 0)
        //        MessageBox.Show("Employee not found!", "Error");
        //    return xxClients;
        //}

        //public static void UpdateClients(Customers cli)
        //{
        //    StreamReader sr = new StreamReader(filePath);
        //    StreamWriter sw = new StreamWriter(filePath2);
        //    string line = sr.ReadLine();
        //    while (line != null)
        //    {
        //        string[] field = line.Split(',');
        //        if (cli.ClientName != field[0])
        //        {
        //            sw.WriteLine(field[0] + "," + field[1] + "," + field[2] + "," + field[3] + "," + field[4] + "," + field[5]);

        //        }
        //        line = sr.ReadLine();
        //    }
        //    sw.WriteLine(cli.ClientName + "," + cli.ClientAddress + "," + cli.ClientCity + "," + cli.PostalCode + "," + cli.ClientPhone + "," + cli.ClientCredit);
        //    sw.Close();
        //    sr.Close();
        //    File.Delete(filePath);
        //    File.Move(filePath2, filePath);
        //    MessageBox.Show("Update successfully!");

        //}

        public static List <Customers> GetCustomerList()
        {
            List <Customers> listCu = new List <Customers>();
            // Connect and open database
            SqlConnection connDB = UtilityDB.ConnectDB();
            // Perform insert statement
            //create an object of type SqlCommand
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connDB;
            cmd.CommandText = "SELECT * FROM Customers";
            SqlDataReader sqlReader = cmd.ExecuteReader();
            Customers     cu;

            while (sqlReader.Read())
            {
                cu              = new Customers();
                cu.CustomerId   = Convert.ToInt32(sqlReader["CustomerId"]);
                cu.CustomerName = sqlReader["CustomerName"].ToString();
                cu.Street       = sqlReader["Street"].ToString();
                cu.City         = sqlReader["City"].ToString();
                cu.PostalCode   = sqlReader["PostalCode"].ToString();
                cu.PhoneNumber  = sqlReader["PhoneNumber"].ToString();
                cu.FaxNumber    = sqlReader["FaxNumber"].ToString();
                cu.CreditLimit  = float.Parse(sqlReader["CreditLimit"].ToString());
                listCu.Add(cu);
            }
            // close database
            connDB.Close();
            return(listCu);
        }
Exemple #2
0
        public static void SavePass(Userr au)
        {
            // Connect and open database
            SqlConnection connDB = UtilityDB.ConnectDB();
            // Perform insert statement
            //create an object of type SqlCommand
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = connDB;
            string sqlInsert = "INSERT INTO Users " +
                               "(UserName,Password)" +
                               " VALUES (@UserName,@Password)";

            cmd.Parameters.AddWithValue("@UserName", au.UserName);
            cmd.Parameters.AddWithValue("@Password", au.Password);
            cmd.CommandText = sqlInsert;
            cmd.ExecuteNonQuery();
            // close database
            connDB.Close();
            MessageBox.Show("Employee record has been saved successfully", "Confirmation");
        }
Exemple #3
0
 public static bool IsValidUser(Userr myUser)
 {
     using (SqlConnection connectionDb = UtilityDB.ConnectDB())
     {
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = connectionDb;
         string sqlSelect = "SELECT UserName,Password FROM Users " +
                            "WHERE UserName = @UserName AND Password = @Password";
         cmd.CommandText = sqlSelect;
         cmd.Parameters.AddWithValue("@UserName", myUser.UserName);
         cmd.Parameters.AddWithValue("@Password", myUser.Password);
         SqlDataReader sqlReader = cmd.ExecuteReader();
         if (sqlReader.Read())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        public static void DeleteRecord(int empId)
        {
            SqlConnection conndb = UtilityDB.ConnectDB();

            try
            {
                string sqlDelete = "DELETE from Employees " +
                                   " WHERE EmployeeId = " + empId;

                SqlCommand cmd = new SqlCommand(sqlDelete, conndb);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Record deleted Successfully.");
            }
            catch (FormatException)
            {
                throw;
            }
            finally
            {
                conndb.Close();
            }
        }
        public static void SaveRecord(Employees emp)
        {
            // Connect and open database
            SqlConnection connDB = UtilityDB.ConnectDB();
            // Perform insert statement
            //create an object of type SqlCommand
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = connDB;
            string sqlInsert = "INSERT INTO Employees " +
                               "(EmployeeId,FirstName,LastName,JobTitle,Email)" +
                               " VALUES (@EmployeeId,@FirstName,@LastName,@JobTitle,@Email)";

            cmd.Parameters.AddWithValue("@EmployeeId", emp.EmployeeId);
            cmd.Parameters.AddWithValue("@FirstName", emp.FirstName);
            cmd.Parameters.AddWithValue("@LastName", emp.LastName);
            cmd.Parameters.AddWithValue("@JobTitle", emp.JobTitle);
            cmd.Parameters.AddWithValue("@Email", emp.Email);
            cmd.CommandText = sqlInsert;
            cmd.ExecuteNonQuery();
            // close database
            connDB.Close();
            MessageBox.Show("Employee record has been saved successfully", "Confirmation");
        }