コード例 #1
0
        private void btnPrintPDF_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf";
            // Show save file dialog box
            DialogResult result = saveFileDialog.ShowDialog();

            //点了保存按钮进入
            if (result == DialogResult.OK)
            {
                DataTable tempDetailDT = ApplicationDetailTable.Clone();
                foreach (DataRow dr in ApplicationDetailTable.Rows)
                {
                    if (dr["IsSuccess"].ToString() == "1")
                    {
                        tempDetailDT.Rows.Add(dr.ItemArray);
                    }
                }

                //获得文件路径
                string   localFilePath = saveFileDialog.FileName.ToString();
                PrintPDF pp            = new PrintPDF();
                try
                {
                    DataTable appDT = applicationInfo.SelectApplicationByTransNo(applicationInfo.TransNo);
                    pp.CreatePDF(appDT, tempDetailDT, localFilePath, "员工内购购买明细");
                    MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
コード例 #2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            bool isSuccess = false;

            Business.PrintPDF printPDF       = new PrintPDF();
            SaveFileDialog    saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf";
            // Show save file dialog box
            DialogResult result = saveFileDialog.ShowDialog();

            applicationInfo.applicationDT = applicationInfo.SelectApplicationByTransNo(applicationInfo.TransNo);
            //点了保存按钮进入
            if (result == DialogResult.OK)
            {
                if (applicationInfo.AppState < 2)
                {
                    MessageBox.Show("商品部未批准,无法打印", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (applicationInfo.applicationDT.Rows.Count > 0)
                    {
                        try
                        {
                            //获得文件路径
                            string   localFilePath = saveFileDialog.FileName.ToString();
                            PrintPDF pp            = new PrintPDF();
                            if (applicationInfo.applicationDT.Rows[0]["MoneyUnit"].ToString() == "1" && Convert.ToInt32(ApplicationDetailTable.Rows[0].ItemArray[6]) == 1)
                            {
                                isSuccess = printPDF.CreatePDF(applicationInfo.applicationDT, ApplicationDetailTable, localFilePath, "Staff Purchase Requisition Form 订购申请表");
                            }
                            else
                            {
                                isSuccess = printPDF.CreateEnPDF(applicationInfo.applicationDT, ApplicationDetailTable, localFilePath);
                            }
                            if (isSuccess)
                            {
                                MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("保存失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }