Exemple #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult dr;
         dr = MessageBox.Show("Do you want to delete?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             int Index = dgvList.CurrentRow.Index;
             int Id    = int.Parse(dgvList.Rows[Index].Cells[1].Value.ToString());
             using (var context = new TailorEntities())
             {
                 var remove = context.StaffDeductions.Find(Id);
                 if (remove != null)
                 {
                     //remove.Status = false;
                     context.SaveChanges();
                     this.LoadData();
                     MessageBox.Show("Removed...");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("There is no value to delete");
     }
 }
Exemple #2
0
 private void Edit()
 {
     using (var db = new TailorEntities())
     {
         var query = db.StaffAttendances.SingleOrDefault(s => s.StaffCode == code && s.Date == date);
         cboCode.SelectedValue = code;
         if (query.Status == "P")
         {
             rbtnP.Checked = true;
         }
         else if (query.Status == "A")
         {
             rbtnA.Checked = true;
         }
         else
         {
             rbtnA.Checked = false;
             rbtnP.Checked = false;
         }
         dtpFromDate.Value     = query.Date;
         dtpUntillDate.Value   = query.Date;
         dtpFromDate.Enabled   = false;
         dtpUntillDate.Enabled = false;
         txtReason.Text        = query.Remark;
     }
 }
Exemple #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (index < 0)
            {
                return;
            }
            DialogResult dr = TailorMessage.Show("តើអ្នកចង់លុបទិន្នន័យមែនទេ?", "លុបទិន្នន័យ", TailorMessageIcon.Warning);

            if (dr == DialogResult.Yes)
            {
                using (var context = new TailorEntities())
                {
                    var staff = context.Staffs.SingleOrDefault(s => s.Code == code);
                    staff.IsActive = false;
                    int action = context.SaveChanges();
                    {
                        if (action >= 1)
                        {
                            LoadData();
                            LoadInfo();
                        }
                    }
                }
            }
        }
Exemple #4
0
 private void cboStaff_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var db = new TailorEntities())
     {
         var staff = db.Staffs.SingleOrDefault(s => s.Code == cboStaff.SelectedValue.ToString());
         cboCode.SelectedValue = staff.Code;
     }
 }
Exemple #5
0
 private void LoadStaffName()
 {
     using (var db = new TailorEntities())
     {
         var staffName = db.Staffs.Where(s => s.IsActive).ToList();
         cboStaff.DataSource    = staffName;
         cboStaff.DisplayMember = "NameKh";
         cboStaff.ValueMember   = "Code";
     }
 }
Exemple #6
0
 private void LoadGender()
 {
     using (var db = new TailorEntities())
     {
         //Load gender from database
         var gender = db.Genders.ToList();
         cboGender.DataSource    = gender;
         cboGender.DisplayMember = "Description";
         cboGender.ValueMember   = "Id";
     }
 }
Exemple #7
0
 private void LoadPosition()
 {
     using (var db = new TailorEntities())
     {
         //Load Position from database
         var position = db.Positions.Where(p => p.IsActive);
         cboSkill.DataSource    = position.ToList();
         cboSkill.DisplayMember = "Description";
         cboSkill.ValueMember   = "Id";
     }
 }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     using (var db = new TailorEntities())
     {
         var query = db.StaffAttendances.Where(a => a.Date >= dtpFromDate.Value.Date && a.Date <= dtpUntillDate.Value.Date).OrderByDescending(a => a.Date).ToList();
         dgvList.Rows.Clear();
         foreach (var a in query)
         {
             dgvList.Rows.Add("", a.StaffCode, a.Staff.NameKh, a.Staff.Gender.Description, a.Date.ToShortDateString(), a.Status, a.Remark);
         }
         TailorService.GenerateRowNumber(dgvList);
     }
 }
Exemple #9
0
 private void txtSearch_TextChanged(object sender, EventArgs e)
 {
     using (var context = new TailorEntities())
     {
         var query = context.Staffs.ToList().Where(s => s.NameKh.Contains(txtSearch.Text.Trim()) || s.Code.ToLower().Contains(txtSearch.Text.Trim().ToLower()) && s.IsActive);
         dgvList.Rows.Clear();
         foreach (var s in query)
         {
             dgvList.Rows.Add("", s.Code, s.NameKh, s.Gender.Description, s.DateOfBirth, s.NationalId, s.Phone, s.BasicSalary);
         }
         TailorService.GenerateRowNumber(dgvList);
     }
 }
        private void txtSeach_TextChanged(object sender, EventArgs e)
        {
            using (var db = new TailorEntities())
            {
                var query = db.StaffAttendances.Where(a => a.Staff.NameKh.Contains(txtSeach.Text.Trim()) || a.StaffCode.ToLower().Contains(txtSeach.Text.Trim().ToLower())).OrderByDescending(a => a.Date).ToList();

                dgvList.Rows.Clear();
                foreach (var a in query)
                {
                    dgvList.Rows.Add("", a.StaffCode, a.Staff.NameKh, a.Staff.Gender.Description, a.Date, a.Status, a.Remark);
                }
                TailorService.GenerateRowNumber(dgvList);
            }
        }
