示例#1
0
        public MainForm()
        {
            InitializeComponent();

            MainPanel.Controls.Add(new Home());
            BackHome.Visible = false;

            var adobePath = Registry.GetValue(@"HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", string.Empty, string.Empty);

            if (adobePath == null)
            {
                MessageBox.Show("Please install adobe reader to fully utilize the system's functionality", "Adobe Reader Not Found", MessageBoxButtons.OK);
            }

            TempFileHandler.CleanTempFile();

            if (Reviewer.IsAdmin)
            {
                ToolStripMenuItem AdminButton = new ToolStripMenuItem("Admin");
                Menu.Items.Add(AdminButton);
                ToolStripMenuItem button = new ToolStripMenuItem("Users List");
                button.Click += UserListBtn;
                AdminButton.DropDownItems.Add(button);
            }
        }
        private void SaveFeedbackBtn_Click(object sender, EventArgs e)
        {
            if (PositionList.SelectedIndex == -1)
            {
                MessageBox.Show("Select a position", "Missing attributes!");
                return;
            }

            if (ApplicantList.SelectedIndex == -1)
            {
                MessageBox.Show("Select an applicant", "Missing attributes!");
                return;
            }

            if (_currentFeed.Header == null)
            {
                MessageBox.Show("Please select the header before proceeding", "Missing component!");
                return;
            }

            if (_currentFeed.Sections.Count <= 0)
            {
                MessageBox.Show("Please select the sections before proceeding", "Missing component!");
                return;
            }

            _currentFeed.ReviewerId = Reviewer.Id.ToString();

            //check if there are null values in the header
            foreach (HeaderItem item in _currentFeed.Header.HeaderItems)
            {
                Control control = Controls.Find("header" + item.Id, true)[0];

                try
                {
                    switch (control.GetType().Name)
                    {
                    case "TextBox":
                    case "Label":
                        item.ValueChosen = ((TextBox)control).Text;
                        break;

                    case "ComboBox":
                        item.ValueChosen = ((ComboBox)control).SelectedItem.ToString();
                        break;

                    case "DateTimePicker":
                        item.ValueChosen = ((DateTimePicker)control).Value.ToString("dd/MM/yyyy");
                        break;
                    }

                    if (item.ValueChosen.Length <= 0)
                    {
                        throw new NullReferenceException();
                    }
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show("Please complete the header before proceeding", "Missing attributes!");
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!");
                    return;
                }
            }

            bool sectionChecked = false;

            //check if there is null values in the sections
            foreach (Section s in _currentFeed.Sections)
            {
                RichTextBox text    = (RichTextBox)Controls.Find("comment" + s.SectionId, true)[0];
                ComboBox    codes   = (ComboBox)Controls.Find("codes" + s.SectionId, true)[0];
                CheckBox    checker = (CheckBox)Controls.Find("checker" + s.SectionId, true)[0];


                if (codes.SelectedIndex == -1)
                {
                    MessageBox.Show("Please complete the sections before proceeding -> Codes", "Missing attributes!");
                    return;
                }

                //Assign values to section object
                s.Comment    = text.Text;
                s.CodeChosen = codes.SelectedItem.ToString();
                s.IsChecked  = checker.Checked;

                if (s.Comment.Length <= 0)
                {
                    MessageBox.Show("Please complete the sections before proceeding -> Comment", "Missing attributes!");
                    return;
                }

                if (s.IsChecked)
                {
                    sectionChecked = true;
                }
            }

            if (!sectionChecked)
            {
                MessageBox.Show("Please check at least one section!", "Missing attributes!");
                return;
            }

            //end of field checkers

            MySql sql = new MySql();

            sql.OpenConnection();
            try
            {
                //update or insert the feedback
                if (String.IsNullOrEmpty(_currentFeed.FeedbackID))
                {
                    if (sql.SaveFeedback(_currentFeed))
                    {
                        MessageBox.Show("Feedback successfully saved.");
                    }
                }
                else
                {
                    if (sql.UpdateFeedback(_currentFeed))
                    {
                        MessageBox.Show("Feedback successfully updated.");
                    }
                }

                //checks whether is all the applications for the position is completed

                if (CheckPositionIsCompleted()) //means all of the applications have generated the feedback
                {
                    var result = MessageBox.Show("All the feedbacks for this current position: " + _currentFeed.Position._positionName + " is completed. \n Please choose the file name of the attachehment to be send to the applicants. \n Yes for Applicant name or No for Applicant code"
                                                 , "Select file name", MessageBoxButtons.YesNo);

                    //true for name false for code
                    bool filename = (result == DialogResult.Yes ? true : false);

                    try
                    {
                        int count = 0;

                        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");


                        foreach (Applicant app in sql.GetEmailList(_currentFeed.Position._positionId))
                        {
                            string      currentFilename = (filename ? app.Name : app.Id);
                            MailMessage mail            = new MailMessage(new MailAddress("*****@*****.**"), new MailAddress(app.Email));
                            mail.Subject = "Application feedback for " + _currentFeed.Position._positionName + " in HappyTech.";
                            mail.Body    = "Hi " + app.Name + ",\nPlease find the attached file as the feedback from us regarding your application at HappyTech. \n\nRegards,\nHappy Tech HR";

                            System.Net.Mail.Attachment attachment;
                            attachment = new System.Net.Mail.Attachment(TempFileHandler.MakeTempFilePdf(app.Pdf, currentFilename));
                            mail.Attachments.Add(attachment);

                            SmtpServer.Port                  = 587;
                            SmtpServer.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            SmtpServer.UseDefaultCredentials = false;
                            SmtpServer.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "happytech123");
                            SmtpServer.EnableSsl             = true;

                            SmtpServer.Send(mail);
                            count++;
                        }
                        MessageBox.Show("Total of " + count + " emails are sent.");
                    } catch (Exception exc)
                    {
                        throw exc;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString(), "Ops! Error occured!");
            }
            finally
            {
                sql.CloseConnection();
            }
        }
        private void ApplicantList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SaveTemplateBtn.Enabled = false;
            ChangeHeader.Visible    = false;
            AddSectionBtn.Visible   = false;

            if (ApplicantList.SelectedIndex != -1)
            {
                PDFDisplay.DocumentText = "<HTML><CENTER>Loading...</CENTER></HTML>";

                Applicant app = (Applicant)ApplicantList.SelectedItem;
                _currentFeed.Applicant = app;

                if (app.Pdf != null)
                {
                    string tempFile = TempFileHandler.MakeTempFile(app.Pdf);
                    PDFDisplay.Navigate(tempFile);
                }
                else
                {
                    PDFDisplay.DocumentText = "<HTML><CENTER>No PDF found</CENTER></HTML>";
                }

                MySql sql = new MySql();
                sql.OpenConnection();

                DataTable Dt = sql.GetDataSet("SELECT * FROM feedbacksystem.feedback WHERE feedback.PositionID = " + _currentFeed.Position._positionId + " AND feedback.AppID = " + _currentFeed.Applicant.Id);
                if (Dt != null && Dt.Rows.Count > 0)
                {
                    Feedback tmpFeedback = sql.GetFeedback(Dt.Rows[0]["FeedbackID"].ToString());
                    _currentFeed.FeedbackID = Dt.Rows[0]["FeedbackID"].ToString();
                    _currentFeed.Header     = tmpFeedback.Header;
                    _currentFeed.Sections   = tmpFeedback.Sections;
                    FillHeader();
                    FillSection();

                    ChangeHeader.Visible  = !CheckPositionIsCompleted();
                    AddSectionBtn.Visible = !CheckPositionIsCompleted();

                    SaveFeedbackBtn.Text = "Update Feedback";
                }
                else
                {
                    SaveFeedbackBtn.Text    = "Save Feedback";
                    _currentFeed.FeedbackID = "";
                    if (_currentFeed.Header != null)
                    {
                        _currentFeed.Header.HeaderItems.Clear();
                        //in order to reset the header items value for the cascading
                        _currentFeed.Header.HeaderItems = sql.GetHeaderItems(_currentFeed.Header.HeaderId);
                        ChangeHeader.Visible            = true;

                        FillHeader();
                    }

                    if (_currentFeed.Sections.Count > 0)
                    {
                        foreach (Section sec in _currentFeed.Sections)
                        {
                            sec.Comment    = null;
                            sec.CodeChosen = null;
                            sec.IsChecked  = false;
                        }
                        AddSectionBtn.Visible = true;

                        FillSection();
                    }
                }

                sql.CloseConnection();
                SetTemplateBtn.Enabled = !CheckPositionIsCompleted();
            }
        }
示例#4
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     TempFileHandler.CleanTempSession();
 }