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(); }