Ejemplo n.º 1
0
        public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            群組_總表NEW1 rpt = new 群組_總表NEW1();

            rpt.Site = this.Site;
            return(rpt);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton5.Checked == false)
            {
                if (string.IsNullOrEmpty(naviTextBox3.Text))
                {
                    MessageBox.Show("列印項目未填 !!", "更新訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (string.IsNullOrEmpty(naviTextBox2.Text))
                {
                    MessageBox.Show("申請月份未填 !!", "更新訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DataSet 群組報表 = new DataSet();

            // 判斷groupbox裡面必須點選一個radiobutton
            //var buttons = groupBox1.Controls.OfType<RadioButton>().FirstOrDefault(n => n.Checked);

            if (radioButton4.Checked)
            {
                Ad = new SqlDataAdapter("PUR2007NET_群組列印_無科目", GonGinVariable.SqlConnectString);
                Ad.SelectCommand.CommandType    = CommandType.StoredProcedure;
                Ad.SelectCommand.CommandTimeout = 600;
                Ad.SelectCommand.Parameters.Clear();
                Ad.SelectCommand.Parameters.Add("@BGYM", SqlDbType.VarChar).Value = naviTextBox2.Text;
                Ad.SelectCommand.Parameters.Add("@項目", SqlDbType.VarChar).Value   = naviTextBox3.Text;
                群組報表.Clear();
                Ad.Fill(群組報表);

                群組_總表無科目 Reporter1 = new 群組_總表無科目();
                //Reporter1.SetDataSource(Dt_明細);
                Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                Form ReportForm = new Form();
                CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                CryReport.ReportSource = Reporter1;
                CryReport.Dock         = DockStyle.Fill;
                Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);

                ReportForm.Controls.Add(CryReport);
                ReportForm.WindowState = FormWindowState.Maximized;
                ReportForm.Show();
            }
            else if (radioButton5.Checked)
            {
                Ad = new SqlDataAdapter("PUR2007NET_群組列印_大群", GonGinVariable.SqlConnectString);
                Ad.SelectCommand.CommandType    = CommandType.StoredProcedure;
                Ad.SelectCommand.CommandTimeout = 600;
                Ad.SelectCommand.Parameters.Clear();
                Ad.SelectCommand.Parameters.Add("@BGYM", SqlDbType.VarChar).Value  = naviTextBox2.Text;
                Ad.SelectCommand.Parameters.Add("@SBGNO", SqlDbType.VarChar).Value = "";
                群組報表.Clear();
                Ad.Fill(群組報表);


                群組_大群總表 Reporter1 = new 群組_大群總表();
                //Reporter1.SetDataSource(Dt_明細);
                Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                Form ReportForm = new Form();
                CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                CryReport.ReportSource = Reporter1;
                CryReport.Dock         = DockStyle.Fill;
                Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");

                ReportForm.Controls.Add(CryReport);
                ReportForm.WindowState = FormWindowState.Maximized;
                ReportForm.Show();
            }
            else if (radioButton6.Checked)
            {
                Ad = new SqlDataAdapter("PUR2007NET_群組列印_群組", GonGinVariable.SqlConnectString);
                Ad.SelectCommand.CommandType    = CommandType.StoredProcedure;
                Ad.SelectCommand.CommandTimeout = 600;
                Ad.SelectCommand.Parameters.Clear();
                Ad.SelectCommand.Parameters.Add("@群組", SqlDbType.VarChar).Value   = naviTextBox4.Text;
                Ad.SelectCommand.Parameters.Add("@BGYM", SqlDbType.VarChar).Value = naviTextBox2.Text;
                Ad.SelectCommand.Parameters.Add("@項目", SqlDbType.VarChar).Value   = naviTextBox3.Text;
                群組報表.Clear();
                Ad.Fill(群組報表);

                string 組別 = string.Empty;
                foreach (DataRow oRows in 群組報表.Tables[2].Rows)
                {
                    組別 += oRows["群組"].ToString() + ",";
                }
                組別 = 組別.TrimEnd(',');
                組別 = "(" + 組別 + ")組";


                String 串部門 = string.Empty;
                int    X   = 0;
                foreach (DataRow item in 群組報表.Tables[1].Rows)
                {
                    串部門 += "(" + item["BGDEP"].ToString() + ")" + item["DEPTNAME"].ToString() + ",";
                    if (X % 8 == 7)
                    {
                        串部門 = 串部門 + "\r\n";
                    }
                    X++;
                }
                串部門 = "群組:" + 串部門.TrimEnd(',');


                群組_總表 Reporter1 = new 群組_總表();
                //Reporter1.SetDataSource(Dt_明細);
                Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                Form ReportForm = new Form();
                CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                CryReport.ReportSource = Reporter1;
                CryReport.Dock         = DockStyle.Fill;
                Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                Reporter1.ParameterFields["代號"].CurrentValues.AddValue("第" + naviTextBox4.Text + "群" + 組別);

                ReportForm.Controls.Add(CryReport);
                ReportForm.WindowState = FormWindowState.Maximized;
                ReportForm.Show();
            }
            else
            {
                if (string.IsNullOrEmpty(naviTextBox1.Text))
                {
                    MessageBox.Show("部門群組未填 !!", "更新訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Ad = new SqlDataAdapter("PUR2007NET_群組列印", GonGinVariable.SqlConnectString);
                Ad.SelectCommand.CommandType    = CommandType.StoredProcedure;
                Ad.SelectCommand.CommandTimeout = 600;
                Ad.SelectCommand.Parameters.Clear();
                Ad.SelectCommand.Parameters.Add("@上階部門", SqlDbType.VarChar).Value = naviTextBox1.Text;
                Ad.SelectCommand.Parameters.Add("@BGYM", SqlDbType.VarChar).Value = naviTextBox2.Text;
                Ad.SelectCommand.Parameters.Add("@項目", SqlDbType.VarChar).Value   = naviTextBox3.Text;
                群組報表.Clear();
                Ad.Fill(群組報表);


                string 階部門 = string.Empty;
                string 代號  = string.Empty;
                _QueryComm.CommandText = " SELECT DEPTNAME,DEPT12,B.大群 FROM AMDDEPT A,PUR群組 B WHERE DEPTNO = @DEPTNO AND A.DEPT12=B.群組 ";
                _QueryComm.CommandType = CommandType.Text;
                _QueryComm.Parameters.Clear();
                _QueryComm.Parameters.Add("@DEPTNO", SqlDbType.VarChar).Value = naviTextBox1.Text;
                _QueryDr = _QueryComm.ExecuteReader();

                if (_QueryDr.HasRows)
                {
                    _QueryDr.Read();
                    階部門 = _QueryDr["DEPTNAME"].ToString();
                    代號  = "第" + _QueryDr["大群"].ToString() + "群_第" + _QueryDr["DEPT12"].ToString() + "組";
                }
                _QueryDr.Close();


                String 串部門 = string.Empty;
                int    X   = 0;
                foreach (DataRow item in 群組報表.Tables[2].Rows)
                {
                    串部門 += "(" + item["BGDEP"].ToString() + ")" + item["DEPTNAME"].ToString() + ",";
                    if (X % 8 == 7)
                    {
                        串部門 = 串部門 + "\r\n";
                    }
                    X++;
                }
                串部門 = "群組:" + 串部門.TrimEnd(',');


                if (radioButton1.Checked)
                {
                    群組_總表 Reporter1 = new 群組_總表();
                    //Reporter1.SetDataSource(Dt_明細);
                    Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                    Form ReportForm = new Form();
                    CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                    CryReport.ReportSource = Reporter1;
                    CryReport.Dock         = DockStyle.Fill;
                    Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                    Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                    Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                    Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                    Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                    Reporter1.ParameterFields["代號"].CurrentValues.AddValue(代號);

                    ReportForm.Controls.Add(CryReport);
                    ReportForm.WindowState = FormWindowState.Maximized;
                    ReportForm.Show();
                }
                else if (radioButton2.Checked)
                {
                    //群組_品類總表 Reporter1 = new 群組_品類總表();
                    ////Reporter1.SetDataSource(Dt_明細);
                    //Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[3]);
                    //Form ReportForm = new Form();
                    //CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                    //CryReport.ReportSource = Reporter1;
                    //CryReport.Dock = DockStyle.Fill;
                    //Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                    //Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                    //Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                    //Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                    //Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                    //Reporter1.ParameterFields["代號"].CurrentValues.AddValue(代號);

                    //ReportForm.Controls.Add(CryReport);
                    //ReportForm.WindowState = FormWindowState.Maximized;
                    //ReportForm.Show();


                    群組_總表NEW1 Reporter1 = new 群組_總表NEW1();
                    //Reporter1.SetDataSource(Dt_明細);
                    Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                    Reporter1.Database.Tables[1].SetDataSource(群組報表.Tables[3]);
                    Form ReportForm = new Form();
                    CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                    CryReport.ReportSource = Reporter1;
                    CryReport.Dock         = DockStyle.Fill;
                    Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                    Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                    Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                    Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                    Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                    Reporter1.ParameterFields["代號"].CurrentValues.AddValue(代號);

                    ReportForm.Controls.Add(CryReport);
                    ReportForm.WindowState = FormWindowState.Maximized;
                    ReportForm.Show();
                }
                else if (radioButton3.Checked)
                {
                    //群組_品類部門 Reporter1 = new 群組_品類部門();
                    ////Reporter1.SetDataSource(Dt_明細);
                    //Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[1]);
                    //Form ReportForm = new Form();
                    //CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                    //CryReport.ReportSource = Reporter1;
                    //CryReport.Dock = DockStyle.Fill;
                    //Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                    //Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                    //Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                    //Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                    //Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                    //Reporter1.ParameterFields["代號"].CurrentValues.AddValue(代號);

                    //ReportForm.Controls.Add(CryReport);
                    //ReportForm.WindowState = FormWindowState.Maximized;
                    //ReportForm.Show();

                    群組_總表NEW2 Reporter1 = new 群組_總表NEW2();
                    //Reporter1.SetDataSource(Dt_明細);
                    Reporter1.Database.Tables[0].SetDataSource(群組報表.Tables[0]);
                    Reporter1.Database.Tables[1].SetDataSource(群組報表.Tables[1]);
                    Form ReportForm = new Form();
                    CrystalDecisions.Windows.Forms.CrystalReportViewer CryReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                    CryReport.ReportSource = Reporter1;
                    CryReport.Dock         = DockStyle.Fill;
                    Reporter1.ParameterFields["列印人"].CurrentValues.AddValue(GonGinVariable.ApplicationUserName);
                    Reporter1.ParameterFields["CompanyName"].CurrentValues.AddValue(GonGinVariable.公司名稱);
                    Reporter1.ParameterFields["部門"].CurrentValues.AddValue(串部門);
                    Reporter1.ParameterFields["月份"].CurrentValues.AddValue(naviTextBox2.Text.Substring(0, 4) + "年" + naviTextBox2.Text.Substring(4, 2) + "月");
                    Reporter1.ParameterFields["項目"].CurrentValues.AddValue(naviTextBox3.Text);
                    Reporter1.ParameterFields["代號"].CurrentValues.AddValue(代號);

                    ReportForm.Controls.Add(CryReport);
                    ReportForm.WindowState = FormWindowState.Maximized;
                    ReportForm.Show();
                }
            }
        }