Example #1
0
        public List <DTO_Employee> GetAllEmployees()
        {
            List <DTO_Employee> lst = new List <DTO_Employee>();
            String     commandText  = "Select * From Employees";
            SqlCommand cmd          = new SqlCommand(commandText, conn);

            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                int    id        = Int32.Parse(dr["EmployeeID"].ToString());
                string firstName = dr["FirstName"].ToString();
                string lastName  = dr["LastName"].ToString();
                string country   = dr["Country"].ToString();

                DTO_Employee newDto = new DTO_Employee()
                {
                    IDEmployee = id,
                    FirstName  = firstName,
                    LastName   = lastName,
                    Country    = country
                };

                lst.Add(newDto);
            }
            conn.Close();
            return(lst);
        }
Example #2
0
        public DTO_Employee GetEmployeeByID(int id)
        {
            DTO_Employee result      = new DTO_Employee();
            String       commandText = "Select * From Employees where EmployeeID = " + id;
            SqlCommand   cmd         = new SqlCommand(commandText, conn);

            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                string firstName = dr["FirstName"].ToString();
                string lastName  = dr["LastName"].ToString();
                string country   = dr["Country"].ToString();

                DTO_Employee newDto = new DTO_Employee()
                {
                    IDEmployee = id,
                    FirstName  = firstName,
                    LastName   = lastName,
                    Country    = country
                };

                result = newDto;
            }
            conn.Close();
            return(result);
        }
        private void updateAction()
        {
            bool valid = true;

            valid = Validate(txtEmployeeId, lblId) == false ? false : valid;
            valid = Validate(txtEmployeeId, lblId) == false ? false : valid;
            valid = Validate(txtEmployeeFullName, lblName) == false ? false : valid;
            valid = Validate(txtEmployeeAddress, lblAddress) == false ? false : valid;
            valid = Validate(txtEmployeeEmail, lblEmail) == false ? false : valid;
            valid = Validate(txtEmployeeTel, lblTel) == false ? false : valid;

            if (valid)
            {
                string   id       = txtEmployeeId.Text.Trim();
                string   name     = txtEmployeeFullName.Text.Trim();
                DateTime birthday = DateTime.Parse(dpBirthday.Text);
                bool     gender   = rdGenderMale.Checked;
                string   address  = txtEmployeeAddress.Text.Trim();
                string   email    = txtEmployeeEmail.Text.Trim();
                string   tel      = txtEmployeeTel.Text.Trim();
                int      role     = int.Parse(cbbRoles.SelectedValue.ToString());

                DTO_Employee dtoEmployee = new DTO_Employee(id, name, birthday, gender, address, email, tel, role);
                busEmployee.UpdateEmployee(dtoEmployee);
                loadEmployees();
            }
            else
            {
                MessageBox.Show("vui lòng kiểm tra lại các ô dữ liệu tô màu đỏ");
            }
        }
