コード例 #1
0
        public void Add(Managers customer)
        {
            try
            {
                using (var conn = GetConnection())
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "INSERT INTO Managers(FullNameManager, Note, PercentOnSale,Phone,StartDateWork) VALUES(@FullNameManager,  @Note, @PercentOnSale,@Phone,@StartDateWork)";
                        cmd.Parameters.AddWithValue("@FullNameManager", customer.FullName);
                        // cmd.Parameters.AddWithValue("@IDManager", customer.IDManager);
                        cmd.Parameters.AddWithValue("@Note", customer.Note);
                        cmd.Parameters.AddWithValue("@PercentOnSale", customer.PercentOnSale);
                        cmd.Parameters.AddWithValue("@Phone", customer.Phone);
                        DateTime d    = Convert.ToDateTime(customer.StartDateWork);
                        string   date = d.ToString("yyyy-MM-dd 00:00:00.000");
                        cmd.Parameters.AddWithValue("@StartDateWork", date);

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Ошибка");
            }
        }
コード例 #2
0
        private static Managers LoadManagers(SqlDataReader reader)
        {
            Managers manager = new Managers();

            try
            {
                manager.FullName      = reader.GetString(reader.GetOrdinal("FullNameManager"));
                manager.IDManager     = reader.GetInt32(reader.GetOrdinal("IDManager"));
                manager.Note          = reader.GetString(reader.GetOrdinal("Note"));
                manager.PercentOnSale = (float)reader.GetDouble(reader.GetOrdinal("PercentOnSale"));
                manager.Phone         = reader.GetDouble(reader.GetOrdinal("Phone"));
                manager.StartDateWork = reader.GetDateTime(reader.GetOrdinal("StartDateWork"));
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Ошибка");
            }

            return(manager);
        }