/// <summary> /// To get all controls data to entity /// </summary> private RegistrationEntity GetControlData() { string[] ctrlArray = { "firstName", "lastName", "fathersName", "mobile", "email", "date_of_birth", "Address", "ddlstates", "city", "pin", "rbntgender", "lang_english", "lang_hindi", "lang_telugu", "other_lang", "applying_for", "applying_for_sub_option", "experience", "key_skills", "ddllacs", "ddlthousands", "upload_resume", "notice_period", "mainCheck" }; RegistrationEntity regEntity = new RegistrationEntity(); string strLanguage = string.Empty; string strSalary = string.Empty; foreach (Control x in this.form1.Controls) { if (x is TextBox) { if (ctrlArray.Contains(x.ID)) { var txt = x as TextBox; if (x.ID == "notice_period") { if (txt.Text.Trim().Length > 0) { regEntity.GetType().GetProperty(x.ID).SetValue(regEntity, Convert.ToInt32(txt.Text)); } } else if (x.ID != "other_lang") { regEntity.GetType().GetProperty(x.ID).SetValue(regEntity, txt.Text); } } } if (x is RadioButtonList) { RadioButtonList rbnt = x as RadioButtonList; if (rbnt.ID == "rbntgender") { regEntity.gender = rbnt.SelectedValue; } } if (x is CheckBoxList) { CheckBoxList chk = x as CheckBoxList; if (chk.ID == "chk_lang") { foreach (ListItem li in chk.Items) { if (li.Selected) { if (strLanguage == string.Empty) { strLanguage = li.Text; } else { strLanguage = strLanguage + ", " + li.Text; } } } } } if (x is DropDownList) { DropDownList ddl = x as DropDownList; if (ddl.SelectedIndex > 0) { if (ddl.ID == "ddlstates") { regEntity.state = ddl.SelectedItem.Text; } if (ddl.ID == "ddllacs") { strSalary = ddl.SelectedItem.Text + "."; } if (ddl.ID == "ddlthousands") { strSalary = strSalary + ddl.SelectedItem.Text; } if (ddl.ID == "applying_for") { regEntity.applying_for = ddl.SelectedItem.Text; } if (ddl.ID == "applying_for_sub_option") { regEntity.applying_for_sub_option = ddl.SelectedItem.Text; } } } } if (other_lang.Text.Trim().Length > 0) { if (strLanguage == string.Empty) { strLanguage = other_lang.Text.Trim(); } else { strLanguage = strLanguage + ", " + other_lang.Text.Trim(); } } if (strSalary.Length > 0) { regEntity.current_salary = strSalary; } if (strLanguage.Length > 0) { regEntity.languages_known = strLanguage; } return(regEntity); }
internal int InsertCandidateRegistration(RegistrationEntity regEntity, DataTable tblEducation, DataTable tblExperence,out int exectuteStatus, out string result) { exectuteStatus = 0; result = ""; int CandId = 0; int res = 0; try { SqlParameter p_id, p_firstName, p_lastName, p_fathersName, p_email, p_gender, p_city, p_state, p_pin, p_date_of_birth, p_mobile, p_languages_known, p_applying_for, p_applying_for_sub_option, p_Address, p_experience, p_key_skills, p_current_salary, p_notice_period, p_ip_address, p_resume_path; p_id = new SqlParameter("@id", SqlDbType.Int); p_id.Direction = ParameterDirection.InputOutput; p_id.Value = 0; p_firstName = new SqlParameter("@firstName", SqlDbType.VarChar, 200); p_firstName.Value = regEntity.firstName; p_lastName = new SqlParameter("@lastName", SqlDbType.VarChar, 200); p_lastName.Value = regEntity.lastName; p_fathersName = new SqlParameter("@fathersName", SqlDbType.VarChar, 200); p_fathersName.Value = regEntity.fathersName; p_email = new SqlParameter("@email", SqlDbType.VarChar, 200); p_email.Value = regEntity.email; p_gender = new SqlParameter("@gender", SqlDbType.VarChar, 200); p_gender.Value = regEntity.gender; p_city = new SqlParameter("@city", SqlDbType.VarChar, 200); p_city.Value = regEntity.city; p_state = new SqlParameter("@state", SqlDbType.VarChar, 200); p_state.Value = regEntity.state; p_pin = new SqlParameter("@pin", SqlDbType.VarChar, 200); p_pin.Value = regEntity.pin; p_date_of_birth = new SqlParameter("@date_of_birth", SqlDbType.VarChar, 200); p_date_of_birth.Value = regEntity.date_of_birth; p_mobile = new SqlParameter("@mobile", SqlDbType.VarChar, 200); p_mobile.Value = regEntity.mobile; p_languages_known = new SqlParameter("@languages_known", SqlDbType.VarChar, 200); p_languages_known.Value = regEntity.languages_known; p_applying_for = new SqlParameter("@applying_for", SqlDbType.VarChar, 200); p_applying_for.Value = regEntity.applying_for; p_applying_for_sub_option = new SqlParameter("@applying_for_sub_option", SqlDbType.VarChar, 200); p_applying_for_sub_option.Value = regEntity.applying_for_sub_option; p_Address = new SqlParameter("@Address", SqlDbType.VarChar, 200); p_Address.Value = regEntity.Address; p_experience = new SqlParameter("@experience", SqlDbType.VarChar, 200); p_experience.Value = regEntity.experience; p_key_skills = new SqlParameter("@key_skills", SqlDbType.VarChar, 200); p_key_skills.Value = regEntity.key_skills; p_current_salary = new SqlParameter("@current_salary", SqlDbType.VarChar, 200); p_current_salary.Value = regEntity.current_salary; p_notice_period = new SqlParameter("@notice_period", SqlDbType.Int); p_notice_period.Value = regEntity.notice_period; p_ip_address = new SqlParameter("@ip_address", SqlDbType.VarChar, 200); p_ip_address.Value = regEntity.ip_address; p_resume_path = new SqlParameter("@resume_path", SqlDbType.VarChar, 200); p_resume_path.Value = regEntity.resume_path; SqlParameter[] parmsArray = { p_id, p_firstName, p_lastName, p_fathersName, p_email, p_gender, p_city, p_state, p_pin, p_date_of_birth, p_mobile, p_languages_known, p_applying_for, p_applying_for_sub_option, p_Address, p_experience, p_key_skills, p_current_salary, p_notice_period, p_ip_address, p_resume_path }; string sqlQuery = "Reg_Candidate_Registration_Proc"; using (SqlConnection mConnection = new SqlConnection(strCon)) { mConnection.Open(); SqlTransaction tn = mConnection.BeginTransaction(); try { using (SqlCommand myCmd = new SqlCommand(sqlQuery, mConnection)) { myCmd.Parameters.AddRange(parmsArray); myCmd.CommandType = CommandType.StoredProcedure; myCmd.Transaction = tn; int s = myCmd.ExecuteNonQuery(); if (s == 1) { //throw new System.ArgumentException("User registration already exist", "original"); } res = s; if (p_id.Value.ToString() != "0") { int.TryParse(p_id.Value.ToString(), out CandId); if (CandId > 1) { regEntity.id = CandId; if (tblEducation != null && tblEducation.Rows.Count > 0) { string degree_name = string.Empty; string specilization = string.Empty; string college_name = string.Empty; string uni_name = string.Empty; string completed_on = string.Empty; string percentage = string.Empty; StringBuilder sCommand = new StringBuilder("insert into candidate_education(id,email,degree_name,specilization,college_name,uni_name,completed_on,percentage) VALUES "); List<string> Rows = new List<string>(); //string[] strNames = { "Id", "DegreeName", "Specialization", "CollegeName", "UniversityName", "YearofPassing", "pcntofmarks" }; try { foreach (DataRow dr in tblEducation.Rows) { degree_name = string.Empty; specilization = string.Empty; college_name = string.Empty; uni_name = string.Empty; completed_on = string.Empty; percentage = string.Empty; degree_name = dr["DegreeName"].ToString(); specilization = dr["Specialization"].ToString(); college_name = dr["CollegeName"].ToString(); uni_name = dr["UniversityName"].ToString(); completed_on = dr["YearofPassing"].ToString(); percentage = dr["pcntofmarks"].ToString(); //InvoiceNo, MID, DTFORMAT, UnitID, PricePerUnit, UnitCount, UnitCost Rows.Add(string.Format("({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}')", regEntity.id, regEntity.email, degree_name, specilization, college_name, uni_name, completed_on, percentage)); } } catch (Exception ex) { throw ex; } sCommand.Append(string.Join(",", Rows)); sCommand.Append(";"); using (SqlCommand myCmd1 = new SqlCommand(sCommand.ToString(), mConnection)) { myCmd1.CommandType = CommandType.Text; myCmd1.Transaction = tn; int s1s1 = myCmd1.ExecuteNonQuery(); res = s1s1; } } if (tblExperence != null && tblExperence.Rows.Count > 0) { string EmployerName = string.Empty; string Employer_Location = string.Empty; string DateStarted = string.Empty; string DateLeft = string.Empty; string JobTitle = string.Empty; StringBuilder sCommand = new StringBuilder("insert into candidate_exp_history(id,email,EmployerName,Employer_Location,DateStarted, DateLeft,JobTitle) VALUES "); List<string> RowsExp = new List<string>(); //string[] strNames = { "Id", "EmployerName", "EmployerLocation", "DateStarted", "DateLeft", "JobTitle" }; try { foreach (DataRow dr in tblExperence.Rows) { EmployerName = string.Empty; Employer_Location = string.Empty; DateStarted = string.Empty; DateLeft = string.Empty; JobTitle = string.Empty; EmployerName = dr["EmployerName"].ToString(); Employer_Location = dr["EmployerLocation"].ToString(); DateStarted = dr["DateStarted"].ToString(); DateLeft = dr["DateLeft"].ToString(); JobTitle = dr["JobTitle"].ToString(); //InvoiceNo, MID, DTFORMAT, UnitID, PricePerUnit, UnitCount, UnitCost RowsExp.Add(string.Format("({0},'{1}','{2}','{3}','{4}','{5}','{6}')", regEntity.id, regEntity.email, EmployerName, Employer_Location, DateStarted, DateLeft, JobTitle)); } } catch (Exception ex) { throw ex; } sCommand.Append(string.Join(",", RowsExp)); sCommand.Append(";"); using (SqlCommand myCmd2 = new SqlCommand(sCommand.ToString(), mConnection)) { myCmd2.CommandType = CommandType.Text; myCmd2.Transaction = tn; int s2s2 = myCmd2.ExecuteNonQuery(); res = s2s2; } } } } } tn.Commit(); result = "Saved successfully"; exectuteStatus = 1; //SqlParameter p_locationID = new SqlParameter("@LocationID", SqlDbType.Int64); //p_locationID.Value = invoiceFiels.LocationID; //SqlParameter p_invoiceDate = new SqlParameter("@InvoiceDate", SqlDbType.DateTime); //p_invoiceDate.Value = invoiceFiels.InvoiceDate; //SqlParameter[] parmsArray1 = { p_locationID, p_invoiceDate }; //string sqlQuery1 = "update tbl_Invoice_Status set DBStatus=1 where InvoiceNo= concat(@LocationID,DATE_FORMAT(@InvoiceDate,'%m%d%Y'));"; //using (SqlCommand myCmd2 = new SqlCommand(sqlQuery1, mConnection)) //{ // myCmd2.CommandType = CommandType.Text; // myCmd2.Parameters.AddRange(parmsArray1); // int sres = myCmd2.ExecuteNonQuery(); // //res = s1s1; //} res = 1; } catch (Exception ex) { tn.Rollback(); res = 0; exectuteStatus = 0; result = ex.Message.Replace("'", ""); } finally { mConnection.Close(); } } } catch (Exception ex) { res = 0; exectuteStatus = 0; result = ex.Message.Replace("'", ""); } return res; }
/// <summary> /// To save the user registration details to tables /// </summary> protected void btnPostResume_Click(object sender, EventArgs e) { if (!mainCheck.Checked) { mainCheck.Focus(); Page.ClientScript.RegisterStartupScript(typeof(Page), "marin1", "alert('you have to accept the declaration, please check check box.!');", true); return; } string[] strEmpty = { "firstName", "lastName", "mobile", "email", "date_of_birth", "Address", "city", "pin", "notice_period" }; foreach (string str in strEmpty) { var ctrl = form1.FindControl(str); if (ctrl != null) { TextBox txt = ctrl as TextBox; if (txt != null && txt.Text.Trim().Length == 0) { txt.Focus(); Page.ClientScript.RegisterStartupScript(typeof(Page), "marin1", "alert('" + str + " cannot be empty.!');", true); return; } } } if (email.Text.Trim().Length > 0) { bool usrstatus = false; UserDetails umbl = new UserDetails(); usrstatus = umbl.Check_Candidate_Registration(email.Text.Trim()); umbl = null; if (usrstatus) { Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", "alert('Your registration details already exist, you cannot register again!!');", true); return; } } if (applying_for.SelectedIndex == 0) { experience.Focus(); Page.ClientScript.RegisterStartupScript(typeof(Page), "marinexp1", "alert('Please select the Applying For drop down.!');", true); return; } if (experience.SelectedIndex == 0) { experience.Focus(); Page.ClientScript.RegisterStartupScript(typeof(Page), "marinexp1", "alert('Please select the experience drop down.!');", true); return; } string strMonth = DateTime.Now.Date.ToString("MM_yyyy"); string updPath = Path.Combine(ResumePath, strMonth); string resume_path = string.Empty; if (upload_resume.HasFile) { string extension = Path.GetExtension(upload_resume.PostedFile.FileName); if (extension.ToLower() == ".pdf" || extension.ToLower() == ".docx") { string resumename = email.Text + extension; if (!Directory.Exists(updPath)) { Directory.CreateDirectory(updPath); } resume_path = Path.Combine(updPath, resumename); upload_resume.SaveAs(resume_path); } else { Page.ClientScript.RegisterStartupScript(typeof(Page), "marin1", "alert('upload resume allowed only pdf/docx extension');", true); return; } } //check validations; RegistrationEntity regEntity = GetControlData(); if (resume_path != string.Empty) { regEntity.resume_path = resume_path; } DataTable tblEducation = GetEducationData(); if (tblEducation == null || tblEducation.Rows.Count == 0) { Page.ClientScript.RegisterStartupScript(typeof(Page), "marined", "alert('Please enter the Education Details.');", true); return; } //string[] strNames = { "Id", "DegreeName", "Specialization", "CollegeName", "UniversityName", "YearofPassing", "pcntofmarks" }; foreach (DataRow dr in tblEducation.Rows) { if (dr["DegreeName"].ToString() == "" || dr["DegreeName"].ToString() == null) { Page.ClientScript.RegisterStartupScript(typeof(Page), "marin1", "alert('Please select the Degree Name.');", true); return; } if ((dr["CollegeName"].ToString().Length == 0) || (dr["UniversityName"].ToString().Length == 0) || (dr["YearofPassing"].ToString().Length == 0) || (dr["pcntofmarks"].ToString().Length == 0)) { Page.ClientScript.RegisterStartupScript(typeof(Page), "marincu", "alert('CollegeName, UniversityName,YearofPassing,%ofmarks cannot be empty.');", true); return; } } DataTable tblExperence = GetExperenceData(); Registration blReg = new Registration(); int ExectuteStatus = 0; string Result = string.Empty; int res = blReg.InsertCandidateRegistration(regEntity, tblEducation, tblExperence, out ExectuteStatus, out Result); blReg = null; if (ExectuteStatus == 1) { Page.ClientScript.RegisterStartupScript(typeof(Page), "ressuss", "alert('User registration form submitted successfully');", true); System.Threading.Thread.Sleep(10000); //Response.Redirect("UserRegistration.aspx"); } else { Page.ClientScript.RegisterStartupScript(typeof(Page), "reserro", "alert('" + Result.Replace("'", "") + "');", true); } }