Example #4
0
        public DTO_Employee getDetail(String username)
        {
            cnn = DataProvider.ConnectData();
            string        sqlQuery   = string.Format("select IdEmployee, Password, NameEmployee, NumberPhoneEmployee, AddressEmployee, sp.Address, SupervisorEmployee, Role, emp.Status from Employee emp, Shops sp where emp.IDShops = sp.IDShops and emp.IdEmployee = '{0}'", username);
            SqlCommand    command    = new SqlCommand(sqlQuery, cnn);
            SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);

            if (dataReader.HasRows)
            {
                if (dataReader.Read())
                {
                    string Username   = dataReader["IdEmployee"].ToString();
                    string Password   = dataReader["Password"].ToString();
                    string Fullname   = dataReader["NameEmployee"].ToString();
                    string role       = dataReader["Role"].ToString();
                    string Shop       = dataReader["Address"].ToString();
                    string Address    = dataReader["AddressEmployee"].ToString();
                    string Supervisor = dataReader["SupervisorEmployee"].ToString();
                    string Phone      = dataReader["NumberPhoneEmployee"].ToString();
                    string Status     = dataReader["Status"].ToString();
                    emp = new DTO_Employee(Username, Password, Fullname, Phone, Address, Shop, Supervisor, role, Status);
                    return(emp);
                }
            }
            cnn.Close();
            return(emp);
        }
        public int Add(DTO_Employee emp)
        {
            List <SqlParameter> paras = new List <SqlParameter>();

            //string sql = " INSERT INTO NhanVien( MaNV, HoNV, TenNV, GioiTinh, SDT, NgaySinh, DiaChiThuongTru, ChucVu)" +
            //    " VALUES (@MaNV, @HoNV, @TenNV, @GioiTinh, @SDT, @NgaySinh, @DiaChiThuongTru, @ChucVu)";

            paras.Add(new SqlParameter("@MaNV", emp.MaNV));
            paras.Add(new SqlParameter("@HoNV", emp.HoNV));
            paras.Add(new SqlParameter("@TenNV", emp.TenNV));
            paras.Add(new SqlParameter("@GioiTinh", emp.GioiTinh));
            paras.Add(new SqlParameter("@SDT", emp.SDT));
            paras.Add(new SqlParameter("@NgaySinh", emp.NgaySinh));
            paras.Add(new SqlParameter("@CMND", emp.CMND));
            paras.Add(new SqlParameter("@DiaChiThuongTru", emp.DiaChiThuongTru));
            paras.Add(new SqlParameter("@ChucVu", emp.ChucVu));

            try
            {
                return(dp.ExcuteNonQuery("sp_ThemNhanVien", System.Data.CommandType.StoredProcedure, paras));
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
Example #6
0
 public Employees CreateEntity(DTO_Employee dto)
 {
     return(new Employees()
     {
         LastName = dto.LastName,
         FirstName = dto.FirstName,
         EmployeeId = dto.EmployeeID
     });
 }
 public fmManager(DTO_Employee emp) : this()
 {
     this.AutoSize      = true;
     this.StartPosition = FormStartPosition.CenterScreen;
     employee           = emp;
     lblFullname.Text   = "Hello " + emp.Fullname;
     loadRevenueByYear();
     loadTop5Revenue();
 }
 public Employee(DTO_Employee employee)
 {
     EmployeeID     = employee.EmployeeID;
     EmployeeTypeID = employee.EmployeeTypeID;
     FirstName      = employee.FirstName;
     LastName       = employee.LastName;
     Suffix         = employee.Suffix;
     Email          = employee.Email;
     CellPhone      = employee.CellPhone;
     Active         = employee.Active;
 }
        private void btndeletenv_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn xoá thật không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                BUS_Employee dl = new BUS_Employee();
                DTO_Employee dt = new DTO_Employee(Convert.ToInt32(txtmanv.Text));
                dl.Delete(dt);
                dgvlistnv.DataSource = GetEmployee();

                MessageBox.Show(" BẠN ĐÃ XÓA NHÂN VIÊN THÀNH CÔNG", " Xác nhận");
            }
        }
        //public override void Validate(string userName, string password)
        //{
        //	try
        //	{
        //		MRNNexus_DAL.MRNNexusTestEntities context = new MRNNexus_DAL.MRNNexusTestEntities();

        //		var outputParameter = new System.Data.Entity.Core.Objects.ObjectParameter("new_identity", typeof(int));
        //		//get user hashed pass using provided username
        //		var result = context.proc_GetUser(userName, outputParameter).Single();
        //		string pass = result.Pass;
        //		//foreach (var e in result)
        //		//{
        //		//	pass = e.Pass;
        //		//}
        //		////

        //		if (!VerifyPassword(password, pass))
        //		{
        //			throw new FaultException("Unkown Username and/or Password");
        //		}

        //	} catch(Exception ex)
        //	{
        //		throw new FaultException("No User with that name.");
        //	}
        //}

        public string CreatePasswordHASH(DTO_Employee token)
        {
            var salt                  = GenerateRandomSalt();
            var iterationCount        = 3;
            var hashValue             = GenerateHashValue(token.LastName + token.CellPhone.Substring(token.CellPhone.Length - 4), salt, iterationCount);
            var iterationCountBtyeArr = BitConverter.GetBytes(iterationCount);
            var valueToSave           = new byte[SaltByteLength + DerivedKeyLength + iterationCountBtyeArr.Length];

            Buffer.BlockCopy(salt, 0, valueToSave, 0, SaltByteLength);
            Buffer.BlockCopy(hashValue, 0, valueToSave, SaltByteLength, DerivedKeyLength);
            Buffer.BlockCopy(iterationCountBtyeArr, 0, valueToSave, salt.Length + hashValue.Length, iterationCountBtyeArr.Length);
            return(Convert.ToBase64String(valueToSave));
        }
