Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            oCandidate    = new DataAccess.Candidate();
            oImageConvert = new CommonFunction.CommonFunction();

            foreach (var oText in pnlMain.Controls.OfType <TextBox>().ToList())
            {
                if (oText.Text.Trim() == String.Empty)
                {
                    oFrmMsgBox             = new frmMessageBox("All fields are required.");
                    oFrmMsgBox.MessageType = frmMessageBox.MESSAGE_TYPE.INFO;
                    oFrmMsgBox.ShowDialog();
                    return;
                }
            }

            oMCandidate               = new Model.Candidate();
            oMCandidate.UNIQUE_ID     = eVariable.sID;
            oMCandidate._Position.ID  = eVariable.sPositionID;
            oMCandidate._Party.ID     = eVariable.sPartyID;
            oMCandidate.ELECTION_CODE = lblElectionNo.Text;
            oMCandidate.DATE_ADDED    = DateTime.Now.ToString("yyyy-MM-dd");
            oMCandidate.ADDED_BY      = eVariable.sUsername;

            if (txtParty.Text != "INDEPENDENT")
            {
                if (oCandidate.IsSamePositionAndParty(oMCandidate))
                {
                    oFrmMsgBox             = new frmMessageBox("THERE SHOULD BE ONLY ONE POSITION PER PARTY");
                    oFrmMsgBox.MessageType = frmMessageBox.MESSAGE_TYPE.INFO;
                    oFrmMsgBox.ShowDialog();
                    return;
                }
            }

            oStringUtility = new CommonFunction.CommonFunction();
            if (pImage.Image != null)
            {
                oMCandidate.PROFILE_PIC = oStringUtility.CompressString(oImageConvert.ImageToBaseString(pImage.Image, ImageFormat.Png));
            }


            if (TransactionType == eVariable.TransactionType.EDIT)
            {
                oMCandidate.MODIFIED_DATE = DateTime.Now.ToString("yyyy-MM-dd");
                oMCandidate.MODIFIED_BY   = eVariable.sUsername;
                oCandidate.UpdateCandidate(oMCandidate);
            }
            else
            {
                oCandidate.InsertCandidate(oMCandidate);
            }

            oFrmCandidateList.LoadCandidates();
            oFrmMsgBox             = new frmMessageBox("Record has been successfully saved.");
            oFrmMsgBox.MessageType = frmMessageBox.MESSAGE_TYPE.INFO;
            oFrmMsgBox.ShowDialog();
            Close();
        }
Exemplo n.º 2
0
        private void btnButton_Click(object sender, EventArgs e)
        {
            if (btnButton.Text.Trim() == "IMPORT")
            {
                if (txtImportPath.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("Please select file to import");
                    return;
                }

                #region Import
                try
                {
                    if (cboImport.SelectedText == "STUDENT" || cboImport.Text == "STUDENT")
                    {
                        if (dgImport.Rows.Count > 0)
                        {
                            foreach (var iData in lstStudent)
                            {
                                oStudent = new DataAccess.Student();
                                if (!oStudent.IsRecordExists(iData))
                                {
                                    oStudent.InsertStudent(iData);
                                }
                            }

                            MessageBox.Show("Record has been succesfully saved", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

                    if (cboImport.SelectedText == "POSITION" || cboImport.Text == "POSITION")
                    {
                        if (dgImport.Rows.Count > 0)
                        {
                            foreach (var iData in lstCandidate)
                            {
                                oCandidate = new DataAccess.Candidate();
                                oCandidate.InsertCandidate(iData);
                            }
                            MessageBox.Show("Record has been succesfully saved", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                #endregion
            }
            else
            {
                if (txtExportPath.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("PLEASE SELECT DISTINATION FILE PATH");
                    return;
                }

                if (dgExport.Rows.Count == 0)
                {
                    MessageBox.Show("POPULATE RECORD FIRST");
                    return;
                }

                #region Export
                ExtractData();
                #endregion
            }
        }