public static MyDoublyLinkedList <Customer> Load() { MyDoublyLinkedList <Customer> customersTable = new MyDoublyLinkedList <Customer>(); string location = "Northwind.mdb"; string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; data source=" + location; string sSql = "select * from Customers"; OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand myCmd = new OleDbCommand(sSql, con); OleDbDataAdapter adapter = new OleDbDataAdapter(); //יצירת אוביקט adapter.SelectCommand = myCmd; // command קישור ל DataSet dataset = new DataSet(); // יצירת טבלה בזיכרון adapter.Fill(dataset, "tblusers"); //מילוי הטבלה ומתן שם dataset.Tables["tblusers"].PrimaryKey = new DataColumn[] { dataset.Tables["tblusers"].Columns["UserID"] }; foreach (DataRow row in dataset.Tables[0].Rows) { customersTable.Insert(new Customer(row[0].ToString(), row[1].ToString(), row[2].ToString(), row[9].ToString())); } return(customersTable); }
/// <summary> /// Update Customers by given list of Customers. /// </summary> /// <param name="customersTable">the table is MyDoublyLinkedList</param> public void Update(MyDoublyLinkedList <Customer> customersTable) { foreach (var customer in customersTable) { UpdateByID(customer); } }
//Select Customers only by single field //and return them as MyDB private MyDB SelectBy(string field, CustomerField selectBy) { MyDoublyLinkedList <Link <Customer> > newList = new MyDoublyLinkedList <Link <Customer> >(); MyDB result = new MyDB(); if (selectBy == CustomerField.CustomerID && field != "") { if (dictCustomerID.ContainsKey(field)) { var line = dictCustomerID[field].Data; result.Insert(line); return(result); } } if (selectBy == CustomerField.CompanyName && field != "") { if (dictCompanyName.ContainsKey(field)) { foreach (var link in dictCompanyName[field]) { var line = link.Data; result.Insert(line); } } } if (selectBy == CustomerField.ContactName && field != "") { if (dictContactName.ContainsKey(field)) { foreach (var link in dictContactName[field]) { var line = link.Data; result.Insert(line); } } } if (selectBy == CustomerField.Phone && field != "") { if (dictPhone.ContainsKey(field)) { foreach (var link in dictPhone[field]) { var line = link.Data; result.Insert(line); } } } return(result); }
/// <summary> /// Insert Customers as MyDoublyLinkedList /// and return true if some of customers ID were reserved /// </summary> /// <param name="customersTable">MyDoublyLinkedList<Customer></param> /// <returns></returns> public bool Insert(MyDoublyLinkedList <Customer> customersTable) { bool reservedID = false; foreach (var customer in customersTable) { if (!dictCustomerID.ContainsKey(customer.CustomerID)) { _customersTable.Insert(customer); AddToDictionaries(_customersTable.Head, CustomerField.All); } else { reservedID = true; } } return(reservedID); }
/// <summary> /// The constructor receive a linked list of customers /// </summary> /// <param name="customersTable"></param> public MyDB(MyDoublyLinkedList <Customer> customersTable) { Insert(customersTable); }