예제 #1
0
        private void txtEmployeeID_Leave(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtEmployeeID.Text.TrimEnd()))
            {
                nsgEmployee = DB.NSGEmployees.Where(emp => emp.NSGEmployeeCode == txtEmployeeID.Text).FirstOrDefault();

                if (nsgEmployee != null)
                {
                    txtEmployeeName.Text  = nsgEmployee.FirstName + " " + nsgEmployee.LastName;
                    cmbRank.SelectedValue = nsgEmployee.RankID;
                    cmbUnit.SelectedValue = nsgEmployee.UnitID;

                    if (nsgEmployee.QuarterTypeID != null)
                    {
                        cmbQuarterType.SelectedValue = nsgEmployee.QuarterTypeID;
                    }

                    if (nsgEmployee.QuarterNumber != null)
                    {
                        txtQuarterNumber.Text = nsgEmployee.QuarterNumber.ToString();
                    }
                }
                else
                {
                    txtEmployeeName.Text         = string.Empty;
                    cmbRank.SelectedIndex        = -1;
                    cmbUnit.SelectedIndex        = -1;
                    cmbQuarterType.SelectedIndex = -1;
                    txtQuarterNumber.Text        = string.Empty;
                }
            }
        }
예제 #2
0
        private void txtEmployeeID_Leave(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtEmployeeID.Text.TrimEnd()))
            {
                btnCreate.Text = "&Create";

                nsgEmployee = DB.NSGEmployees.Where(emp => emp.NSGEmployeeCode == txtEmployeeID.Text).FirstOrDefault();

                if (nsgEmployee != null)
                {
                    btnCreate.Text = "&Update";

                    txtFirstName.Text = nsgEmployee.FirstName;
                    txtLastName.Text  = nsgEmployee.LastName;
                    if (nsgEmployee.Gender.ToUpper() == "MALE")
                    {
                        radMale.Checked = true;
                    }
                    else
                    {
                        radFemale.Checked = true;
                    }
                    cmbRank.SelectedValue        = nsgEmployee.RankID;
                    cmbUnit.SelectedValue        = nsgEmployee.UnitID;
                    cmbQuarterType.SelectedValue = nsgEmployee.QuarterTypeID;
                    txtQuarterNumber.Text        = nsgEmployee.QuarterNumber.ToString();

                    coreUser = DB.CoreUsers.Where(cu => cu.EmployeeID.ToString() == txtEmployeeID.Text).FirstOrDefault();

                    if (coreUser != null)
                    {
                        txtUserName.Text = coreUser.UserName;
                    }
                }
            }
        }
