public static SystemManager Login(string email, string password) { string query = string.Format("Select * From Employee Where " + "Employee.DEPARTMENT_ID = 5 and Employee.EMAIL = '{0}' and Employee.PASSWORD = '******'", email, password); DataTable dt = DataBaseEvents.ExecuteQuery(query, data_source); if (dt.Rows.Count <= 0) { return(null); } int employee_id = int.Parse(dt.Rows[0][0].ToString()); int department_id = int.Parse(dt.Rows[0][1].ToString()); string employee_name = dt.Rows[0][2].ToString(); string employee_surname = dt.Rows[0][3].ToString(); string employee_email = dt.Rows[0][4].ToString(); string employee_password = dt.Rows[0][5].ToString(); string employee_gender = dt.Rows[0][6].ToString(); string birth_date = dt.Rows[0][7].ToString(); string pic_path_file = dt.Rows[0][8].ToString(); DateTime b_date = Convert.ToDateTime(birth_date); SystemManager manager = new SystemManager(employee_id, department_id, employee_name, employee_surname, employee_password, employee_email, employee_gender, b_date, pic_path_file); return(manager); }
public GiveBook(Detail detail, User user, string query) { InitializeComponent(); dt_form = detail; this.lbl_message.Text = ""; if (query == "Select * From Books") { this.btn_return_book.Hide(); this.btn_give_book.Show(); this.tb_search_book.Enabled = true; } else { this.btn_give_book.Hide(); this.btn_return_book.Show(); this.tb_search_book.Enabled = false; } book_list = new Book_List(); search_list = new Book_List(); this.user = user; DataTable dt = DataBaseEvents.ExecuteQuery(query, datasource); SizeF scale = new Size(); scale.Width = (float)0.80; scale.Height = (float)0.80; book_list.Fill_Book_List(dt, book_list, search_list, null, pnl_book_list, INFO_COLOR_MODE.NORMAL, false); book_list.Draw_All_Books(); }
public void AddEventListener(DataBaseEvents eventName, DataBaseEventListener listener) { this.dispatcher.Invoke(() => { if (this.listenerHosts.ContainsKey(eventName) == true) { if (this.listeners.ContainsKey(eventName) == false) { this.listeners[eventName] = new DataBaseEventListenerCollection(); } this.listeners[eventName].Add(listener); var dataBases = this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.DataBases.Where(item => item.IsLoaded).ToArray()); var listenerHost = this.listenerHosts[eventName]; foreach (var item in dataBases) { listenerHost.Subscribe(item, listener); } } else { throw new NotImplementedException(); } }); }
private void Generate_Penalty_Message() { DateTime creation = DateTime.Now; DateTime receiving = DateTime.Now.AddDays(15.0); this.creation_date = creation.ToString(); this.receiving_date = receiving.ToString(); string book_name = DataBaseEvents.ExecuteQuery(("Select Books.NAME From Books Where Books.BOOK_ID = " + book_id), data_source).Rows[0][0].ToString(); string user_name = DataBaseEvents.ExecuteQuery(("Select Users.NAME From Users Where Users.USER_ID = " + user_id), data_source).Rows[0][0].ToString(); string gender = DataBaseEvents.ExecuteQuery(("Select Users.GENDER From Users Where Users.USER_ID = " + user_id), data_source).Rows[0][0].ToString(); int user_total_fee = int.Parse(DataBaseEvents.ExecuteQuery(("Select Users.FEE From Users Where Users.USER_ID = " + user_id), data_source).Rows[0][0].ToString()) + this.fee; string title = ""; if (gender == "Male") { title = "Mr."; } else { title = "Mrs."; } string msg = string.Format("{0} \"{1}\", you have been fined due to penalty of \"{2}\". Your fee is \"{3}\" and you cannot take another book until you pay all your fees (\"{4}\").", title, user_name, pt_name, fee, user_total_fee); this.message = msg; }
private void RemoveDataBaseEventListener(DataBaseEvents eventName, DataBaseEventListener listener) { if (this.Context.Properties[typeof(DataBaseEventListenerContext)] is DataBaseEventListenerContext context) { context.RemoveEventListener(eventName, listener); } else { throw new NotImplementedException(); } }
public Receipt_Detail(Receipt receipt, Book book, User user) { InitializeComponent(); main_page = (Microwave)Application.OpenForms["Microwave"]; main_receipt_list = main_page.Main_receipt_list; this.receipt = receipt; this.book = book; this.user = user; this.manager_id = receipt.Librarian_id; this.manager_name = DataBaseEvents.ExecuteQuery("Select ( NAME || ' ' || SURNAME) From Employee Where EMPLOYEE_ID = " + receipt.Librarian_id, data_source).Rows[0][0].ToString(); }
private void Generate_Return_Message() { DateTime now = DateTime.Now; this.creation_date = now.ToString(); this.receiving_date = now.ToString(); string book_name = DataBaseEvents.ExecuteQuery(("Select Books.NAME From Books Where Books.BOOK_ID = " + book_id), data_source).Rows[0][0].ToString(); string user_name = DataBaseEvents.ExecuteQuery(("Select Users.NAME From Users Where Users.USER_ID = " + user_id), data_source).Rows[0][0].ToString(); string msg = string.Format("\"{0}\" has been returned to the library by \"{1}\" on \"{2}\". " + "Thanks for your common sense." , book_name, user_name, creation_date);; this.message = msg; }
private void Generate_Give_Message() { DateTime creation = DateTime.Now; DateTime receiving = DateTime.Now.AddDays(15.0); this.creation_date = creation.ToString(); this.receiving_date = receiving.ToString(); string book_name = DataBaseEvents.ExecuteQuery(("Select Books.NAME From Books Where Books.BOOK_ID = " + book_id), data_source).Rows[0][0].ToString(); string user_name = DataBaseEvents.ExecuteQuery(("Select Users.NAME From Users Where Users.USER_ID = " + user_id), data_source).Rows[0][0].ToString(); string msg = string.Format("\"{0}\" has been borrowed by \"{1}\" on \"{2}\". " + "The book should be returned to the library in 15 days (\"{3}\"). Have a good time." , book_name, user_name, creation_date, receiving_date); this.message = msg; }
private void AddDataBaseEventListener(DataBaseEvents eventName, DataBaseEventListener listener) { if (this.Context.Properties.ContainsKey(typeof(DataBaseEventListenerContext)) == false) { this.eventListenerContext = new DataBaseEventListenerContext(this.cremaHost, this.eventListeners); this.Context.Properties[typeof(DataBaseEventListenerContext)] = this.eventListenerContext; } if (this.eventListenerContext != null) { this.eventListenerContext.AddEventListenerAsync(eventName, listener); } else { throw new NotImplementedException(); } }
// Reads ID's from database private void Join_Tables() { DataTable dt = null; string que_author = string.Format("Select Authors.AUTHOR_ID from Authors where Authors.NAME = '{0}'", author); string que_publisher = string.Format("Select Publishers.PUBLISHER_ID from Publishers where Publishers.NAME = '{0}'", publisher); string que_category = string.Format("Select Categories.CATEGORY_ID from Categories where Categories.NAME = '{0}'", category); string que_shelf = string.Format("Select Shelves.SHELF_ID from Shelves where Shelves.NAME= '{0}'", shelf); dt = DataBaseEvents.ExecuteQuery(que_author, data_source); author_id = int.Parse(dt.Rows[0][0].ToString()); dt = DataBaseEvents.ExecuteQuery(que_publisher, data_source); publisher_id = int.Parse(dt.Rows[0][0].ToString()); dt = DataBaseEvents.ExecuteQuery(que_category, data_source); category_id = int.Parse(dt.Rows[0][0].ToString()); dt = DataBaseEvents.ExecuteQuery(que_shelf, data_source); shelf_id = int.Parse(dt.Rows[0][0].ToString()); }
// Comboboxes Events private void Cb_author_SelectedIndexChanged(object sender, EventArgs e) { int last_index = cb_author.Items.Count - 1; if (cb_author.SelectedIndex == 0) { cb_author.ForeColor = Color.Gray; } else if (cb_author.SelectedIndex == last_index) { main_page.Create_Add_Author_Form(); string query = string.Format("Select {0}.NAME From {0}", "Authors"); DataTable dt = DataBaseEvents.ExecuteQuery(query, data_source); int rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } cb_author.Items.Clear(); cb_author.Items.Add("Author's Name"); for (int i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); cb_author.Items.Add(item); } cb_author.Items.Add("Add new Author"); cb_author.SelectedIndex = 0; } else { cb_author.ForeColor = Color.LightGray; } }
private void Fill_Book_Search_List_Box(string query) { lb_book_search.Items.Clear(); DataTable dt = DataBaseEvents.ExecuteQuery(query, datasource); int rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } for (int i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); if (lb_book_search.Items.Contains(item)) { continue; } lb_book_search.Items.Add(item); } }
public void Give_Penalty_To_User(User user, Book book, Receipt penalty, Detail detail) { penalty.Add(); user.Fee += penalty.Fee; user.Change_Fee(); detail.Tb_5.Text = user.Fee + "₺"; if (penalty.Pt_name == "LOST" || penalty.Pt_name == "DAMAGED") { user.Book_count--; string query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, user.User_id); DataTable dt = DataBaseEvents.ExecuteQuery(query_select, data_source); if (dt.Rows.Count <= 0) { return; } int current_count = int.Parse(dt.Rows[0][0].ToString()); if (current_count > 1) { current_count--; string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, user.User_id); DataBaseEvents.ExecuteNonQuery(query_update, data_source); } else { string query_delete = string.Format("Delete From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, user.User_id); DataBaseEvents.ExecuteNonQuery(query_delete, data_source); } detail.Dgw_users.DataSource = Book.Show_All_Books(user); detail.Tb_6.Text = user.Book_count.ToString(); } }
// Reads Authors, Publishers, Categories, Shelves from Database -- NEED TO CHANGE!!!! private void Fill_Comboboxes() { DataTable dt; string query = ""; int i; int rows_count; query = string.Format("Select {0}.NAME From {0}", "Authors"); dt = DataBaseEvents.ExecuteQuery(query, data_source); rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } for (i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); cb_author.Items.Add(item); } cb_author.Items.Add("Add new Author"); query = string.Format("Select {0}.NAME From {0}", "Publishers"); dt = DataBaseEvents.ExecuteQuery(query, data_source); rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } for (i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); cb_publisher.Items.Add(item); } cb_publisher.Items.Add("Add new Publisher"); query = string.Format("Select {0}.NAME From {0}", "Categories"); dt = DataBaseEvents.ExecuteQuery(query, data_source); rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } for (i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); cb_category.Items.Add(item); } cb_category.Items.Add("Add new Category"); query = string.Format("Select {0}.NAME From {0}", "Shelves"); dt = DataBaseEvents.ExecuteQuery(query, data_source); rows_count = dt.Rows.Count; if (rows_count <= 0) { return; } for (i = 0; i < rows_count; i++) { string item = dt.Rows[i][0].ToString(); cb_shelf.Items.Add(item); } }
public override void Revert_Changes(Book book, User user) { if (this.mode == MODE.GIVE) { book.Count++; book.Change_Count(); string query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.User_id); DataTable dt = DataBaseEvents.ExecuteQuery(query_select, data_source); if (dt.Rows.Count <= 0) { return; } int current_count = int.Parse(dt.Rows[0][0].ToString()); if (current_count > 1) { current_count--; string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, this.user_id); DataBaseEvents.ExecuteNonQuery(query_update, data_source); } else { string query_delete = string.Format("Delete From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.user_id); DataBaseEvents.ExecuteNonQuery(query_delete, data_source); } // Popularity Author aut = main_page.Main_author_list.Find_Author_By_ID(book.Author_id); Category ctg = main_page.Main_category_list.Find_Category_By_ID(book.Category_id); book.Popularity_score -= 5; aut.Popularity_score -= 5; ctg.Popularity_score -= 5; book.Change_Popularity_Score(); aut.Change_Popularity_Score(); ctg.Change_Popularity_Score(); } else { book.Count--; book.Change_Count(); string query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.User_id); DataTable dt = DataBaseEvents.ExecuteQuery(query_select, data_source); if (dt.Rows.Count <= 0) { string query_delete = string.Format("Insert Into Book_User(BOOK_ID, USER_ID, COUNT) Values({0},{1},{2})", book.Book_id, this.user_id, 1); DataBaseEvents.ExecuteNonQuery(query_delete, data_source); } else { int current_count = int.Parse(dt.Rows[0][0].ToString()); if (current_count > 0) { current_count++; string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, this.user_id); DataBaseEvents.ExecuteNonQuery(query_update, data_source); } } } }
protected DataBaseEventListenerHost(DataBaseEvents eventName) { this.eventName = eventName; }