Example #11
0
        public DTO_Employee GetEmployeeByID(int id)
        {
            DTO_Employee res       = null;
            var          querylinq = from e in ctx.Employees
                                     where e.EmployeeID == id
                                     select e;

            Data.EF.Employee ef_emp = querylinq.FirstOrDefault();
            if (ef_emp != null)
            {
                res = new DTO_Employee(ef_emp);
            }
            return(res);
        }
        public async Task GetKnockerResponsesByKnockerID(DTO_Employee token)
        {
            try
            {
                var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "GetKnockerResponsesByKnockerID"),
                                                            token);

                response.EnsureSuccessStatusCode();
                KnockerResponsesList = await response.Content.ReadAsAsync <List <DTO_KnockerResponse> >();
            }
            catch (Exception ex)
            {
            }
        }
        public int Delete(DTO_Employee emp)
        {
            List <SqlParameter> paras = new List <SqlParameter>();

            paras.Add(new SqlParameter("@MaNV", emp.MaNV));
            try
            {
                return(dp.ExcuteNonQuery("sp_XoaNhanVien", System.Data.CommandType.StoredProcedure, paras));
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public async Task GetLeadsBySalesPersonID(DTO_Employee token)
        {
            try
            {
                var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "GetLeadsBySalesPersonID"),
                                                            token);

                response.EnsureSuccessStatusCode();
                LeadList = await response.Content.ReadAsAsync <List <DTO_Lead> >();
            }
            catch (Exception ex)
            {
            }
        }
Example #15
0
        public List <DTO_Employee> GetAllEmployees()
        {
            List <DTO_Employee> lst = new List <DTO_Employee>();
            var res = from e in ctx.Employees
                      orderby e.LastName
                      select e;

            foreach (Data.EF.Employee ef_emp in res)
            {
                DTO_Employee dto = new DTO_Employee(ef_emp);
                lst.Add(dto);
            }
            return(lst);
        }
        public async Task GetCalendarDataByEmployeeID(DTO_Employee token)
        {
            try
            {
                var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "GetCalendarDataByEmployeeID"),
                                                            token);

                response.EnsureSuccessStatusCode();
                CalDataList = await response.Content.ReadAsAsync <List <DTO_CalendarData> >();
            }
            catch (Exception ex)
            {
            }
        }
        public async Task AddEmployee(DTO_Employee token)
        {
            try
            {
                var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "AddEmployee"),
                                                            token);

                response.EnsureSuccessStatusCode();
                Employee = await response.Content.ReadAsAsync <DTO_Employee>();
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }
        }
Example #18
0
        public bool addEmployee(DTO_Employee emp)
        {
            string sql = string.Format(" insert into Employee  values( '{0}' , '{1}' , '{2}' ,(select IDShops from Shops  where Address = '{3}' ), '{4}' , '{5}' , '{6}' , '{7}' ,'On') ", emp.Username, emp.Password, emp.Fullname, emp.IDShop, emp.Address, emp.Supervisor, emp.Phone, emp.role);

            cnn = DataProvider.ConnectData();
            SqlCommand command = new SqlCommand(sql, cnn);
            int        row     = command.ExecuteNonQuery();

            cnn.Close();
            if (row > 0)
            {
                return(true);
            }
            return(false);
        }