예제 #3
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string successMsg = string.Empty;

            try
            {
                if (ValidateControls())
                {
                    btnCreate.Enabled = false;
                    btnCancel.Enabled = false;

                    this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                    if (nsgEmployee == null)
                    {
                        nsgEmployee             = new NSGEmployee();
                        nsgEmployee.EntryDate   = DateTime.Now;
                        nsgEmployee.EntryUserID = GlobalClass.LoggedInUserID;
                    }
                    else
                    {
                        nsgEmployee.UpdateDate   = DateTime.Now;
                        nsgEmployee.UpdateUserID = GlobalClass.LoggedInUserID;
                    }

                    nsgEmployee.NSGEmployeeCode = txtEmployeeID.Text;
                    nsgEmployee.FirstName       = txtFirstName.Text;
                    nsgEmployee.LastName        = txtLastName.Text;
                    nsgEmployee.Gender          = (radMale.Checked ? "Male" : "Female");
                    nsgEmployee.RankID          = int.Parse(cmbRank.SelectedValue.ToString());
                    nsgEmployee.UnitID          = int.Parse(cmbUnit.SelectedValue.ToString());

                    if (cmbQuarterType.SelectedIndex > -1)
                    {
                        nsgEmployee.QuarterTypeID = int.Parse(cmbQuarterType.SelectedValue.ToString());
                    }

                    nsgEmployee.QuarterNumber = int.Parse(txtQuarterNumber.Text);

                    nsgEmployee.IsActive = chkEmpActive.Checked;

                    DB.NSGEmployees.Add(nsgEmployee);

                    successMsg = "Employee created successfully.";

                    if (chkCreateLogin.Checked)
                    {
                        CoreUser coreDupUser;

                        if (coreUser == null)
                        {
                            coreDupUser = DB.CoreUsers.Where(cu => cu.UserName.ToUpper() == txtUserName.Text.ToUpper()).FirstOrDefault();
                        }
                        else
                        {
                            coreDupUser = DB.CoreUsers.Where(cu => cu.UserName.ToUpper() == txtUserName.Text.ToUpper() && cu.EmployeeID != txtEmployeeID.Text).FirstOrDefault();
                        }

                        if (coreDupUser == null)
                        {
                            if (coreUser == null)
                            {
                                coreUser             = new CoreUser();
                                coreUser.EntryDate   = DateTime.Now;
                                coreUser.EntryUserID = GlobalClass.LoggedInUserID;
                            }
                            else
                            {
                                coreUser.UpdateDate   = DateTime.Now;
                                coreUser.UpdateUserID = GlobalClass.LoggedInUserID;
                            }

                            coreUser.UserName     = txtUserName.Text;
                            coreUser.UserPassword = txtPassword.Text;
                            coreUser.EmployeeID   = txtEmployeeID.Text;
                            coreUser.FirstName    = txtFirstName.Text;
                            coreUser.LastName     = txtLastName.Text;
                            coreUser.IsActive     = chkUserActive.Checked;

                            DB.CoreUsers.Add(coreUser);
                            successMsg = "Employee and login created successfully.";
                        }
                        else
                        {
                            MessageBox.Show("This user name already exists.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtUserName.Text       = string.Empty;
                            txtPassword.Text       = string.Empty;
                            txtReTypePassword.Text = string.Empty;
                            txtUserName.Focus();
                            this.btnCreate.Enabled = true;
                            this.btnCancel.Enabled = true;
                            this.Cursor            = System.Windows.Forms.Cursors.Default;
                            return;
                        }
                    }

                    DB.SaveChanges();
                    MessageBox.Show(successMsg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Cursor = System.Windows.Forms.Cursors.Default;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                this.Cursor = System.Windows.Forms.Cursors.Default;
                MessageBox.Show(ex.Message, this.Text + " : btnCreate_Click : " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.btnCreate.Enabled = true;
                this.btnCancel.Enabled = true;
                this.Cursor            = System.Windows.Forms.Cursors.Default;
            }
        }
예제 #4
0
        private void RefreshMe()
        {
            if (visitorID == 0)
            {
                txtVisitorNumber.Text         = string.Empty;
                txtFirstName.Text             = string.Empty;
                txtLastName.Text              = string.Empty;
                cmbGender.SelectedIndex       = -1;
                txtMobileNo.Text              = string.Empty;
                cmbIdentityType.SelectedIndex = -1;
                txtIdentityNumber.Text        = string.Empty;
                txtVisitorAddress.Text        = string.Empty;
                cmbState.SelectedIndex        = -1;
                cmbCity.SelectedIndex         = -1;
                txtVehicleNumber.Text         = string.Empty;
                txtPurpose.Text              = string.Empty;
                txtEmployeeID.Text           = string.Empty;
                txtEmployeeName.Text         = string.Empty;
                cmbRank.SelectedIndex        = -1;
                cmbUnit.SelectedIndex        = -1;
                cmbQuarterType.SelectedIndex = -1;
                txtQuarterNumber.Text        = string.Empty;
                dgvCoVisitors.Rows.Clear();
                picVisitorPhoto.Image = null;
                btnPrint.Enabled      = false;
                isNewEntry            = true;
                isEditEntry           = false;
                visitor           = null;
                nsgEmployee       = null;
                coVisitors        = new List <CoVisitor>();
                coVisitorsRemoved = new List <CoVisitor>();
            }
            else
            {
                txtVisitorNumber.Text = visitorID.ToString();

                if (!isEditEntry || visitor.OutTime != null)
                {
                    txtVisitorNumber.ReadOnly  = true;
                    txtFirstName.ReadOnly      = true;
                    txtLastName.ReadOnly       = true;
                    cmbGender.Enabled          = false;
                    txtMobileNo.ReadOnly       = true;
                    cmbIdentityType.Enabled    = false;
                    txtIdentityNumber.ReadOnly = true;
                    txtVisitorAddress.ReadOnly = true;
                    cmbState.Enabled           = false;
                    cmbCity.Enabled            = false;
                    txtVehicleNumber.ReadOnly  = true;
                    txtPurpose.ReadOnly        = true;
                    txtEmployeeID.ReadOnly     = true;
                    txtEmployeeName.ReadOnly   = true;
                    cmbRank.Enabled            = false;
                    cmbUnit.Enabled            = false;
                    cmbQuarterType.Enabled     = false;
                    txtQuarterNumber.ReadOnly  = true;
                    dgvCoVisitors.Enabled      = false;
                }

                btnPrint.Enabled = true;
            }
        }
예제 #5
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateControls())
                {
                    return;
                }

                if (isNewEntry)
                {
                    visitor             = new Visitor();
                    visitor.InTime      = DateTime.Now;
                    visitor.EntryDate   = DateTime.Now;
                    visitor.EntryUserID = GlobalClass.LoggedInUserID;
                }
                else
                {
                    if (!isEditEntry)
                    {
                        visitor.OutTime = DateTime.Now;
                    }

                    visitor.UpdateDate   = DateTime.Now;
                    visitor.UpdateUserID = GlobalClass.LoggedInUserID;
                }

                visitor.MachineID      = GlobalClass.MachineName;
                visitor.FirstName      = txtFirstName.Text;
                visitor.LastName       = txtLastName.Text;
                visitor.Gender         = cmbGender.Text;
                visitor.MobileNo       = txtMobileNo.Text;
                visitor.IdentityTypeID = int.Parse(cmbIdentityType.SelectedValue.ToString());
                visitor.IdentityNumber = txtIdentityNumber.Text;
                visitor.VisitorAddress = txtVisitorAddress.Text;
                visitor.StateID        = int.Parse(cmbState.SelectedValue.ToString());

                if (cmbCity.SelectedIndex > -1)
                {
                    visitor.CityID = int.Parse(cmbCity.SelectedValue.ToString());
                }

                visitor.VehicleNumber = txtVehicleNumber.Text;

                visitor.Purpose       = txtPurpose.Text;
                visitor.PersonEmpCode = txtEmployeeID.Text;
                visitor.PersonName    = txtEmployeeName.Text;

                if (cmbRank.SelectedIndex != -1)
                {
                    visitor.RankID = int.Parse(cmbRank.SelectedValue.ToString());
                }

                if (cmbUnit.SelectedIndex != -1)
                {
                    visitor.UnitID = int.Parse(cmbUnit.SelectedValue.ToString());
                }

                if (cmbQuarterType.SelectedIndex != -1)
                {
                    visitor.QuarterTypeID = int.Parse(cmbQuarterType.SelectedValue.ToString());
                }

                if (txtQuarterNumber.Text.TrimEnd() != string.Empty)
                {
                    visitor.QuarterNumber = int.Parse(txtQuarterNumber.Text);
                }

                byte[] visitorImage = (byte[])imgConverter.ConvertTo(picVisitorPhoto.Image, typeof(byte[]));
                visitor.VisitorPhoto = visitorImage;

                if (isNewEntry)
                {
                    DB.Visitors.Add(visitor);
                }

                if (isNewEntry && nsgEmployee == null && !string.IsNullOrEmpty(txtEmployeeID.Text.TrimEnd()))
                {
                    nsgEmployee = new NSGEmployee();
                    nsgEmployee.NSGEmployeeCode = txtEmployeeID.Text;
                    nsgEmployee.FirstName       = txtFirstName.Text;
                    nsgEmployee.Gender          = "Male";
                    nsgEmployee.RankID          = int.Parse(cmbRank.SelectedValue.ToString());
                    nsgEmployee.UnitID          = int.Parse(cmbUnit.SelectedValue.ToString());

                    if (cmbQuarterType.SelectedIndex > -1)
                    {
                        nsgEmployee.QuarterTypeID = int.Parse(cmbQuarterType.SelectedValue.ToString());
                    }

                    if (txtQuarterNumber.Text.TrimEnd() != string.Empty)
                    {
                        nsgEmployee.QuarterNumber = int.Parse(txtQuarterNumber.Text);
                    }

                    nsgEmployee.IsActive = true;

                    nsgEmployee.EntryDate   = DateTime.Now;
                    nsgEmployee.EntryUserID = GlobalClass.LoggedInUserID;

                    DB.NSGEmployees.Add(nsgEmployee);
                }

                DB.SaveChanges();

                foreach (DataGridViewRow dgvRow in dgvCoVisitors.Rows)
                {
                    if (dgvRow.Cells["CoVisitorName"].Value != null)
                    {
                        CoVisitor coVisitor = null;

                        if (dgvRow.Cells["CoVisitorID"].Value != null)
                        {
                            coVisitor              = coVisitors.Find(cv => cv.CoVisitorID == long.Parse(dgvRow.Cells["CoVisitorID"].Value.ToString()));
                            coVisitor.UpdateDate   = DateTime.Now;
                            coVisitor.UpdateUserID = GlobalClass.LoggedInUserID;
                        }
                        else
                        {
                            coVisitor             = new CoVisitor();
                            coVisitor.EntryDate   = DateTime.Now;
                            coVisitor.EntryUserID = GlobalClass.LoggedInUserID;
                            coVisitor             = DB.CoVisitors.Add(coVisitor);
                            coVisitors.Add(coVisitor);
                        }

                        coVisitor.VisitorID     = visitor.VisitorID;
                        coVisitor.CoVisitorName = dgvRow.Cells["CoVisitorName"].Value.ToString();

                        if (dgvRow.Cells["IdentityType"].Value != null)
                        {
                            coVisitor.IdentityTypeID = int.Parse(dgvRow.Cells["IdentityType"].Value.ToString());
                        }

                        if (dgvRow.Cells["IdentityNumber"].Value != null)
                        {
                            coVisitor.IdentityNumber = dgvRow.Cells["IdentityNumber"].Value.ToString();
                        }

                        coVisitor.Gender         = dgvRow.Cells["Gender"].Value.ToString();
                        coVisitor.VisitorAddress = string.Empty;

                        coVisitor.RelationshipID = int.Parse(dgvRow.Cells["Relationship"].Value.ToString());
                    }
                }

                if (coVisitorsRemoved.Count > 0)
                {
                    DB.CoVisitors.RemoveRange(coVisitorsRemoved);
                }

                DB.SaveChanges();

                if (isNewEntry)
                {
                    DialogResult msgResponse = MessageBox.Show("Visitor information saved successfully.\nDo you want to continue with Print?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                    if (msgResponse == DialogResult.Yes)
                    {
                        btnPrint_Click(null, null);
                    }

                    msgResponse = MessageBox.Show("Do you want to continue with Visitor Entry?", this.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                    if (msgResponse == DialogResult.Yes)
                    {
                        RefreshMe();
                    }
                    else if (msgResponse == DialogResult.No)
                    {
                        btnCancel_Click(null, null);
                    }
                    else
                    {
                        visitorID = visitor.VisitorID;
                        RefreshMe();
                    }
                }
                else if (isEditEntry)
                {
                    MessageBox.Show("Visitor information updated successfully.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnCancel_Click(null, null);
                }
                else
                {
                    MessageBox.Show("Visitor exit saved successfully.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnCancel_Click(null, null);
                }
            }
            catch (Exception ex)
            {
                this.Cursor = System.Windows.Forms.Cursors.Default;
                MessageBox.Show(ex.Message, this.Text + " : btnEnter_Click : " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #6
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                txtUsername.Focus();
                MessageBox.Show("Please enter Username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                txtPassword.Focus();
                MessageBox.Show("Please enter Password.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["LicenseExpiry"]))
            {
                if (DateTime.Today > DateTime.Parse(ConfigurationManager.AppSettings["LicenseExpiry"].ToString()))
                {
                    MessageBox.Show("Software License Expired, Please contact software administrator.");
                    return;
                }
            }

            this.btnLogin.Enabled  = false;
            this.btnCancel.Enabled = false;
            this.Cursor            = System.Windows.Forms.Cursors.WaitCursor;

            string username = txtUsername.Text.ToUpper();

            CoreUser coreUser = DB.CoreUsers.Where(cu => cu.UserName.ToUpper() == txtUsername.Text.ToUpper() && cu.UserPassword == txtPassword.Text).FirstOrDefault();

            if (coreUser != null)
            {
                GlobalClass.LoggedInUserID = coreUser.CoreUserID;
                GlobalClass.EmployeeName   = coreUser.FirstName + " " + coreUser.LastName;

                NSGEmployee nsgEmp = DB.NSGEmployees.Where(em => em.NSGEmployeeCode == coreUser.EmployeeID).FirstOrDefault();

                if (coreUser.UserName.ToUpper() == "NSGADMIN")
                {
                    if (MessageBox.Show("Do you want to create user?", "Login", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        frmCreateUser createUserForm = new frmCreateUser();
                        this.Hide();
                        createUserForm.ShowDialog();
                        this.txtPassword.Text  = string.Empty;
                        this.txtUsername.Text  = string.Empty;
                        this.btnLogin.Enabled  = true;
                        this.btnCancel.Enabled = true;
                        this.txtUsername.Focus();
                        this.Cursor = System.Windows.Forms.Cursors.Default;
                        this.Show();
                    }
                    else
                    {
                        //GlobalClass.LoggedInUserRank = DB.CoreRanks.Where(cr => cr.RankID == nsgEmp.RankID).FirstOrDefault().RankName;
                        //GlobalClass.LoggedInUserUnit = DB.CoreUnits.Where(cu => cu.UnitID == nsgEmp.UnitID).FirstOrDefault().UnitName;

                        this.btnLogin.Enabled  = true;
                        this.btnCancel.Enabled = true;
                        this.Cursor            = System.Windows.Forms.Cursors.Default;
                        this.Hide();
                        frmMainPage frmMainPage = new frmMainPage();
                        frmMainPage.ShowDialog();
                        this.Close();
                    }
                }
                else
                {
                    GlobalClass.LoggedInUserRank = DB.CoreRanks.Where(cr => cr.RankID == nsgEmp.RankID).FirstOrDefault().RankName;
                    GlobalClass.LoggedInUserUnit = DB.CoreUnits.Where(cu => cu.UnitID == nsgEmp.UnitID).FirstOrDefault().UnitName;

                    this.btnLogin.Enabled  = true;
                    this.btnCancel.Enabled = true;
                    this.Cursor            = System.Windows.Forms.Cursors.Default;
                    this.Hide();
                    frmMainPage frmMainPage = new frmMainPage();
                    frmMainPage.ShowDialog();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Invalid username or password!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPassword.Text = string.Empty;
                txtUsername.Text = string.Empty;
                txtUsername.Focus();
                this.btnLogin.Enabled  = true;
                this.btnCancel.Enabled = true;
                this.Cursor            = System.Windows.Forms.Cursors.Default;
                return;
            }
        }