private void Print_NIC() { try { string NIC = dgvNIC.CurrentRow.Cells[3].Value.ToString(); Community.DBLayer dblayer = new Community.DBLayer(); SqlConnection con = new SqlConnection(Community.DBLayer.con_String); string query = richTextBox1.Text; string query1 = "NIC = '" + NIC + "'"; query = query.Replace("NIC = @NIC", query1); SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; DataTable dt = new DataTable(); SqlDataAdapter ada = new SqlDataAdapter(cmd); ada.Fill(dt); MCKJ.Reports.Members.frmViewer frm = new MCKJ.Reports.Members.frmViewer(); MCKJ.Reports.Members.rptNIC rpt = new MCKJ.Reports.Members.rptNIC(); rpt.SetDataSource(dt); frm.crystalReportViewer1.ReportSource = rpt; frm.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnShow_Click(object sender, EventArgs e) { int chk_Query = 0; string Filter = ""; string Query = "Select *,tblFamily.Sign,tblFamily.Nukh,tblFamily.City,tblFamily.Area,tblFamily.Country, tblNIC.ISNICPrinted from tblFamilyMember INNER JOIN tblFamily ON tblFamilyMember.FCardNo = tblFamily.FCardNo LEFT JOIN tblNIC ON tblFamilyMember.FamilyMemberID = tblnic.MemberID "; if (chkAll.Checked != true) { if (chkName.Checked) { int length = txtName.Text.Length; if (chk_Query == 0) { Query = Query + "Where Left(tblFamilyMember.MemberName," + length + ") ='" + txtName.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Name = " + txtName.Text; } else { Query = Query + "AND Left(tblFamilyMember.MemberName," + length + ") ='" + txtName.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Name = " + txtName.Text; } } if (chkCMIC.Checked) { int length = txtCMIC.Text.Length; if (chk_Query == 0) { Query = Query + "Where RIGHT(tblFamilyMember.NIC," + length + ") ='" + txtCMIC.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By CommCard = " + txtCMIC.Text; } else { Query = Query + "AND RIGHT(tblFamilyMember.NIC," + length + ") ='" + txtCMIC.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; CommCard = " + txtCMIC.Text; } } if (chkStatus.Checked) { int BOOL = 0; if (cmbStatus.Text == "Active") { BOOL = 1; } else { BOOL = 0; } if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.Active =" + BOOL; chk_Query = chk_Query + 1; if (BOOL == 1) { Filter = "Filter By Status = Active"; } else { Filter = "Filter By Status = In-Active"; } } else { Query = Query + "AND tblFamilyMember.Active =" + BOOL; chk_Query = chk_Query + 1; if (BOOL == 1) { Filter = Filter + "; Status = Active"; } else { Filter = Filter + "; Status = In-Active"; } } } if (chkAgeGroup.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.AgeGroup ='" + cmbAdult.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Age-Group = " + cmbAdult.Text; } else { Query = Query + "AND tblFamilyMember.AgeGroup ='" + cmbAdult.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Age-Group = " + cmbAdult.Text; } } if (chkArea.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamily.Area ='" + cmbArea.Text + "' ";; chk_Query = chk_Query + 1; Filter = "Filter By Area = " + cmbArea.Text; } else { Query = Query + "AND tblFamily.Area ='" + cmbArea.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Area = " + cmbArea.Text; } } if (chkBloodGroup.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.BloodGroup ='" + cmbBGroup.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Blood Group = " + cmbBGroup.Text; } else { Query = Query + "AND tblFamilyMember.BloodGroup ='" + cmbBGroup.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Blood Group = " + cmbBGroup.Text; } } if (chkCity.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamily.City ='" + cmbCity.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By City = " + cmbCity.Text; } else { Query = Query + "AND tblFamily.City ='" + cmbCity.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; City = " + cmbCity.Text; } } if (chkFCard.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.FCardNo ='" + txtFCardNo.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By CardNo = " + txtFCardNo.Text; } else { Query = Query + "AND tblFamilyMember.FCardNo ='" + txtFCardNo.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; CardNo = " + txtFCardNo.Text; } } if (chkGender.Checked) { if (chk_Query == 0) { Query = Query + "WHERE tblFamilyMember.Gender ='" + cmbGender.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Gender = " + cmbGender.Text; } else { Query = Query + "AND tblFamilyMember.Gender ='" + cmbGender.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Gender = " + cmbGender.Text; } } if (chkMaritalStatus.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.MaritalStatus ='" + cmbMaritalStatus.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Marital Status = " + cmbMaritalStatus.Text; } else { Query = Query + "AND tblFamilyMember.MaritalStatus ='" + cmbMaritalStatus.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Marital Status = " + cmbMaritalStatus.Text; } } if (chkNukh.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamily.Nukh ='" + cmbNukh.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Nukh = " + cmbNukh.Text; } else { Query = Query + "AND tblFamily.Nukh ='" + cmbNukh.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Nukh = " + cmbNukh.Text; } } if (chkOrakh.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamily.Sign ='" + cmbSign.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Orakh = " + cmbSign.Text; } else { Query = Query + "AND tblFamily.Sign ='" + cmbSign.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Orakh = " + cmbSign.Text; } } if (chkOutOf.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.Outof ='" + cmbOutof.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Out-OF = " + cmbOutof.Text; } else { Query = Query + "AND tblFamilyMember.Outof ='" + cmbOutof.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Out-OF = " + cmbOutof.Text; } } if (chkRelation.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.LeaderRelation ='" + cmbRelation.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Relation = " + cmbRelation.Text; } else { Query = Query + "AND tblFamilyMember.LeaderRelation ='" + cmbRelation.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Relation = " + cmbRelation.Text; } } if (chkVillage.Checked) { if (chk_Query == 0) { Query = Query + "tblFamily.Village ='" + cmbVillage.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By Origin = " + cmbVillage.Text; } else { Query = Query + "AND tblFamily.Village ='" + cmbVillage.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; Origin = " + cmbVillage.Text; } } if (chkWorkType.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.WorkType ='" + cmbTypeWork.Text + "'"; chk_Query = chk_Query + 1; Filter = "Filter By Work Type = " + cmbTypeWork.Text; } else { Query = Query + "AND tblFamilyMember.WorkType ='" + cmbTypeWork.Text + "'"; chk_Query = chk_Query + 1; Filter = Filter + ";Work Type = " + cmbTypeWork.Text; } } if (chkCNIC.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.CNIC ='" + txtCNIC.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By CNIC = " + txtCNIC.Text; } else { Query = Query + "AND tblFamilyMember.CNIC ='" + txtCNIC.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; CNIC = " + txtCNIC.Text; } } if (chkDOB.Checked) { if (chk_Query == 0) { Query = Query + "Where tblFamilyMember.DOB ='" + dtpDOB.Text + "' "; chk_Query = chk_Query + 1; Filter = "Filter By DOB = " + dtpDOB.Text; } else { Query = Query + "AND tblFamilyMember.DOB ='" + dtpDOB.Text + "' "; chk_Query = chk_Query + 1; Filter = Filter + "; DOB = " + dtpDOB.Text; } } } Query = Query + "Order by tblFamily.FCardNo asc"; try { SqlConnection conn = new SqlConnection(Community.DBLayer.con_String); conn.Open(); SqlCommand cmd = new SqlCommand(Query, conn); DataTable dt = new DataTable(); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt); MCKJ.Reports.Members.frmViewer frm = new MCKJ.Reports.Members.frmViewer(); MCKJ.Reports.Members.rptCustom rpt = new MCKJ.Reports.Members.rptCustom(); frm.crystalReportViewer1.ReportSource = rpt; rpt.SetDataSource(dt); rpt.SetParameterValue(0, Filter); frm.Show(); conn.Close(); } catch (Exception ex) { MessageBox.Show("AN unknown error occured \n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void Print_NIC() { try { string[] Query = { "", "", "", "" }; if (txtCMIC1.Text == "" && txtCMIC2.Text == "" && txtCMIC3.Text == "" && txtCMIC4.Text == "") { MessageBox.Show("Please enter atleast One Community ID Card Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (txtCMIC1.Text != "") { Query[0] = "RIGHT(tblNIC.NIC,5) = '" + txtCMIC1.Text + "'"; } if (txtCMIC2.Text != " - -") { Query[1] = "RIGHT(tblNIC.NIC,5) = '" + txtCMIC2.Text + "'"; } if (txtCMIC3.Text != " - -") { Query[2] = "RIGHT(tblNIC.NIC,5) = '" + txtCMIC3.Text + "'"; } if (txtCMIC4.Text != " - -") { Query[3] = "RIGHT(tblNIC.NIC,5) = '" + txtCMIC4.Text + "'"; } string QUERY = ""; for (int x = 0; x < 4; x++) { if (QUERY == "") { if (Query[x] != "") { QUERY += Query[x] + " "; } } else { if (Query[x] != "") { QUERY += " OR " + Query[x]; } } } int len = QUERY.Length; Community.DBLayer dblayer = new Community.DBLayer(); SqlConnection con = new SqlConnection(Community.DBLayer.con_String); string query = richTextBox1.Text; query = query.Replace("NIC = @NIC", QUERY); SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; DataTable dt = new DataTable(); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { con.Close(); SqlDataAdapter ada = new SqlDataAdapter(cmd); ada.Fill(dt); MCKJ.Reports.Members.frmViewer frm = new MCKJ.Reports.Members.frmViewer(); MCKJ.Reports.Members.rptNIC rpt = new MCKJ.Reports.Members.rptNIC(); MCKJ.Reports.Members.rptNIC_back rptBack = new MCKJ.Reports.Members.rptNIC_back(); rpt.SetDataSource(dt); rptBack.SetDataSource(dt); frm.crystalReportViewer1.ReportSource = rpt; frm._nicbackbuttonvisible = true; frm._rptNICback = rptBack; frm._rptNICfront = rpt; frm.Show(); } else { MessageBox.Show("No record to preview please enter other ID Card No.s", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information); con.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }