Esempio n. 1
0
        private void btAdd_Click(object sender, EventArgs e)
        {
            int    CMND = 0, SDT = 0;
            string HoNV = "", TenNV = "", ChucVu = "", GhiChu = "";

            HoNV   = txtHoNV.Text.Trim();
            TenNV  = txtTenNV.Text.Trim();
            ChucVu = txtChucNV.Text.Trim();
            GhiChu = txtGhiChu.Text.Trim();

            try
            {
                CMND = int.Parse(txtCMNDNV.Text);
                SDT  = int.Parse(txtSDTNV.Text);
            }
            catch (FormatException ex)
            {
                MessageBox.Show("CMND hoặc SDT chưa nhập hoặc không hợp lệ, nếu thêm thành công mặc định giá trị này bằng 0");
            }

            Employee emp = new Employee(HoNV, TenNV, ChucVu, CMND, SDT, GhiChu);

            try
            {
                int i = new EmployeeBUS().Add(emp);
                switch (i)
                {
                case -1:
                    MessageBox.Show("Lỗi, không thể thêm dữ liệu");
                    break;

                case -2:
                    MessageBox.Show("Phải nhập đầy đủ họ, tên và chức vụ");
                    break;

                default:
                    TaiKhoan tk = new TaiKhoan();
                    tk.MaNV    = i;
                    tk.MatKhau = i.ToString();
                    db.TaiKhoans.InsertOnSubmit(tk);
                    db.SubmitChanges();
                    MessageBox.Show("Đã thêm một nhân viên ở mã " + i);
                    break;
                }
                LoadData();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
                //throw;
            }
        }
Esempio n. 2
0
        private void btAdd_Click(object sender, EventArgs e)
        {
            List <ChiTietPhong> list = db.ChiTietPhongs.Where(c => c.MaPhong == int.Parse(cbbMaPhong.Text)).ToList();
            bool available           = false;

            foreach (ChiTietPhong item in list)
            {
                if (item.TrangThaiPhong == true)
                {
                    available = true;
                }
            }
            if (available == true)
            {
                MessageBox.Show("Phòng đang bận");
            }
            else
            {
                try
                {
                    if (dtNgayDatPhong.Value > dtNgayNhanPhong.Value)
                    {
                        MessageBox.Show("Ngày đặt không lớn hơn ngày nhận phòng");
                    }
                    else
                    {
                        ChiTietPhong ct = new ChiTietPhong();
                        ct.MaNV           = int.Parse(txtMaNV.Text);
                        ct.MaKH           = int.Parse(cbbMaKH.Text);
                        ct.MaPhong        = int.Parse(cbbMaPhong.Text);
                        ct.NgayDatPhong   = dtNgayDatPhong.Value;
                        ct.NgayNhanPhong  = dtNgayNhanPhong.Value;
                        ct.NgayTraPhong   = new DateTime(8888, 12, 30);
                        ct.LoaiHinhThue   = txtLoaiHinhThue.Text;
                        ct.ThanhTien      = 0;
                        ct.GhiChu         = txtGhiChu.Text;
                        ct.TrangThaiPhong = true;
                        db.ChiTietPhongs.InsertOnSubmit(ct);
                        db.SubmitChanges();
                        LoadData();
                        MessageBox.Show("Thêm thành công");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 3
0
        public void EditAccount(string fullName,
                                string address,
                                string email,
                                string pass,
                                string phone,
                                int department,
                                int role)
        {
            var query = from employeeUpdate in db.Employees where employeeUpdate.FullName == fullName select employeeUpdate;

            foreach (Employee employee in query)
            {
                employee.EAddress     = address;
                employee.Email        = email;
                employee.Password     = pass;
                employee.Phone        = phone;
                employee.DepartmentID = department;
                employee.RoleID       = role;
            }
            try
            {
                db.SubmitChanges();
                MessageBox.Show("Data Updated");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 4
0
 private void btAdd_Click(object sender, EventArgs e)
 {
     try
     {
         Phong p = new Phong();
         p.MaPhong  = int.Parse(txtMaPhong.Text);
         p.SoGiuong = int.Parse(txtSoGiuong.Text);
         p.GhiChu   = txtGhiChu.Text;
         db.Phongs.InsertOnSubmit(p);
         db.SubmitChanges();
         MessageBox.Show("Thêm thành công");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     LoadData();
 }
Esempio n. 5
0
        public static void SetWorkerActive(string id)
        {
            Int32           _id    = Int32.Parse(id);
            LINQDataContext db     = new LINQDataContext();
            var             result = (from e in db.PERSONEL
                                      where e.id_personel.Equals(_id)
                                      select e).First();

            result.active = "T";
            db.SubmitChanges();
        }
Esempio n. 6
0
        public static void DeleteCustomer(string id)
        {
            LINQDataContext db = new LINQDataContext();
            //Get customer to Delete
            CLIENT delClient = db.CLIENT.First(e => e.id_client.Equals(id));

            //Delete Employee
            db.CLIENT.DeleteOnSubmit(delClient);

            //Save changes to Database.
            db.SubmitChanges();
        }
Esempio n. 7
0
        public void AddAccount(Employee employee)
        {
            db.Employees.InsertOnSubmit(employee);

            try
            {
                db.SubmitChanges();
                MessageBox.Show("Data Inserted");
            }
            catch (Exception)
            {
                MessageBox.Show("Error");
            }
        }
Esempio n. 8
0
        public static void SaveRequestDetails(Int32 id, string desc, string status, string result, DateTime expDate)
        {
            LINQDataContext db      = new LINQDataContext();
            REQUEST         request = (from e in db.REQUEST
                                       where e.id_request.Equals(id)
                                       select e).SingleOrDefault();

            request.description = desc;
            request.status      = status;
            request.result      = result;
            request.date_reg    = expDate;

            db.SubmitChanges();
        }
Esempio n. 9
0
        public static void DeleteRequestsActivity(Int32 id)
        {
            LINQDataContext db = new LINQDataContext();
            var             activityToDelete = from e in db.ACTIVITY
                                               where e.id_request == id
                                               select e;

            foreach (var activity in activityToDelete)
            {
                db.ACTIVITY.DeleteOnSubmit(activity);
            }

            db.SubmitChanges();
        }
Esempio n. 10
0
        public static void EditActivity(string id, DateTime final, string status, string result)
        {
            //Create new Employee
            LINQDataContext db  = new LINQDataContext();
            ACTIVITY        Act = db.ACTIVITY.First(e => e.id_activity.Equals(id));

            Act.date_fn_cn = final;
            Act.status     = status;
            Act.result     = result;

            //Edit Activity to database
            db.SubmitChanges();

            return;
        }
Esempio n. 11
0
        public static void DeleteCurrentRequest()
        {
            LINQDataContext db       = new LINQDataContext();
            var             number   = GetRequestId();
            var             requests = from e in db.REQUEST
                                       where e.id_request.Equals(number)
                                       select e;

            foreach (var request in requests)
            {
                db.REQUEST.DeleteOnSubmit(request);
            }

            db.SubmitChanges();
        }
Esempio n. 12
0
        public static void AddActivity(Int32 id, Int32 sn, string ad, string dc, DateTime regDate, DateTime exDate)
        {
            LINQDataContext db       = new LINQDataContext();
            ACTIVITY        activity = new ACTIVITY();

            activity.id_request  = id;
            activity.sequence_nb = sn;
            activity.act_dict    = ad;
            activity.description = dc;
            activity.date_reg    = regDate;
            activity.date_fn_cn  = exDate;
            activity.status      = "ACT";

            db.ACTIVITY.InsertOnSubmit(activity);
            db.SubmitChanges();
        }
Esempio n. 13
0
        public static void EditCustomer(string id, string name, string fname, string lname, string tel)
        {
            //Edit
            LINQDataContext db        = new LINQDataContext();
            CLIENT          newClient = db.CLIENT.First(e => e.id_client.Equals(id));

            newClient.name       = name;
            newClient.first_name = fname;
            newClient.last_name  = lname;
            newClient.tel        = tel;


            //Save changes to Database.
            db.SubmitChanges();
            return;
        }
Esempio n. 14
0
        public static void EditPersonel(string id, string fname, string lname, string password, string active)
        {
            //Create new Employee
            LINQDataContext db       = new LINQDataContext();
            PERSONEL        Personel = db.PERSONEL.First(e => e.id_personel.Equals(id));

            Personel.first_name = fname;
            Personel.last_name  = lname;
            Personel.password   = password;
            Personel.active     = active;

            //Edit Employee to database
            db.SubmitChanges();

            return;
        }
Esempio n. 15
0
        public static void AddVehicle(string nr_object, string name, string obj_type, int id_client)
        {
            //Create new Employee
            LINQDataContext db         = new LINQDataContext();
            OBJECT          newVehicle = new OBJECT();

            newVehicle.nr_object = nr_object;
            newVehicle.name      = name;
            newVehicle.obj_type  = obj_type;
            newVehicle.id_client = id_client;

            //Add new Customer to database
            db.OBJECT.InsertOnSubmit(newVehicle);

            //Save changes to Database.
            db.SubmitChanges();
        }
Esempio n. 16
0
        public static void CreateEmptyRequest()
        {
            LINQDataContext db      = new LINQDataContext();
            REQUEST         request = new REQUEST();

            request.id_request  = GetRequestId();
            request.description = "";
            request.status      = "";
            request.result      = "";
            request.date_reg    = DateTime.Today;
            request.date_fn_cn  = DateTime.Today;
            request.id_personel = 1;
            request.nr_object   = GetDefaultVehicle(); // Alles klar

            db.REQUEST.InsertOnSubmit(request);
            db.SubmitChanges();
        }
Esempio n. 17
0
        public static void FulfillRequestInformation(Int32 idre, string desc, string stat, string resu, DateTime datr, DateTime datf, Int32 idpe, string nrob)
        {
            LINQDataContext db      = new LINQDataContext();
            REQUEST         request = (from e in db.REQUEST
                                       where e.id_request.Equals(idre)
                                       select e).SingleOrDefault();

            request.description = desc;
            request.status      = stat;
            request.result      = resu;
            request.date_reg    = datr;
            request.date_fn_cn  = datf;
            request.id_personel = idpe;
            request.nr_object   = nrob;

            db.SubmitChanges();
        }
Esempio n. 18
0
        public static void AddCustomer(string name, string fname, string lname, string tel)
        {
            //Create new Employee
            LINQDataContext db        = new LINQDataContext();
            CLIENT          newClient = new CLIENT();

            newClient.name       = name;
            newClient.first_name = fname;
            newClient.last_name  = lname;
            newClient.tel        = tel;

            //Add new Customer to database
            db.CLIENT.InsertOnSubmit(newClient);

            //Save changes to Database.
            db.SubmitChanges();
            return;
        }
Esempio n. 19
0
        public static void AddObject(string nr, string name, Int32 id, string type)
        {
            //Create new Employee
            LINQDataContext db        = new LINQDataContext();
            OBJECT          newObject = new OBJECT();

            newObject.nr_object = nr;
            newObject.name      = name;
            newObject.id_client = id;
            newObject.obj_type  = type;

            //Add new Customer to database
            db.OBJECT.InsertOnSubmit(newObject);

            //Save changes to Database.
            db.SubmitChanges();
            return;
        }
Esempio n. 20
0
 private void btXacNhan_Click(object sender, EventArgs e)
 {
     if (db.TaiKhoans.Where(c => c.MaNV == MaNV).FirstOrDefault().MatKhau != txtMatKhauCu.Text)
     {
         MessageBox.Show("Sai mật khẩu, yêu cầu nhập lại");
     }
     else if (txtMatKhauMoi.Text != txtXacNhanMatKhau.Text)
     {
         MessageBox.Show("Mật khẩu mới không khớp với mật khẩu xác nhận");
     }
     else
     {
         TaiKhoan tk = db.TaiKhoans.Where(c => c.MaNV == MaNV).FirstOrDefault();
         tk.MatKhau = txtMatKhauMoi.Text;
         db.SubmitChanges();
         MessageBox.Show("Đổi mật khẩu thành công");
         this.Close();
     }
 }
Esempio n. 21
0
        public void DeleteAccount(string fullName)
        {
            var query = from deleteEmployee in db.Employees where deleteEmployee.FullName == fullName select deleteEmployee;

            foreach (var command in query)
            {
                db.Employees.DeleteOnSubmit(command);
            }

            try
            {
                db.SubmitChanges();
                MessageBox.Show("Data Deleted");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 22
0
        public static void AddPersonel(string fname, string lname, string login, string role, string password, string active)
        {
            //Create new Employee
            LINQDataContext db          = new LINQDataContext();
            PERSONEL        newPersonel = new PERSONEL();

            newPersonel.first_name = fname;
            newPersonel.last_name  = lname;
            newPersonel.login      = login;
            newPersonel.password   = password;
            newPersonel.role       = role;
            newPersonel.active     = active;

            //Add new Employee to database
            db.PERSONEL.InsertOnSubmit(newPersonel);

            //Save changes to Database.
            db.SubmitChanges();
            return;
        }
Esempio n. 23
0
        public static void UpdateActivity(Int32 id, Int32 sn, string dc, string wo, string status, DateTime dreg, DateTime dfc, string act)
        {
            //Int32 _idPersonel = 0;
            LINQDataContext db     = new LINQDataContext();
            var             result = (from e in db.ACTIVITY
                                      where e.id_activity == id && e.sequence_nb == sn
                                      select e).First();
            var result1 = (from e in db.PERSONEL
                           where e.last_name.ToString().Equals(wo)
                           select e).First();

            result.id_personel = result1.id_personel;
            result.description = dc;
            result.status      = status;
            result.date_reg    = dreg;
            result.date_fn_cn  = dfc;
            result.act_dict    = act;


            db.SubmitChanges();
        }
        private void GroupsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvGroup[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvGroup.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvGroup.rows in db.Groups
                    //
                    int ID_No = 0;
                    int.TryParse(dgvGroup[0, rowCounter].Value.ToString(), out ID_No);
                    // Define the query expression.
                    var query = (from groups in db.Groups
                                 where groups.ID == ID_No
                                 select groups).SingleOrDefault();

                    if (query != null) // EDIT
                    {
                        try
                        {
                            int year = 0;
                            query.Semester_Entry_Year = (int.TryParse(dgvGroup[1, rowCounter].Value.ToString(), out year)) ? year : 0;

                            query.Semester_Entry_FS = (dgvGroup[2, rowCounter].Value != null) ?
                                ((dgvGroup[2, rowCounter].Value.ToString() == colSemesterEntry.Items[0].ToString()) ? true : false) : true;
                            //
                            // find branch id in string ComboBox Select Academic field
                            //
                            int Branch_ID = 0;
                            string bIND = (dgvGroup[3, rowCounter].Value != null) ? dgvGroup[3, rowCounter].Value.ToString() : "";
                            if (bIND == "")
                            {
                                throw new Exception("Pleas Select a Branch for the Group by Group's Id (" + ID_No + ")");
                            }
                            string branch_id = "";
                            foreach (char ch in bIND.ToCharArray())
                            {
                                if (char.IsDigit(ch))
                                {
                                    branch_id += ch.ToString();
                                }
                                else
                                {
                                    Branch_ID = int.Parse(branch_id);
                                    break;
                                }
                            }

                            query.Branch_Selection = Branch_ID;
                            //
                            int size = 0;
                            query.Size_No = (dgvGroup[4, rowCounter].Value != null) ? (int.TryParse(dgvGroup[4, rowCounter].Value.ToString(), out size)) ? size : 0 : 0;

                            db.SubmitChanges();
                        }
                        catch { }
                    }
                    else
                    {
                        //
                        // find branch id in string ComboBox Select Academic field
                        //
                        int Branch_ID = 0;
                        string bIND = (dgvGroup[3, rowCounter].Value != null) ? dgvGroup[3, rowCounter].Value.ToString() : "";
                        if (bIND == "")
                        {
                            throw new Exception("Pleas Select a Branch for the Group by Group's Id (" + ID_No + ")");
                        }
                        string branch_id = "";
                        foreach (char ch in bIND.ToCharArray())
                        {
                            if (char.IsDigit(ch))
                            {
                                branch_id += ch.ToString();
                            }
                            else
                            {
                                Branch_ID = int.Parse(branch_id);
                                break;
                            }
                        }
                        //
                        int size = 0;
                        int year = 0;
                        db.GroupsSave(ID_No, (int.TryParse(dgvGroup[1, rowCounter].Value.ToString(), out year)) ? year : 0,
                            (dgvGroup[2, rowCounter].Value != null) ?
                            ((dgvGroup[2, rowCounter].Value.ToString() == colSemesterEntry.Items[0].ToString()) ? true : false) : true,
                             Branch_ID,
                            (dgvGroup[4, rowCounter].Value != null) ? (int.TryParse(dgvGroup[4, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }
Esempio n. 25
0
        private void GroupsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvGroup[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvGroup.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvGroup.rows in db.Groups
                    //
                    int ID_No = 0;
                    int.TryParse(dgvGroup[0, rowCounter].Value.ToString(), out ID_No);
                    // Define the query expression.
                    var query = (from groups in db.Groups
                                 where groups.ID == ID_No
                                 select groups).SingleOrDefault();

                    if (query != null) // EDIT
                    {
                        try
                        {
                            int year = 0;
                            query.Semester_Entry_Year = (int.TryParse(dgvGroup[1, rowCounter].Value.ToString(), out year)) ? year : 0;

                            query.Semester_Entry_FS = (dgvGroup[2, rowCounter].Value != null) ?
                                                      ((dgvGroup[2, rowCounter].Value.ToString() == colSemesterEntry.Items[0].ToString()) ? true : false) : true;
                            //
                            // find branch id in string ComboBox Select Academic field
                            //
                            int    Branch_ID = 0;
                            string bIND      = (dgvGroup[3, rowCounter].Value != null) ? dgvGroup[3, rowCounter].Value.ToString() : "";
                            if (bIND == "")
                            {
                                throw new Exception("Pleas Select a Branch for the Group by Group's Id (" + ID_No + ")");
                            }
                            string branch_id = "";
                            foreach (char ch in bIND.ToCharArray())
                            {
                                if (char.IsDigit(ch))
                                {
                                    branch_id += ch.ToString();
                                }
                                else
                                {
                                    Branch_ID = int.Parse(branch_id);
                                    break;
                                }
                            }

                            query.Branch_Selection = Branch_ID;
                            //
                            int size = 0;
                            query.Size_No = (dgvGroup[4, rowCounter].Value != null) ? (int.TryParse(dgvGroup[4, rowCounter].Value.ToString(), out size)) ? size : 0 : 0;

                            db.SubmitChanges();
                        }
                        catch { }
                    }
                    else
                    {
                        //
                        // find branch id in string ComboBox Select Academic field
                        //
                        int    Branch_ID = 0;
                        string bIND      = (dgvGroup[3, rowCounter].Value != null) ? dgvGroup[3, rowCounter].Value.ToString() : "";
                        if (bIND == "")
                        {
                            throw new Exception("Pleas Select a Branch for the Group by Group's Id (" + ID_No + ")");
                        }
                        string branch_id = "";
                        foreach (char ch in bIND.ToCharArray())
                        {
                            if (char.IsDigit(ch))
                            {
                                branch_id += ch.ToString();
                            }
                            else
                            {
                                Branch_ID = int.Parse(branch_id);
                                break;
                            }
                        }
                        //
                        int size = 0;
                        int year = 0;
                        db.GroupsSave(ID_No, (int.TryParse(dgvGroup[1, rowCounter].Value.ToString(), out year)) ? year : 0,
                                      (dgvGroup[2, rowCounter].Value != null) ?
                                      ((dgvGroup[2, rowCounter].Value.ToString() == colSemesterEntry.Items[0].ToString()) ? true : false) : true,
                                      Branch_ID,
                                      (dgvGroup[4, rowCounter].Value != null) ? (int.TryParse(dgvGroup[4, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }
Esempio n. 26
0
        public Boolean InsertNew(Object any)
        {
            if (any is Recruiter)
            {
                Recruiter    obj = (Recruiter)any;
                TabRecruiter rec = new TabRecruiter();

                rec.fname        = obj.FirstName;
                rec.lname        = obj.LastName;
                rec.uname        = obj.Username;
                rec.mobile       = obj.MobileNumber;
                rec.email        = obj.EmailAddress;
                rec.address      = obj.Address;
                rec.designation  = obj.Designation;
                rec.organisation = obj.Organisation;
                rec.dob          = obj.DateOfBirth;
                rec.gender       = obj.Gender;

                db.TabRecruiters.InsertOnSubmit(rec);
                db.SubmitChanges();

                if (this.InserLogin(obj))
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            else if (any is Seeker)
            {
                Seeker obj = (Seeker)any;

                TabSeeker seek = new TabSeeker();

                seek.fname   = obj.FirstName;
                seek.lname   = obj.LastName;
                seek.uname   = obj.Username;
                seek.mobile  = obj.MobileNumber;
                seek.email   = obj.EmailAddress;
                seek.address = obj.Address;
                seek.dob     = obj.DateOfBirth;
                seek.gender  = obj.Gender;

                db.TabSeekers.InsertOnSubmit(seek);
                db.SubmitChanges();

                foreach (var i in obj.skills)
                {
                    db.TabSkills.InsertOnSubmit(new TabSkill()
                    {
                        uname = obj.Username + obj.skills.IndexOf(i), skill = i, user = obj.Username
                    });
                }

                db.SubmitChanges();

                if (this.InserLogin(obj))
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }


            return(false);
        }