Example #19
0
 public void DeleteEmployee(DTO_Employee employee)
 {
     try
     {
         SqlCommand command = new SqlCommand("pr_DeleteEmployee", DAL_DBConnect.connection);
         command.CommandType = System.Data.CommandType.StoredProcedure;
         command.Parameters.Add("@Employee_Id", System.Data.SqlDbType.Char, 13).Value = employee.Id;
         command.ExecuteNonQuery();
         command.Parameters.Clear();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message.ToString(), "Notice");
     }
 }
Example #20
0
        public fmBill(DTO_Employee emp, List <DTO_Product> list, DTO_Customer cus, string totalPrice)
        {
            InitializeComponent();
            txtcashier.Text = "Cashier: " + emp.Fullname;
            txtCus.Text     = "Customer: " + cus.cusName;
            String bill = String.Format("{0,-4} {1,-60} {2,-40} {3,-40} {4,-40}\n\n\n", "No.", "Product", "Quantity", "Price", "Amount");

            for (int i = 0; i < list.Count; i++)
            {
                bill += String.Format("{0,-4} {1,-60} {2,-40} {3,-40} {4,-40}\n {5,-1000}\n", (i + 1), list[i].proName, list[i].proQuantity.ToString().Trim(), (list[i].proPrice / list[i].proQuantity), list[i].proPrice, "-" + list[i].discount + "%");
            }
            lblInfoBill.Text = bill;
            lblTotal.Text    = totalPrice;
            lblDate.Text     = "Date: " + DateTime.Today.ToString("d");
        }
 private void btnTimNV_Click(object sender, EventArgs e)
 {
     switch (typeCheck)
     {
     case 1:
     {
         DTO_Employee emp = new DTO_Employee(Convert.ToInt32(txtbTimKiem.Text));
         DataTable    dt  = new DataTable();
         BUS_Employee em  = new BUS_Employee();
         dt = em.SearchByMaNV(emp);
         dgvTimKiem.DataSource = dt;
         break;
     }
     }
 }
