private void btnView_Click(object sender, EventArgs e) { try { ReportDocument CrRep = new ReportDocument(); CRT2 = ""; CRT3 = ""; fnd = false; DateTime edt1 = dt1.Value; DateTime edt2 = dt2.Value;; // string sdt2 = string.Format("yyyy,MM,dd,00,00,00", Gvar.ArCalendar(dt2.Value, true)); string adate1 = dt1.Value.Date.ToString("dd-MM-yyyy"); string adate2 = dt2.Value.Date.ToString("dd-MM-yyyy"); string sdt1 = edt1.Date.ToString("yyyy,MM,dd,00,00,00"); string sdt2 = edt2.Date.ToString("yyyy,MM,dd,23,59,59"); string hd3; hd3 = "'Report'"; crt1 = ""; switch (Gvar._Gind) { case 1: { rep_path = Gvar.report_path + "\\reports\\RepProject.rpt"; CrRep.Load(rep_path); //DateTime edt1 = Convert.ToDateTime(Gvar.ArCalendar(dt1.Value, true,false)); //DateTime edt2 = Convert.ToDateTime(Gvar.ArCalendar(dt2.Value, true,false)); goto nxt; string rdt1 = dt1.Value.ToString("dd/MM/yyyy"); string rdt2 = dt2.Value.ToString("dd/MM/yyyy"); if (!chkdate.Checked) { crt1 = " {TRN_ACCOUNTS.PAY_DATE} in DateTime (" + sdt1 + ") to DateTime (" + sdt2 + ")"; RPTHEAD = "Account Summary From " + rdt1 + " To " + rdt2; } else { RPTHEAD = "Account Summary Report for All Dates"; crt1 = ""; } //crt1 = crt1 + " And ({QRY_ITEM.TRN_TYPE} = 2 Or {QRY_ITEM.TRN_TYPE} =8)"; string crt2 = ""; if (cmbowner.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt2 = "{accounts.acc_type_code} = " + cmbowner.SelectedValue; RPTHEAD = RPTHEAD + " for Type " + cmbowner.Text; } fnd = false; string crt4 = ""; lst1.EndEdit(); int i = 0; if (chklst1.Checked) { //crt4 = "{accounts.acc_no} <> -1"; fnd = true; } else { for (i = 0; i < lst1.RowCount; i++) { if (lst1[0, i].Value != null) { if ((bool)lst1[0, i].Value) { if (crt4 == "") { crt4 = lst1[2, i].Value.ToString(); } else { crt4 = crt4 + "," + lst1[2, i].Value.ToString(); } fnd = true; } } } crt4 = "{accounts.acc_no} in [" + crt4 + "]"; RPTHEAD = RPTHEAD + ", for Accounts " + crt4; } if (!fnd) { MessageBox.Show("There is No Accounts selected, Please Try AGain", "Wrong Selection"); return; } fnd = false; string crt3 = ""; lst2.EndEdit(); //if (chklst2.Checked) //{ // // crt3 = "{accounts.acc_no} <> -1"; // fnd = true; //} //else //{ // for (i = 0; i < lst2.RowCount; i++) // { // if (lst2[0, i].Value != null) // { // if ((bool)lst2[0, i].Value) // { // if (crt3 == "") // { // crt3 = lst2[1, i].Value.ToString(); // } // else // { // crt3 = crt3 + "," + lst2[1, i].Value.ToString(); // } // fnd = true; // } // } // } // crt3 = "{TRN_accounts.acc_no} in [" + crt3 + "]"; //} //if (!fnd) //{ // MessageBox.Show("There is No Account selected, Please Try Again", "Wrong Vehicle Selection"); // return; //} string crt5 = ""; if (cmbsaleagent.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt5 = "{accounts.account_link} = " + cmbsaleagent.SelectedValue; RPTHEAD = RPTHEAD + " for Saleagent " + cmbsaleagent.Text; } string crt6 = ""; if (cmblocaltion.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt6 = "{accounts_info.area_name} = '" + cmblocaltion.Text + "'"; RPTHEAD = RPTHEAD + " for Area " + cmblocaltion.Text; } string crt = ""; if (crt1 != "") { if (crt != "") { crt = crt + " aND " + crt1; } else { crt = crt1; } } if (crt2 != "") { if (crt != "") { crt = crt + " aND " + crt2; } else { crt = crt2; } } if (crt3 != "") { if (crt != "") { crt = crt + " aND " + crt3; } else { crt = crt3; } } // if (crt3 != "") crt = crt + " aND " + crt3; //if (crt4 != "") crt = crt + " aND " + crt4; //crt = crt + " aND " + crt4 + " AND {DATA_ENTRY.TRN_TYPE} = 7"; if (crt4 != "") { if (crt != "") { crt = crt + " aND " + crt4; } else { crt = crt4; } } if (crt5 != "") { if (crt != "") { crt = crt + " aND " + crt5; } else { crt = crt5; } } if (crt6 != "") { if (crt != "") { crt = crt + " aND " + crt6; } else { crt = crt6; } } //if (crt1 != "") crt2 = crt1 + " And " + crt2; rep_formula = crt; // 2 + " aND " + crt3 + " aND " + crt4;// +" AND {QRY_ITEM.QTY}<>0"; CrRep.SummaryInfo.ReportTitle = RPTHEAD; // "Account Detail Report from " + rdt1 + " To " + rdt2; if (cmbtransaction.SelectedIndex == 1) { if (crt == "") { rep_formula = "{TRN_accounts.DR_CR}='D'"; } else { rep_formula = crt + " AND {TRN_accounts.DR_CR}='D'"; } CrRep.SummaryInfo.ReportTitle = RPTHEAD + " , FOR " + cmbtransaction.Text; } if (cmbtransaction.SelectedIndex == 2) { if (crt == "") { rep_formula = "{TRN_accounts.DR_CR}='C'"; } else { rep_formula = crt + " AND {TRN_accounts.DR_CR}='C'"; } CrRep.SummaryInfo.ReportTitle = RPTHEAD + " , FOR " + cmbtransaction.Text; } nxt :; } break; case 2: { rep_path = Gvar.report_path + "\\reports\\repacctrans.rpt"; CrRep.Load(rep_path); //DateTime edt1 = Convert.ToDateTime(Gvar.ArCalendar(dt1.Value, true,false)); //DateTime edt2 = Convert.ToDateTime(Gvar.ArCalendar(dt2.Value, true,false)); string rdt1 = dt1.Value.ToString("dd/MM/yyyy"); string rdt2 = dt2.Value.ToString("dd/MM/yyyy"); if (!chkdate.Checked) { crt1 = " {TRN_ACCOUNTS.PAY_DATE} in DateTime (" + sdt1 + ") to DateTime (" + sdt2 + ")"; RPTHEAD = "Account Detail From " + rdt1 + " To " + rdt2; } else { RPTHEAD = "Accounts Detail Report for All Date "; } //crt1 = crt1 + " And ({QRY_ITEM.TRN_TYPE} = 2 Or {QRY_ITEM.TRN_TYPE} =8)"; string crt2 = ""; if (cmbowner.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt2 = "{accounts.acc_type_code} = " + cmbowner.SelectedValue; RPTHEAD = RPTHEAD + ", for Type " + cmbowner.Text; } fnd = false; string crt4 = ""; lst1.EndEdit(); int i = 0; if (chklst1.Checked) { //crt4 = "{accounts.acc_no} <> -1"; fnd = true; } else { for (i = 0; i < lst1.RowCount; i++) { if (lst1[0, i].Value != null) { if ((bool)lst1[0, i].Value) { if (crt4 == "") { crt4 = lst1[2, i].Value.ToString(); } else { crt4 = crt4 + "," + lst1[2, i].Value.ToString(); } fnd = true; } } } crt4 = "{accounts.acc_no} in [" + crt4 + "]"; } if (!fnd) { MessageBox.Show("There is No Accounts selected, Please Try AGain", "Wrong Selection"); return; } fnd = false; string crt3 = ""; lst2.EndEdit(); //if (chklst2.Checked) //{ // //crt3 = "{accounts.acc_no} <> -1"; // fnd = true; //} //else //{ // for (i = 0; i < lst2.RowCount; i++) // { // if (lst2[0, i].Value != null) // { // if ((bool)lst2[0, i].Value) // { // if (crt3 == "") // { // crt3 = lst2[1, i].Value.ToString() ; // } // else // { // crt3 = crt3 + "," + lst2[1, i].Value.ToString(); // } // fnd = true; // } // } // } // crt3 = "{TRN_accounts.acc_no} in [" + crt3 + "]"; //} //if (!fnd) //{ // MessageBox.Show("There is No vehicle selected, Please Try Again", "Wrong Vehicle Selection"); // return; //} string crt5 = ""; if (cmbsaleagent.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt5 = "{accounts.account_link} = " + cmbsaleagent.SelectedValue; RPTHEAD = RPTHEAD + " for Saleagent " + cmbsaleagent.Text; } string crt6 = ""; if (cmblocaltion.SelectedIndex < 1) { // crt2 = "{accounts.acc_type_code} <> -1"; } else { crt6 = "{accounts_info.area_name} = '" + cmblocaltion.Text + "'"; RPTHEAD = RPTHEAD + " for Area " + cmblocaltion.Text; } string crt = ""; if (crt1 != "") { if (crt != "") { crt = crt + " aND " + crt1; } else { crt = crt1; } } if (crt2 != "") { if (crt != "") { crt = crt + " aND " + crt2; } else { crt = crt2; } } if (crt3 != "") { if (crt != "") { crt = crt + " aND " + crt3; } else { crt = crt3; } } // if (crt3 != "") crt = crt + " aND " + crt3; //if (crt4 != "") crt = crt + " aND " + crt4; //crt = crt + " aND " + crt4 + " AND {DATA_ENTRY.TRN_TYPE} = 7"; if (crt4 != "") { if (crt != "") { crt = crt + " aND " + crt4; } else { crt = crt4; } } if (crt5 != "") { if (crt != "") { crt = crt + " aND " + crt5; } else { crt = crt5; } } if (crt6 != "") { if (crt != "") { crt = crt + " aND " + crt6; } else { crt = crt6; } } //if (crt1 != "") crt2 = crt1 + " And " + crt2; rep_formula = crt; // 2 + " aND " + crt3 + " aND " + crt4;// +" AND {QRY_ITEM.QTY}<>0"; //rep_formula = crt1 + " aND " + crt2 + " aND " + crt3 + " and " + crt4; //" AND {QRY_ITEM.QTY}<>0"; CrRep.SummaryInfo.ReportTitle = RPTHEAD; // "Account Detail Report from " + rdt1 + " To " + rdt2; if (cmbtransaction.SelectedIndex == 1) { if (crt == "") { rep_formula = "{TRN_accounts.DR_CR}='D'"; } else { rep_formula = crt + " AND {TRN_accounts.DR_CR}='D'"; } CrRep.SummaryInfo.ReportTitle = RPTHEAD + ", For Trans of " + cmbtransaction.Text; } if (cmbtransaction.SelectedIndex == 2) { if (crt == "") { rep_formula = "{TRN_accounts.DR_CR}='C'"; } else { rep_formula = crt + " AND {TRN_accounts.DR_CR}='C'"; } CrRep.SummaryInfo.ReportTitle = RPTHEAD + ", For Trans of " + cmbtransaction.Text; } if (!cmbdept.Visible) { CrRep.ReportDefinition.Sections[5].SectionFormat.EnableSuppress = true; CrRep.ReportDefinition.Sections[6].SectionFormat.EnableSuppress = true; CrRep.ReportDefinition.Sections[9].SectionFormat.EnableSuppress = true; CrRep.ReportDefinition.Sections[10].SectionFormat.EnableSuppress = true; } if (!panel2.Visible) { } if (chkinvoice.Checked) // CrRep.GetComponentName("invoice") { string sec = CrRep.ReportDefinition.Sections[8].Name; CrRep.ReportDefinition.Sections[8].SectionFormat.EnableSuppress = false; } } break; } //if (CRT4 != "") // rep_formula = rep_formula + " AND " + CRT4; CrRep.Load(rep_path); //MessageBox.Show(rep_formula); CrRep.ReportOptions.EnableSaveDataWithReport = false; CrystalDecisions.Shared.ConnectionInfo crconnectioninfo = new CrystalDecisions.Shared.ConnectionInfo(); CrystalDecisions.Shared.TableLogOnInfos crtablelogoninfos = new CrystalDecisions.Shared.TableLogOnInfos(); CrystalDecisions.Shared.TableLogOnInfo crtablelogoninfo = new CrystalDecisions.Shared.TableLogOnInfo(); Tables CrTables; crconnectioninfo.ServerName = decoder.DataSource; crconnectioninfo.DatabaseName = decoder.InitialCatalog; crconnectioninfo.UserID = decoder.UserID; crconnectioninfo.Password = decoder.Password; //crconnectioninfo.ServerName = "Mujeeb-pc"; //crconnectioninfo.DatabaseName = "sqlStockex"; //crconnectioninfo.UserID = "sa"; //crconnectioninfo.Password = "******"; CrTables = CrRep.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtablelogoninfo = CrTable.LogOnInfo; crtablelogoninfo.ConnectionInfo = crconnectioninfo; CrTable.ApplyLogOnInfo(crtablelogoninfo); } CrRep.SetDatabaseLogon(decoder.UserID, decoder.Password, decoder.DataSource, decoder.InitialCatalog); if (rep_formula != "") { CrRep.RecordSelectionFormula = rep_formula; } CrRep.SummaryInfo.ReportTitle = RPTHEAD; // crystalReportViewer.ReportSource = reportDocument; //ConnectionInfo connInfo = new ConnectionInfo(); //connInfo.ServerName = "dbservername"; //connInfo.DatabaseName = "dbname"; //connInfo.UserID = "dbusername"; //connInfo.Password = "******"; //reportViewer.ReportSource = GetReportSource(connInfo); //reportViewer.RefreshReport(); // CrRep.Database.SetDataSource (db) // CrRep.VerifyOnEveryPrint = False //CrRep.DiscardSavedData //CrRep.ReadRecords //CrRep.Load(rep_path); //Crv1.ReportSource = CrRep; //Crv1.Width = this.Width; FrmrepView frm = new FrmrepView(); frm.MdiParent = this.ParentForm; frm.crv1.ReportSource = CrRep; frm.Show(); //Control[] ctrls = frm.Controls.Find("crv1", false); //if (ctrls.Length > 0) //{ // CrystalDecisions.Windows.Forms.CrystalReportViewer rep = (CrystalDecisions.Windows.Forms.CrystalReportViewer) ctrls[0]; // rep.ReportSource = CrRep; // frm.Show(); //} CrRep.SetDatabaseLogon(decoder.UserID, decoder.Password, "Mujeeb", decoder.InitialCatalog); //FRMREPORT.CRV1.ReportSource = CrRep //FRMREPORT.CRV1.Refresh //FRMREPORT.CRV1.RefreshEx (True) //FRMREPORT.CRV1.ViewReport //FRMREPORT.Show } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void print_Report(int idx) { string crt; string rep_path; bool fnd = false; try { ReportDocument CrRep = new ReportDocument(); rep_path = ""; crt = ""; switch (idx) { case 1: { //crt = "{Reciepts.Reciept_no} =" + Convert.ToDouble(Txtitem.Text); rep_path = Gvar.report_path + "\\reports\\ItemMasterN.rpt"; CrRep.Load(rep_path); CrRep.SummaryInfo.ReportTitle = "Material Stock Report for all"; } break; } //crconnectioninfo.ServerName = "Mujeeb"; //crconnectioninfo.DatabaseName = "Printex"; //crconnectioninfo.UserID = "sa"; //crconnectioninfo.Password = "******"; //CrRep.PrintOptions.PaperSize= CrystalDecisions.Shared.PaperSize.PaperEnvelope10; if (crt != "") { CrRep.RecordSelectionFormula = crt; } CrystalDecisions.Shared.ConnectionInfo crconnectioninfo = new CrystalDecisions.Shared.ConnectionInfo(); CrystalDecisions.Shared.TableLogOnInfos crtablelogoninfos = new CrystalDecisions.Shared.TableLogOnInfos(); CrystalDecisions.Shared.TableLogOnInfo crtablelogoninfo = new CrystalDecisions.Shared.TableLogOnInfo(); Tables CrTables; crconnectioninfo.ServerName = decoder.DataSource; crconnectioninfo.DatabaseName = decoder.InitialCatalog; crconnectioninfo.UserID = decoder.UserID; crconnectioninfo.Password = decoder.Password; CrTables = CrRep.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtablelogoninfo = CrTable.LogOnInfo; crtablelogoninfo.ConnectionInfo = crconnectioninfo; CrTable.ApplyLogOnInfo(crtablelogoninfo); } //CrRep.SetDatabaseLogon(decoder.UserID, decoder.Password, decoder.DataSource, decoder.InitialCatalog); //CrRep.Load(); //CrRep.ReadRecords(); //CrRep.Refresh(); //if (chkprinter.Checked) //{ // CrRep.PrintToPrinter(1, true, 0, 0); //} //else //{ FrmrepView frm = new FrmrepView(); frm.MdiParent = this.ParentForm; frm.crv1.ReportSource = CrRep; frm.Show(); //} //ConnectionInfo connInfo = new ConnectionInfo(); //connInfo.ServerName = "dbservername"; //connInfo.DatabaseName = "dbname"; //connInfo.UserID = "dbusername"; //connInfo.Password = "******"; //reportViewer.ReportSource = GetReportSource(connInfo); CrRep.SetDatabaseLogon(decoder.UserID, decoder.Password, "Mujeeb", decoder.InitialCatalog); //CrRep.Load(); // CrRep.ReadRecords(); //CrRep.Refresh(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); } }
private void print_reciept() { string crt; string rep_path; fnd = false; try { ReportDocument CrRep = new ReportDocument(); rep_path = Application.StartupPath + "\\reports\\Rptsalary.rpt"; CrRep.Load(rep_path); //CrRep.PrintOptions.PaperSize= CrystalDecisions.Shared.PaperSize.PaperEnvelope10; crt = "{SALARY_DET.SALARY_MONTH} = '" + 0 + "'"; if (crt != "") { CrRep.RecordSelectionFormula = crt; } //CrRep.VerifyDatabase = false; CrystalDecisions.Shared.ConnectionInfo crconnectioninfo = new CrystalDecisions.Shared.ConnectionInfo(); CrystalDecisions.Shared.TableLogOnInfos crtablelogoninfos = new CrystalDecisions.Shared.TableLogOnInfos(); CrystalDecisions.Shared.TableLogOnInfo crtablelogoninfo = new CrystalDecisions.Shared.TableLogOnInfo(); Tables CrTables; crconnectioninfo.ServerName = decoder.DataSource; //crconnectioninfo.ServerName = "SqlZoomERP"; crconnectioninfo.DatabaseName = decoder.InitialCatalog; crconnectioninfo.UserID = decoder.UserID; crconnectioninfo.Password = decoder.Password; CrTables = CrRep.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtablelogoninfo = CrTable.LogOnInfo; crtablelogoninfo.ConnectionInfo = crconnectioninfo; CrTable.ApplyLogOnInfo(crtablelogoninfo); } CrRep.SummaryInfo.ReportTitle = "Salary Report for Month "; //CrRep.DataDefinition.FormulaFields["shipaddress"].Text = "'" + cmbaddress.Text + "'"; // CrRep.SetDatabaseLogon(decoder.UserID, decoder.Password, decoder.DataSource, decoder.InitialCatalog); CrRep.ReadRecords(); //CrRep.Load(); // CrRep.ReadRecords(); CrRep.Refresh(); //if (chkprinter.Checked) //{ // CrRep.PrintToPrinter(1, true, 0, 0); //} //else //{ if (chkprintview.Checked) { FrmrepView frm = new FrmrepView(); frm.MdiParent = this.ParentForm; frm.crv1.ReportSource = CrRep; frm.Show(); return; } CrRep.PrintToPrinter(1, true, 0, 0); return; //} } catch (System.Exception excep) { MessageBox.Show(excep.Message); } }