static void Main(string[] args) { string connectString = System.Configuration.ConfigurationManager.ConnectionStrings["LinqToSQLDBConnectionString"].ToString(); LinqToSQLDataContext db = new LinqToSQLDataContext(connectString); //Create new Employee Employee newEmployee = new Employee(); newEmployee.Name = "Michael"; newEmployee.Email = "*****@*****.**"; newEmployee.ContactNo = "343434343"; newEmployee.DepartmentId = 3; newEmployee.Address = "Michael - USA"; //Add new Employee to database db.Employees.InsertOnSubmit(newEmployee); //Save changes to Database. db.SubmitChanges(); //Get new Inserted Employee Employee insertedEmployee = db.Employees.FirstOrDefault(e ⇒e.Name.Equals("Michael")); Console.WriteLine("Employee Id = {0} , Name = {1}, Email = {2}, ContactNo = {3}, Address = {4}", insertedEmployee.EmployeeId, insertedEmployee.Name, insertedEmployee.Email, insertedEmployee.ContactNo, insertedEmployee.Address); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); }
private void DeleteUser(string selectedUser) { try { var db = new LinqToSQLDataContext(con); var selectUser = from q in db.tbl_Users where q.Name == selectedUser select q; foreach (var item in selectUser) { db.tbl_Users.DeleteOnSubmit(item); } db.SubmitChanges(); ResetValues(); } catch { System.Windows.MessageBox.Show("Something went wrong while Deleting User"); } }
private void btnEditUser_Click(object sender, RoutedEventArgs e) { if (lvUsers.SelectedItem != null) { saveType = "Edit"; LoadRights(); gbAddEditUsers.Visibility = Visibility.Visible; btnNewUser.IsEnabled = false; btnEditUser.IsEnabled = false; btnDeleteUser.IsEnabled = false; btnSaveUser.IsEnabled = true; btnCancelUser.IsEnabled = true; var db = new LinqToSQLDataContext(con); var selectUser = (from q in db.tbl_Users where q.Name == lvUsers.SelectedItem.ToString().Split(',')[0].Remove(0, 6) select q).SingleOrDefault(); tbOperatortag.Text = selectUser.Operatortag; tbName.Text = selectUser.Name; cbRights.SelectedItem = selectUser.Rights; checkActive.IsChecked = selectUser.Active; tbCardcode.Text = selectUser.CardCode; } else { System.Windows.MessageBox.Show("Select a User First"); } }
static void Main(string[] args) { string connectString = System.Configuration.ConfigurationManager.ConnectionStrings["LinqToSQLDBConnectionString"].ToString(); LinqToSQLDataContext db = newLinqToSQLDataContext(connectString); //Get Employee to Delete Employee deleteEmployee = db.Employees.FirstOrDefault(e ⇒e.Name.Equals("George Michael")); //Delete Employee db.Employees.DeleteOnSubmit(deleteEmployee); //Save changes to Database. db.SubmitChanges(); //Get All Employee from Database var employeeList = db.Employees; foreach (Employee employee in employeeList) { Console.WriteLine("Employee Id = {0} , Name = {1}, Email = {2}, ContactNo = {3}", employee.EmployeeId, employee.Name, employee.Email, employee.ContactNo); } Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); }
static void Main(string[] args) { string connectString = System.Configuration.ConfigurationManager.ConnectionStrings["LinqToSQLDBConnectionString"].ToString(); LinqToSQLDataContext db = new LinqToSQLDataContext(connectString); //Get Employee for update Employee employee = db.Employees.FirstOrDefault(e => e.Name.Equals("Michael")); employee.Name = "George Michael"; employee.Email = "*****@*****.**"; employee.ContactNo = "99999999"; employee.DepartmentId = 2; employee.Address = "Michael George - UK"; //Save changes to Database. db.SubmitChanges(); //Get Updated Employee Employee updatedEmployee = db.Employees.FirstOrDefault(e ⇒e.Name.Equals("George Michael")); Console.WriteLine("Employee Id = {0} , Name = {1}, Email = {2}, ContactNo = {3}, Address = {4}", updatedEmployee.EmployeeId, updatedEmployee.Name, updatedEmployee.Email, updatedEmployee.ContactNo, updatedEmployee.Address); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); }
public ViewUserProfiles() { InitializeComponent(); con = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\keese_000\Desktop\AFSTUDEER STAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\KT4\REDO\Herkansing KT4\Herkansing-KT4\Sewco\UsermanagementDB.mdf;Integrated Security=True"; db = new LinqToSQLDataContext(con); LoadProfiles(); }
public void UpdateRecord(int ID, string Name, string Dept) { LinqToSQLDataContext LTDT = new LinqToSQLDataContext(); LINQTOSQL0 L0 = (from item in LTDT.LINQTOSQL0s where item.ID == ID select item).FirstOrDefault(); L0.NAME = Name; L0.DEPARTMENT = Dept; LTDT.SubmitChanges(); }
public void InsertRecord(string Name, string Dept) { LinqToSQLDataContext LTDT = new LinqToSQLDataContext(); LINQTOSQL0 L0 = new LINQTOSQL0 { NAME = Name, DEPARTMENT = Dept }; LTDT.LINQTOSQL0s.InsertOnSubmit(L0); LTDT.SubmitChanges(); }
private void cbSearch_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!isDeleting) //failsafe { db = new LinqToSQLDataContext(con); var selectProfile = from q in db.tbl_UserProfiles where q.Userprofile == cbSearchProfiles.SelectedItem.ToString() select q; var selectUsers = (from q in db.tbl_Users where q.Rights == cbSearchProfiles.SelectedItem.ToString() select new { Name = q.Name, Operatortag = q.Operatortag, Active = q.Active, Cardcode = q.CardCode }).ToList(); lvUsers.Items.Clear(); foreach (var item in selectUsers) { lvUsers.Items.Add(String.Format("Name: {0}, Operatortag: {1}, \nActive: {2}, Cardcode: None Assigned\n", item.Name, item.Operatortag, item.Active.ToString())); } foreach (var q in selectProfile) { tbUserProfile.Text = q.Userprofile; checkProductions.IsChecked = q.Productions; checkMaintenance.IsChecked = q.Maintenance; checkProductDef.IsChecked = q.Products; checkUsers.IsChecked = q.Users; checkMachineConfig.IsChecked = q.MachineConfig; checkReprint.IsChecked = q.Reprint; checkReset.IsChecked = q.Reset; checkFind.IsChecked = q.Find; checkDesktop.IsChecked = q.Desktop; checkMaterials.IsChecked = q.Materials; checkProductProfile.IsChecked = q.ProductProfile; checkLabelEditor.IsChecked = q.LabelEditor; checkBobbinMonitor.IsChecked = q.BobbinMonitor; checkBobbinTracing.IsChecked = q.BobbinTracer; } } else { isDeleting = false; //Done deleting the Profile } }
public void DeleteRecord(int ID) { LinqToSQLDataContext LTDT = new LinqToSQLDataContext(); LINQTOSQL0 L0; if (ID != 0) { L0 = (from item in LTDT.LINQTOSQL0s where item.ID == ID select item).FirstOrDefault(); LTDT.LINQTOSQL0s.DeleteOnSubmit(L0); } else { IEnumerable <LINQTOSQL0> Data = from item in LTDT.LINQTOSQL0s where item.ID != 0 select item; LTDT.LINQTOSQL0s.DeleteAllOnSubmit(Data); } LTDT.SubmitChanges(); }
private bool databaseConnectionIsValid() // Check if there is a valid database connection. { using (var checkConnection = new LinqToSQLDataContext()) { try { checkConnection.Connection.Open(); // Open connection, if not possible, it will generate an exception. checkConnection.Connection.Close(); return(true); } catch (Exception ex) { MessageBox.Show(clLanguages.getName("__NoDatabaseConnection")); return(false); } } }
public void setInputFinancialFilesBatch(string userName, string status, string errorDescription) { LinqToSQLDataContext db = new LinqToSQLDataContext(); //Create new InputFinancialFile Object InputFinancialFilesBatch newFileBatch = new InputFinancialFilesBatch(); newFileBatch.CreationDateTime = getCreationDateTime(); newFileBatch.UserName = userName; newFileBatch.Status = status; newFileBatch.ErrorDescription = errorDescription; //Add new Employee to database db.InputFinancialFilesBatches.InsertOnSubmit(newFileBatch); //Save changes to Database. db.SubmitChanges(); }
private void EditUser(string selectedUser) { bool result = true; try { var db = new LinqToSQLDataContext(con); var selectTag = from q in db.tbl_Users where q.Operatortag == tbOperatortag.Text select q; var selectUsername = (from q in db.tbl_Users where q.Name == selectedUser select q).SingleOrDefault(); if (selectTag.Count() > 0) { System.Windows.MessageBox.Show("This Tag is already Taken"); result = false; } if (result) { selectUsername.Name = tbName.Text; selectUsername.Operatortag = tbOperatortag.Text; selectUsername.Rights = cbRights.Text; selectUsername.Active = checkActive.IsChecked.Value; db.SubmitChanges(); ResetValues(); result = true; } } catch { System.Windows.MessageBox.Show("Something went wrong While Updating this user"); result = false; } finally { LoadUsers(); } }
private void NewUser() { bool result = true; try { var db = new LinqToSQLDataContext(con); var selectTag = from q in db.tbl_Users where q.Operatortag == tbOperatortag.Text select q; if (selectTag.Count() > 0) { System.Windows.MessageBox.Show("This Tag is already Taken"); result = false; } if (result) { tbl_User user = new tbl_User { Name = tbName.Text, Rights = cbRights.Text, Active = checkActive.IsChecked.Value, Operatortag = tbOperatortag.Text, CardCode = tbCardcode.Text }; db.tbl_Users.InsertOnSubmit(user); db.SubmitChanges(); result = true; } } catch { System.Windows.MessageBox.Show("Something went wrong While Adding this user"); result = false; } finally { ResetValues(); } }
static void Main(string[] args) { //int[] scores = new int[] { 97, 92, 81, 60}; ////define a query expression //var scoreQuery = from score in scores where score > 80 select score; //foreach(int i in scoreQuery) //{ // Console.WriteLine(i + " "); //} //Console.WriteLine("Hello World!"); string connectString = System.Configuration.ConfigurationManager.ConnectionStrings["LinqToSQLDBConnectionString"].ToString(); LinqToSQLDataContext db = new LinqToSQLDataContext(connectString); //Create new Employee Employee newEmployee = new Employee(); newEmployee.Name = "Michael"; newEmployee.Email = "*****@*****.**"; newEmployee.ContactNo = "343434343"; newEmployee.DepartmentId = 3; newEmployee.Address = "Michael - USA"; //Add new Employee to database db.Employees.InsertOnSubmit(newEmployee); //Save changes to Database. db.SubmitChanges(); //Get new Inserted Employee Employee insertedEmployee = db.Employees.FirstOrDefault(e ⇒e.Name.Equals("Michael")); Console.WriteLine("Employee Id = {0} , Name = {1}, Email = {2}, ContactNo = {3}, Address = {4}", insertedEmployee.EmployeeId, insertedEmployee.Name, insertedEmployee.Email, insertedEmployee.ContactNo, insertedEmployee.Address); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); }
private void LoadRights() { try { cbRights.Items.Clear(); var db = new LinqToSQLDataContext(con); var selectProfile = from q in db.tbl_UserProfiles select q.Userprofile; foreach (var item in selectProfile) { cbRights.Items.Add(item); } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString(), "Something went wrong while loading User Profiles to Combobox"); } }
private void LoadUsers() { lvUsers.Items.Clear(); try { var tempDB = new LinqToSQLDataContext(con); var query = (from q in tempDB.tbl_Users select new { Name = q.Name, Rights = q.Rights, Operatortag = q.Operatortag, Active = q.Active, Cardcode = q.CardCode }).ToList(); foreach (var item in query) { lvUsers.Items.Add(String.Format("Name: {0}, Rights: {1}, \nOperatortag: {2}, Active: {3}, \nCardcode: None Assigned\n", item.Name, item.Rights, item.Operatortag, item.Active.ToString())); } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString(), "Something went wrong while Loading users into the Listview"); } }
private void DeleteProfile(string selectedProfile) { try { var db = new LinqToSQLDataContext(con); var selectProfile = from sp in db.tbl_UserProfiles where sp.Userprofile == selectedProfile select sp; foreach (var item in selectProfile) { db.tbl_UserProfiles.DeleteOnSubmit(item); } db.SubmitChanges(); isDeleting = true; ResetValues(); } catch { System.Windows.MessageBox.Show("Something went wrong while Deleting the Profile"); } }
private void SaveNewProfile() { try { using (LinqToSQLDataContext db = new LinqToSQLDataContext(con)) { tbl_UserProfile tbl = new tbl_UserProfile { Userprofile = tbUserProfile.Text, Productions = checkProductions.IsChecked.Value, Maintenance = checkMaintenance.IsChecked.Value, Products = checkProductDef.IsChecked.Value, Users = checkUsers.IsChecked.Value, MachineConfig = checkMachineConfig.IsChecked.Value, Reprint = checkReprint.IsChecked.Value, Reset = checkReset.IsChecked.Value, Find = checkFind.IsChecked.Value, Desktop = checkDesktop.IsChecked.Value, Materials = checkMaterials.IsChecked.Value, ProductProfile = checkProductProfile.IsChecked.Value, LabelEditor = checkLabelEditor.IsChecked.Value, BobbinMonitor = checkBobbinMonitor.IsChecked.Value, BobbinTracer = checkBobbinTracing.IsChecked.Value }; db.tbl_UserProfiles.InsertOnSubmit(tbl); db.SubmitChanges(); } ResetValues(); } catch (Exception exc) { System.Windows.MessageBox.Show("Something went wrong While Adding this user"); } }
public Manager() { connectionString = getConnectionStringFromFile(connectionStringFilePath); db = new LinqToSQLDataContext(connectionString); }
public static void reloadDatabase() { DBDataClass = new LinqToSQLDataContext(); // Create a instance of the database }
public Queries() { dc = new LinqToSQLDataContext(Properties.Settings.Default.TransportCompanyConnectionString); }
public static void setInputFinancialFile(List <byte[]> files, List <string> filesNames) { LinqToSQLDataContext db = new LinqToSQLDataContext(); int len = files.Count; int headerPart1 = 2; int headerPart2 = 7; int headerPart3 = 8; int trailerpart1 = 2; int trailerpart2 = 7; int trailerpart3 = 17; int trailerpart4 = 2; int trailerpart5 = 17; for (int i = 0; i < len; i++) { //Create new InputFinancialFile Object InputFinancialFile newFile = new InputFinancialFile(); var first = files[i].Take(headerPart1).ToArray(); var second = files[i].Skip(headerPart1).ToArray(); //var str = System.Text.Encoding.Default.GetString(first); //will skip the first 2 byte first = second.Take(headerPart2).ToArray(); second = second.Skip(headerPart2).ToArray(); newFile.FUN = BitConverter.ToInt32(first, 0); first = second.Take(headerPart3).ToArray(); second = second.Skip(headerPart3).ToArray(); newFile.DateTime = BitConverter.ToInt32(first, 0); // the total size - the size of header int bodySkip = files[i].Length - trailerpart1 - trailerpart2 - trailerpart3 - trailerpart4 - trailerpart5; first = files[i].Take(bodySkip).ToArray(); second = files[i].Skip(bodySkip).ToArray(); //will skip the all content first = second.Take(trailerpart1).ToArray(); second = second.Skip(trailerpart1).ToArray(); // will skip the first 2 bytes first = second.Take(trailerpart2).ToArray(); second = second.Skip(trailerpart2).ToArray(); newFile.TotalCreditCount = BitConverter.ToInt32(first, 0); first = second.Take(trailerpart3).ToArray(); second = second.Skip(trailerpart3).ToArray(); newFile.TotalCreditAmount = BitConverter.ToInt32(first, 0); first = second.Take(trailerpart4).ToArray(); second = second.Skip(trailerpart4).ToArray(); newFile.TotalDebitCount = BitConverter.ToInt16(first, 0); first = second.Take(trailerpart5).ToArray(); second = second.Skip(trailerpart5).ToArray(); newFile.TotalDebitAmount = BitConverter.ToInt32(first, 0); newFile.FileName = filesNames[i]; newFile.PhysicalLocation = ""; // until know //Add new Employee to database db.InputFinancialFiles.InsertOnSubmit(newFile); //Save changes to Database. db.SubmitChanges(); } }
public void setOutputFinancialFile(string filePath) { // Here we will open the merged file and parse it LinqToSQLDataContext db = new LinqToSQLDataContext(); int headerPart1 = 2; int headerPart2 = 7; int headerPart3 = 8; int trailerpart1 = 2; int trailerpart2 = 7; int trailerpart3 = 17; int trailerpart4 = 2; int trailerpart5 = 17; //Create new InputFinancialFile Object OutputFinancialFile outFile = new OutputFinancialFile(); byte[] file = File.ReadAllBytes(filePath).ToArray(); var first = file.Take(headerPart1).ToArray(); var second = file.Skip(headerPart1).ToArray(); //will skip the first 2 byte first = second.Take(headerPart2).ToArray(); second = second.Skip(headerPart2).ToArray(); outFile.FUN = BitConverter.ToInt32(first, 0); first = second.Take(headerPart3).ToArray(); second = second.Skip(headerPart3).ToArray(); outFile.DateTime = BitConverter.ToInt32(first, 0); // the total size - the size of header int bodySkip = file.Length - trailerpart1 - trailerpart2 - trailerpart3 - trailerpart4 - trailerpart5; first = file.Take(bodySkip).ToArray(); second = file.Skip(bodySkip).ToArray(); //will skip the all content first = second.Take(trailerpart1).ToArray(); second = second.Skip(trailerpart1).ToArray(); // will skip the first 2 bytes first = second.Take(trailerpart2).ToArray(); second = second.Skip(trailerpart2).ToArray(); outFile.TotalCreditCount = BitConverter.ToInt32(first, 0); first = second.Take(trailerpart3).ToArray(); second = second.Skip(trailerpart3).ToArray(); outFile.TotalCreditAmount = BitConverter.ToInt32(first, 0); first = second.Take(trailerpart4).ToArray(); second = second.Skip(trailerpart4).ToArray(); outFile.TotalDebitCount = BitConverter.ToInt16(first, 0); first = second.Take(trailerpart5).ToArray(); second = second.Skip(trailerpart5).ToArray(); outFile.TotalDebitAmount = BitConverter.ToInt32(first, 0); outFile.PhysicalDirectory = filePath; //Add new Employee to database db.OutputFinancialFiles.InsertOnSubmit(outFile); //Save changes to Database. db.SubmitChanges(); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { try { var db = new LinqToSQLDataContext(); tbl_User t = null; t = db.tbl_Users.Single(p => p.Operatortag == tbUsername.Text && p.Active == true); if (t != null) { var query = from q in db.tbl_UserProfiles where q.Userprofile == t.Rights select q.Userprofile; foreach (var q in query) { userprofiles.SetRights(q.ToString()); } #region rights if (!userprofiles.xMachineConfig) { btnConfiguration.Visibility = Visibility.Collapsed; } else { btnConfiguration.Visibility = Visibility.Visible; } if (!userprofiles.xProductions) { btnProductions.Visibility = Visibility.Collapsed; } else { btnProductions.Visibility = Visibility.Visible; } if (!userprofiles.xUsers) { btnUserManagement.Visibility = Visibility.Collapsed; } else { btnUserManagement.Visibility = Visibility.Visible; } if (!userprofiles.xFind) { btnStatistics.Visibility = Visibility.Collapsed; } else { btnStatistics.Visibility = Visibility.Visible; } if (!userprofiles.xProducts) { btnDatabase.Visibility = Visibility.Collapsed; } else { btnDatabase.Visibility = Visibility.Visible; } if (!userprofiles.xLabelEditor) { btnLabelEditor.Visibility = Visibility.Collapsed; } else { btnLabelEditor.Visibility = Visibility.Visible; } if (!userprofiles.xDesktop) { btnDesktop.Visibility = Visibility.Collapsed; } else { btnDesktop.Visibility = Visibility.Visible; } #endregion } else { btnConfiguration.Visibility = Visibility.Collapsed; btnDatabase.Visibility = Visibility.Collapsed; btnLabelEditor.Visibility = Visibility.Collapsed; btnProductions.Visibility = Visibility.Collapsed; btnStatistics.Visibility = Visibility.Collapsed; btnUserManagement.Visibility = Visibility.Collapsed; btnDesktop.Visibility = Visibility.Collapsed; MessageBox.Show("User isn't active"); } } catch { btnConfiguration.Visibility = Visibility.Collapsed; btnDatabase.Visibility = Visibility.Collapsed; btnLabelEditor.Visibility = Visibility.Collapsed; btnProductions.Visibility = Visibility.Collapsed; btnStatistics.Visibility = Visibility.Collapsed; btnUserManagement.Visibility = Visibility.Collapsed; btnDesktop.Visibility = Visibility.Collapsed; MessageBox.Show("No User Detected or User isn't active"); } }