Exemple #11
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            //sarche staff deduction
            dgvList.Rows.Clear();
            int i = 1;

            using (var context = new TailorEntities())
            {
                var result = from s in context.StaffDeductions.ToList() where s.Staff.NameKh.ToLower().StartsWith(txtSearch.Text.ToLower()) select s;
                foreach (var s in result)
                {
                    dgvList.Rows.Add(i++, s.StaffCode, s.Staff.NameKh, s.Date, s.Amount, s.Reason);
                }
            }
        }
Exemple #12
0
        private void LoadData()
        {
            //Load Staff Deduction
            dgvList.Rows.Clear();
            int i = 1;

            using (var context = new TailorEntities())
            {
                var staff = context.StaffDeductions.ToList();

                foreach (var s in staff)
                {
                    dgvList.Rows.Add(i++, s.StaffCode, s.Staff.NameKh, s.Date, s.Amount, s.Reason);
                }
            }
        }
Exemple #13
0
        public void LoadInfo()
        {
            using (var context = new TailorEntities())
            {
                //Count all boy staff in database
                var bStaff = context.Staffs.Where(s => s.GenderId == 1 && s.IsActive).Count();
                lblBoy.Text = bStaff + " នាក់";

                //Count all girl staff in database
                var gStaff = context.Staffs.Where(s => s.GenderId == 2 && s.IsActive).Count();
                lblGirl.Text = gStaff + " នាក់";

                //Count all staff in database
                var staff = context.Staffs.Where(s => s.IsActive).Count();
                lblAllStaff.Text = staff + "​​​​​​​​ នាក់";
            }
        }
        public void LoadAttendanceInfo()
        {
            using (var db = new TailorEntities())
            {
                var work = db.StaffAttendances.Where(a => a.Date == DateTime.Today && a.Status == "W").Count();
                lblW.Text = work + " នាក់";

                var permission = db.StaffAttendances.Where(a => a.Date == DateTime.Today && a.Status == "P").Count();
                lblP.Text = permission + " នាក់";

                var absent = db.StaffAttendances.Where(a => a.Date == DateTime.Today && a.Status == "A").Count();
                lblA.Text = absent + " នាក់";

                var all = db.StaffAttendances.Where(a => a.Date == DateTime.Today).Count();
                lblAll.Text = all + " នាក់";
            }
        }
Exemple #15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var db = new TailorEntities())
            {
                var query       = db.Staffs.Where(s => s.IsActive).ToList();
                var attendances = db.StaffAttendances.Where(a => a.Date.Month == dtpAttendanceDate.Value.Month).ToList();

                foreach (var s in query)
                {
                    int isExist = 0;
                    foreach (var a in attendances)
                    {
                        if (s.Code == a.Staff.Code && a.Date == dtpAttendanceDate.Value.Date)
                        {
                            isExist = 1;
                        }
                    }
                    if (isExist == 0)
                    {
                        var attendance = new StaffAttendance()
                        {
                            StaffCode    = s.Code,
                            Date         = dtpAttendanceDate.Value,
                            Status       = "W",
                            ComputerCode = TailorService.GetComputerCode(),
                            ComputeTime  = TailorService.GetComputerTime()
                        };
                        db.StaffAttendances.Add(attendance);
                    }
                }
                int action = db.SaveChanges();
                if (action >= 1)
                {
                    progressBar1.Value  = 100;
                    lblFinished.Visible = true;
                }
            }

            if (view != null)
            {
                view.LoadStaffAttendance();
            }
        }
