Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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();
        }
        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();
        }
        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();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
            }
        }
Esempio n. 8
0
        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();
            }
        }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (requirments.All(x => x))
            {
                User user = new User();
                user.Name     = txtName.Text;
                user.Surname  = txtSurname.Text;
                user.DOB      = dtpDOB.Value;
                user.Email    = txtEmail.Text;
                user.Password = txtPassword.Text;
                user.IsAdmin  = false;

                _context.Users.InsertOnSubmit(user);

                _context.SubmitChanges();
            }
            else
            {
                MessageBox.Show("Please fill in the required Sections");
            }
        }
Esempio n. 11
0
        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");
            }
        }
Esempio n. 12
0
        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");
            }
        }
Esempio n. 13
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     _context.SubmitChanges();
 }
Esempio n. 14
0
        public void deleteEmploye(Pracownicy employe)
        {
            var employes = (from p in dc.Pracownicies
                            where p.nr_pesel == employe.nr_pesel
                            select p).First();

            dc.Pracownicies.DeleteOnSubmit(employes);
            dc.SubmitChanges();
        }
        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();
            }
        }
Esempio n. 16
0
        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();
        }