コード例 #1
0
ファイル: FormClientNav.cs プロジェクト: forr/BonTemps
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (update == false)
            {
                try
                {
                    Client c = new Client(null,
                                          this.tbxFirstName.Text,
                                          this.tbxLastName.Text,
                                          this.tbxAddress.Text,
                                          this.tbxPostalCode.Text,
                                          this.tbxCity.Text,
                                          this.tbxPhoneNumber.Text,
                                          this.tbxEmail.Text,
                                          0);

                    if (new Database().Insert(Database.TableName.Clients, c.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)))
                    {
                        if (fmOrigin.GetType() == typeof(FormMain))
                        {
                            FormMain fm = (FormMain)fmOrigin;
                            fm.FormNewClient_CloseOnAdd();
                        }
                        this.Close();
                    }
                    else
                        MessageBox.Show("Failed to add new user");
                }
                catch
                {
                    MessageBox.Show("Failed to add new user");
                }
            }
            else
            {
                try
                {
                    if(new Database().Update(Database.TableName.Clients, new String[] { "Address", "PostalCode", "City", "PhoneNumber", "Email" }, new String[] { this.tbxAddress.Text, this.tbxPostalCode.Text, this.tbxCity.Text, this.tbxPhoneNumber.Text, this.tbxEmail.Text }, id))
                    {
                            if (fmOrigin.GetType() == typeof(FormMain))
                            {
                                FormMain fm = (FormMain)fmOrigin;
                                fm.FormNewClient_CloseOnAdd();
                            }
                            this.Close();
                    }
                    else
                    {
                            MessageBox.Show("Failed to edit new user");
                    }
                }
                catch
                {
                    MessageBox.Show("Failed to edit new user");
                }
            }
        }
コード例 #2
0
ファイル: Database.cs プロジェクト: forr/BonTemps
 public override List<Client> GetClientListByName(string name)
 {
     List<Client> result = new List<Client>();
     string statement = String.Format("SELECT * FROM Clients WHERE Name LIKE @Name");
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 sqlQuery.Parameters.AddWithValue("@Name", "%" + name + "%");
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 while (sqlDR.Read())
                 {
                     Client c = new Client();
                     c.ClientID = Convert.ToUInt64(sqlDR["ClientID"]);
                     c.FirstName = sqlDR["Name"].ToString().Split(' ')[0];
                     c.LastName = (sqlDR["Name"].ToString().Replace(c.FirstName, "")).Remove(0, 1);
                     c.Address = sqlDR["Address"].ToString();
                     c.PostalCode = sqlDR["PostalCode"].ToString();
                     c.City = sqlDR["City"].ToString();
                     c.PhoneNumber = sqlDR["PhoneNumber"].ToString();
                     c.Email = sqlDR["Email"].ToString();
                     c.Visits = (int)sqlDR["Visits"];
                     result.Add(c);
                 }
             }
             return result;
         }
     }
     catch(Exception ex)
     {
         return result;
     }
 }
コード例 #3
0
ファイル: Database.cs プロジェクト: forr/BonTemps
 public override Client GetClient(ulong clientID)
 {
     Client result = Client.Null;
     string statement = "SELECT * FROM Clients WHERE ClientID=@ID";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 sqlQuery.Parameters.AddWithValue("@ID", (int)clientID);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 if (sqlDR.Read())
                 {
                     Client c = new Client();
                     c.ClientID = Convert.ToUInt64(sqlDR["ClientID"]);
                     c.FirstName = sqlDR["Name"].ToString().Split(' ')[0];
                     c.LastName = (sqlDR["Name"].ToString().Replace(c.FirstName, "")).Remove(0, 1);
                     c.Address = sqlDR["Address"].ToString();
                     c.PostalCode = sqlDR["PostalCode"].ToString();
                     c.City = sqlDR["City"].ToString();
                     c.PhoneNumber = sqlDR["PhoneNumber"].ToString();
                     c.Email = sqlDR["Email"].ToString();
                     c.Visits = (int)sqlDR["Visits"];
                     return c;
                 }
                 result = Client.Null;
             }
         }
     }
     catch { result = Client.Null; }
     return result;
 }
コード例 #4
0
ファイル: Database.cs プロジェクト: forr/BonTemps
 public override List<Client> GetAllClients()
 {
     List<Client> clnt = new List<Client>();
     string statement = "SELECT * FROM Clients";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 while (sqlDR.Read())
                 {
                     Client c = new Client();
                     c.ClientID = Convert.ToUInt64(sqlDR["ClientID"]);
                     c.FirstName = sqlDR["Name"].ToString().Split(' ')[0];
                     c.LastName = (sqlDR["Name"].ToString().Replace(c.FirstName, "")).Remove(0,1);
                     c.Address = sqlDR["Address"].ToString();
                     c.PostalCode = sqlDR["PostalCode"].ToString();
                     c.City = sqlDR["City"].ToString();
                     c.PhoneNumber = sqlDR["PhoneNumber"].ToString();
                     c.Email = sqlDR["Email"].ToString();
                     c.Visits = (int)sqlDR["Visits"];
                     clnt.Add(c);
                 }
                 return clnt;
             }
             return null;
         }
     }
     catch { return null; }
 }