Exemple #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cboCode.SelectedIndex < 0)
            {
                cboCode.Focus();
                error.SetError(cboCode, null);
                return;
            }

            if (cboStaff.SelectedIndex < 0)
            {
                cboStaff.Focus();
                error.SetError(cboStaff, null);
                return;
            }

            if (string.IsNullOrEmpty(txtAmount.Text.Trim()))
            {
                txtAmount.Focus();
                error.SetError(txtAmount, null);
                return;
            }

            using (var db = new TailorEntities())
            {
                StaffBonu bonus = new StaffBonu()
                {
                    StaffCode    = cboStaff.SelectedValue.ToString(),
                    Date         = dtpDate.Value,
                    Amount       = decimal.Parse(txtAmount.Text),
                    Remark       = txtReason.Text,
                    ComputerCode = TailorService.GetComputerCode(),
                    ComputeTime  = TailorService.GetComputerTime()
                };
                db.StaffBonus.Add(bonus);
                int action = db.SaveChanges();
                if (action >= 1)
                {
                    lblFinished.Visible = true;
                }
            }
        }
Exemple #17
0
 private void Edit()
 {
     using (var db = new TailorEntities())
     {
         var staff = db.Staffs.SingleOrDefault(s => s.Code == code);
         txtNameKh.Text          = staff.NameKh;
         cboGender.SelectedValue = staff.GenderId;
         dtpBirthDate.Value      = staff.DateOfBirth.Value;
         cboSkill.SelectedValue  = staff.PositionId;
         txtBirthPlace.Text      = staff.PlaceOfBirth;
         txtNameEn.Text          = staff.NameEn;
         txtNationalId.Text      = staff.NationalId;
         txtPhone.Text           = staff.Phone;
         txtBasicSalary.Text     = staff.BasicSalary.ToString();
         txtCurrentAddress.Text  = staff.CurrentAddress;
         lblCode.Visible         = true;
         lblCode.Text           += "  " + code;
         btnSave.Text            = "កែប្រែ";
     }
 }
        public void LoadStaffAttendance()
        {
            using (var db = new TailorEntities())
            {
                var query = db.StaffAttendances.Where(s => s.Date == DateTime.Today).ToList();
                dgvList.Rows.Clear();
                foreach (var a in query)
                {
                    dgvList.Rows.Add("", a.StaffCode, a.Staff.NameKh, a.Staff.Gender.Description, a.Date, a.Status, a.Remark);
                }
                TailorService.GenerateRowNumber(dgvList);

                foreach (DataGridViewColumn col in dgvList.Columns)
                {
                    col.SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                dgvList.Columns[4].DefaultCellStyle.Format = "dd/MM/yyyy";
            }
        }
Exemple #19
0
        public void LoadData()
        {
            using (var context = new TailorEntities())
            {
                var query = context.Staffs.Where(s => s.IsActive).ToList();
                dgvList.Rows.Clear();
                foreach (var s in query)
                {
                    dgvList.Rows.Add("", s.Code, s.NameKh, s.Gender.Description, s.DateOfBirth, s.NationalId, s.Phone, s.BasicSalary);
                }
                TailorService.GenerateRowNumber(dgvList);
            }
            //disable sort in datagridview
            foreach (DataGridViewColumn col in dgvList.Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            //format cell with currency
            dgvList.Columns[7].DefaultCellStyle.Format = "c";
            dgvList.Columns[4].DefaultCellStyle.Format = "dd/MM/yyyy";
        }
Exemple #20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtNameKh.Text.Trim()))
            {
                txtNameKh.Focus();
                error.SetError(txtNameKh, null);
                return;
            }

            if (cboGender.SelectedIndex < 0)
            {
                cboGender.Focus();
                error.SetError(cboGender, null);
                return;
            }

            if (cboSkill.SelectedIndex < 0)
            {
                cboSkill.Focus();
                error.SetError(cboSkill, null);
                return;
            }

            if (string.IsNullOrEmpty(txtNationalId.Text.Trim()))
            {
                txtNationalId.Focus();
                error.SetError(txtNationalId, null);
                return;
            }

            if (string.IsNullOrEmpty(txtPhone.Text))
            {
                txtPhone.Focus();
                error.SetError(txtPhone, null);
                return;
            }

            if (string.IsNullOrEmpty(txtBasicSalary.Text.Trim()))
            {
                txtBasicSalary.Focus();
                error.SetError(txtBasicSalary, null);
                return;
            }

            if (edit)
            {
                using (var db = new TailorEntities())
                {
                    DialogResult dr = TailorMessage.Show("Are you sure you want to update data?", "Update", TailorMessageIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        var staff = db.Staffs.SingleOrDefault(s => s.Code == code);
                        staff.NameKh         = txtNameKh.Text;
                        staff.NameEn         = txtNameEn.Text;
                        staff.GenderId       = int.Parse(cboGender.SelectedValue.ToString());
                        staff.NationalId     = txtNationalId.Text;
                        staff.DateOfBirth    = dtpBirthDate.Value;
                        staff.PlaceOfBirth   = txtBirthPlace.Text;
                        staff.CurrentAddress = txtCurrentAddress.Text;
                        staff.Phone          = txtPhone.Text;
                        staff.PositionId     = int.Parse(cboSkill.SelectedValue.ToString());
                        staff.BasicSalary    = decimal.Parse(txtBasicSalary.Text);
                        staff.IsActive       = true;
                        int action = db.SaveChanges();
                        if (action >= 1)
                        {
                            lblFinished.Visible = true;
                            lblFinished.Visible = true;
                        }
                    }
                }
            }
            else
            {
                id = int.Parse(cboSkill.SelectedValue.ToString());
                using (var db = new TailorEntities())
                {
                    var position = db.Positions.FirstOrDefault(p => p.Id == id);
                    code = position.Abbreviation;

                    var staff = db.Staffs.Count();
                    countRow = staff;
                    countRow++;
                }

                using (var db = new TailorEntities())
                {
                    DialogResult dr = TailorMessage.Show("Are you sure you want to add data?", "Save", TailorMessageIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        Staff staff = new Staff()
                        {
                            Code           = code + countRow,
                            NameKh         = txtNameKh.Text,
                            NameEn         = txtNameEn.Text,
                            GenderId       = int.Parse(cboGender.SelectedValue.ToString()),
                            NationalId     = txtNationalId.Text,
                            DateOfBirth    = dtpBirthDate.Value,
                            PlaceOfBirth   = txtBirthPlace.Text,
                            CurrentAddress = txtCurrentAddress.Text,
                            Phone          = txtPhone.Text,
                            PositionId     = int.Parse(cboSkill.SelectedValue.ToString()),
                            BasicSalary    = decimal.Parse(txtBasicSalary.Text),
                            IsActive       = true
                        };
                        staff = db.Staffs.Add(staff);
                        int action = db.SaveChanges();
                        if (action >= 1)
                        {
                            lblFinished.Visible = true;
                            lblCode.Text       += " " + staff.Code;
                            lblCode.Visible     = true;
                            code = staff.Code;
                            edit = true;
                        }
                    }
                }
            }

            if (staffView != null)
            {
                staffView.LoadData();
                staffView.LoadInfo();
            }
        }
Exemple #21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cboCode.SelectedIndex < 0)
            {
                error.SetError(cboCode, null);
                cboCode.Focus();
                return;
            }

            if (cboStaff.SelectedIndex < 0)
            {
                error.SetError(cboStaff, null);
                cboStaff.Focus();
                return;
            }

            if (dtpUntillDate.Value < dtpFromDate.Value)
            {
                error.SetError(dtpUntillDate, null);
                dtpUntillDate.Focus();
                return;
            }

            string status = rbtnA.Checked ? "A" : "P";

            DateTime startDate = dtpFromDate.Value;
            DateTime endDate   = dtpUntillDate.Value;

            if (edit)
            {
                using (var db = new TailorEntities())
                {
                    var query = db.StaffAttendances.SingleOrDefault(a => a.StaffCode == code && a.Date == date);
                    query.Status = status;
                    query.Remark = txtReason.Text;

                    int action = db.SaveChanges();
                    if (action >= 1)
                    {
                        lblFinished.Visible = true;
                    }
                }
            }
            else
            {
                using (var db = new TailorEntities())
                {
                    var query = db.StaffAttendances.Where(a => a.Date.Month == dtpFromDate.Value.Month || a.Date.Month == dtpUntillDate.Value.Month).ToList();

                    for (DateTime date = startDate.Date; date <= endDate.Date; date = date.AddDays(1))
                    {
                        int isExist = 0;
                        foreach (var a in query)
                        {
                            if (a.StaffCode == cboCode.SelectedValue.ToString() && a.Date.Date == date)
                            {
                                isExist = 1;
                            }
                        }
                        if (isExist == 0)
                        {
                            StaffAttendance attendance = new StaffAttendance()
                            {
                                StaffCode    = cboCode.SelectedValue.ToString(),
                                Date         = date,
                                Status       = status,
                                Remark       = txtReason.Text,
                                ComputerCode = TailorService.GetComputerCode(),
                                ComputeTime  = TailorService.GetComputerTime()
                            };
                            db.StaffAttendances.Add(attendance);
                        }
                    }
                    int action = db.SaveChanges();
                    if (action >= 1)
                    {
                        lblFinished.Visible = true;
                    }
                }
            }
            if (AttendanceView != null)
            {
                AttendanceView.LoadStaffAttendance();
                AttendanceView.LoadAttendanceInfo();
            }
        }