Exemple #1
0
        //Пишем историю книги
        public void AddBooksHistory(int id, _Readership reader)
        {
            string insert = "Insert Into BooksHistory(Id, Login, DateOfIssue) Values(@Id, @Login, @DateOfIssue)";

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionStrings.DBQuery))
                {
                    using (SqlCommand cmd = new SqlCommand(insert, connection))
                    {
                        connection.Open();
                        cmd.Parameters.AddWithValue("@Id", id);
                        cmd.Parameters.AddWithValue("@Login", reader.Login);
                        cmd.Parameters.AddWithValue("@DateOfIssue", DateTime.Now.ToShortDateString());
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                System.IO.StreamWriter writer = new System.IO.StreamWriter(@"C:\Users\Dmitriy\Downloads\WebApplication2\WebApplication2\WebApplication2\App_Data\ErrorLogDataBase.txt", true);
                writer.WriteLine(string.Format("Date : " + DateTime.Now.ToString() + " Error : " + ex.Message));
                writer.Close();
            }
        }
Exemple #2
0
        //Вернуть книгу
        public void BooksReturn(_Readership reader)
        {
            string insert = string.Format("Update BooksHistory Set DateOfReturn = '{0}' Where Login = '******'", DateTime.Now.ToShortDateString(), reader.Login);

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionStrings.DBQuery))
                {
                    using (SqlCommand cmd = new SqlCommand(insert, connection))
                    {
                        connection.Open();

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                System.IO.StreamWriter writer = new System.IO.StreamWriter(@"C:\Users\Dmitriy\Downloads\WebApplication2\WebApplication2\WebApplication2\App_Data\ErrorLogDataBase.txt", true);
                writer.WriteLine(string.Format("Date : " + DateTime.Now.ToString() + " Error : " + ex.Message));
                writer.Close();
            }
        }