Example #22
0
        public bool updateEmployee(DTO_Employee emp)
        {
            string sql = string.Format("update Employee set Password = '******', NameEmployee = '{1}', IDShops = (select IDShops from Shops  where Address = '{2}'), AddressEmployee = '{3}', SupervisorEmployee = '{4}',  NumberPhoneEmployee = '{5}', Role = '{6}', Status = '{7}' where IdEmployee = '{8}' ", emp.Password, emp.Fullname, emp.IDShop, emp.Address, emp.Supervisor, emp.Phone, emp.role, emp.Status, emp.Username);

            cnn = DataProvider.ConnectData();
            SqlCommand command = new SqlCommand(sql, cnn);
            int        row     = command.ExecuteNonQuery();

            cnn.Close();
            if (row > 0)
            {
                return(true);
            }
            return(false);
        }
        public DataTable SearchByChucVu(DTO_Employee emp)
        {
            SqlConnection       cnn   = dp.getConnect();
            List <SqlParameter> paras = new List <SqlParameter>();
            DataTable           dt    = new DataTable();
            SqlCommand          cmd   = new SqlCommand("sp_TimTheoChucVuNhanVien", cnn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ChucVu", emp.ChucVu));
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(dt);
            dp.DisConnect();
            return(dt);
        }
Example #24
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (CheckData() == true)
     {
         DTO_Employee dto_emp = new DTO_Employee(txtEmployeeID.Text, txtName.Text, Birthday.Value.ToShortDateString(), txtGender.Text, txtAddress.Text, txtEmail.Text, txtPhonenumber.Text, txtTitle.Text, long.Parse(txtSalary.Text));
         if (bus_emp.Edit(dto_emp))
         {
             MessageBox.Show("EDIT SUCCESS!", "EDIT", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadData();
         }
         else
         {
             MessageBox.Show("EDIT FAIL!", "EDIT", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        private void dgvView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            index = e.RowIndex;
            try
            {
                if (tabControl2.SelectedIndex == 0)
                {
                    DataGridViewRow selectedRow = dgvView.Rows[index];
                }
                if (tabControl2.SelectedIndex == 1)
                {
                    txtMnQuantityType.ReadOnly = true;
                    DataGridViewRow selectedRow = dgvView.Rows[index];
                    string          quantity    = selectedRow.Cells[3].Value.ToString();
                    txtMnQuantityType.Text = quantity;
                }
                if (tabControl2.SelectedIndex == 2)
                {
                    BUS_Employee    busEmp      = new BUS_Employee();
                    DataGridViewRow selectedRow = dgvView.Rows[index];
                    string          idEmp       = selectedRow.Cells[0].Value.ToString();
                    employee = busEmp.getDetail(idEmp);

                    txtEmpID.Text         = idEmp;
                    txtEmpPass.Text       = employee.Password;
                    txtEmpName.Text       = employee.Fullname;
                    txtEmpPhone.Text      = employee.Phone;
                    txtEmpAddress.Text    = employee.Address;
                    cbEmpShop.Text        = employee.IDShop;
                    txtEmpSupervisor.Text = employee.Supervisor;
                    cbEmpRole.Text        = employee.role;
                    if (employee.Status.Equals("Off"))
                    {
                        rdOn.Checked = false;
                    }
                    else
                    {
                        rdOn.Checked = true;
                    }
                }
            }
            catch
            {
                Clear();
            }
        }
 public int UpdateEmployee(DTO_Employee emp)
 {
     if (emp.MaNV.ToString() == "" || emp.HoNV == "" || emp.TenNV == "" || emp.GioiTinh == "" || emp.SDT == "" || emp.CMND == "" || emp.DiaChiThuongTru == "" || emp.ChucVu == "")
     {
         return(-2);
     }
     if (true)
     {
     }
     try
     {
         return(new DAO_Employee().UpdateEmployee(emp));
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
Example #27
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            BUS_Employee busEmp   = new BUS_Employee();
            string       username = txtLogin.Text;
            string       pass     = txtPass.Text;
            string       check    = chekcLoginForm();

            if (check.Equals(""))
            {
                emp = busEmp.Login(username, pass);
                if (emp != null)
                {
                    if (emp.role.Equals("Cashier"))
                    {
                        this.Hide();
                        Thread t = new Thread(new ThreadStart(showfmEmployee));
                        t.Start();
                        this.Close();
                    }
                    if (emp.role.Equals("Manager"))
                    {
                        this.Hide();
                        Thread t = new Thread(new ThreadStart(showfmManager));
                        t.Start();
                        this.Close();
                    }
                    if (emp.role.Equals("Admin"))
                    {
                        this.Hide();
                        Thread t = new Thread(new ThreadStart(showfmAdmin));
                        t.Start();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Invalid account");
                }
            }
            else
            {
                MessageBox.Show(check);
            }
        }
        public int Delete(DTO_Employee emp)
        {
            if (emp.MaNV.ToString() == "")
            {
                return(-2);
            }

            if (true)
            {
            }
            try
            {
                return(new DAO_Employee().Delete(emp));
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            bool valid = true;

            valid = CustomValidate.Instance.Required(txtEmployeeId, lblId) == false ? false : valid;
            if (valid)
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    DTO_Employee employee = new DTO_Employee(txtEmployeeId.Text.Trim());
                    busEmployee.DeleteEmployee(employee);
                    loadEmployees();
                }
            }
            else
            {
                MessageBox.Show("Vui lòng xem lại dữ liệu", "Thông báo");
            }
        }
        public async Task GetAdjustmentResults()
        {
            try
            {
                DTO_Employee token = new DTO_Employee
                {
                    EmployeeID = 2,
                };

                var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "GetAdjustmentResults"),
                                                            token);

                response.EnsureSuccessStatusCode();
                AdjustmentResults = await response.Content.ReadAsAsync <List <DTO_LU_AdjustmentResult> >();
            }catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }
        }