dousi7579 2017-04-14 06:49
浏览 40

如何将两个MySQL id传递给c#.exe?

I am trying to make a PDF form filling program. The program should get 2 id's from the PHP script, search the MySQL database, and fill the forms with info based of those two id's, but i cant make the PHP script pass arguments to the c# executable. Maybe u can help me out :)

PHP script :

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("documente", $con);

$idfirma;
$idagent;

$sql="SELECT * FROM `agenti` WHERE `Nume Agent` = '$_GET[numea]'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "Date agent"."<br>";
echo $row['Nume Agent'];echo "    |     ";echo $row['Sigiliu'];echo "    |     ";echo $row['Legitimatie']."<br>"."<br>"."<br>"."<br>"."<br>";
$idagent=$row['ID'];
}

$sql1="SELECT * FROM `dateclienti` WHERE `Cod Fiscal` = '$_GET[codf]'";
$result = mysql_query($sql1);
while($row = mysql_fetch_array($result)) {
echo "Date Firma"."<br>";
echo $row['Nume Societate'];echo "    |     ";echo $row['Adresa Sediu'];echo "    |     ";echo $row['Cod Fiscal']."<br>";
$idfirma=$row['ID'];
}



exec("pdfgen\PdfGenerator\bin\Debug\PdfGenerator.exe $idfirma, $idagent 2>&1");
echo $idfirma."<br>"."<br>";
echo $idagent;



if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }




mysql_close($con)
?>

c# scipt :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
using System.IO;
using MySql.Data.MySqlClient;




namespace PdfGenerator
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            FillForm();
            ListFieldNames();
        }


        /// <summary>
        /// List all of the form fields into a textbox.  The
        /// form fields identified can be used to map each of the
        /// fields in a PDF.
        /// </summary>
      private void ListFieldNames()


       {
              string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf";

              // title the form
              this.Text += " - " + pdfTemplate;

              // create a new PDF reader based on the PDF template document
              PdfReader pdfReader = new PdfReader(pdfTemplate);

              // create and populate a string builder with each of the 
              // field names available in the subject PDF
              StringBuilder sb = new StringBuilder();
              foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
              {
                  sb.Append(de.Key.ToString() + Environment.NewLine);
              }

              // Write the string builder's content to the form's textbox
              textBox1.Text = sb.ToString();
              textBox1.SelectionStart = 0;
          }



         private void FillForm()
        {
            string idagent1 = null;
            string idfirma1 = null;
            string[] args = System.Environment.GetCommandLineArgs();
            if(args.Length !=0)
            {
                idfirma1 = args[1];
                idagent1 = args[2];

            }


                using (var connection = new MySqlConnection("server = localhost; User Id = root; password = ; database = documente;"))
            {


                connection.Open();


                string agenti = "SELECT `Nume Agent` FROM `agenti` WHERE `ID` = @id";
                string name1 = null;

                using (var cmd = new MySqlCommand(agenti, connection))
                {
                    cmd.Parameters.AddWithValue("@id", idagent1);
                    MySqlDataReader rdr = cmd.ExecuteReader();
                    DataTable dt = new DataTable();
                    dt.Load(rdr);

                    foreach (DataRow row in dt.Rows)
                    {
                        string name = row["Nume Agent"].ToString();

                        name1 = name;
                    }






















                    string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf";
                    string newFile = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\completed_form.pdf";

                    PdfReader pdfReader = new PdfReader(pdfTemplate);
                    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
                                newFile, FileMode.Create));

                    AcroFields pdfFormFields = pdfStamper.AcroFields;

                    // set form pdfFormFields

                    // The first worksheet and W-4 form
                    pdfFormFields.SetField("topmostSubform[0].Page1[0].regcomert[0]", name1);




                    // flatten the form to remove editting options, set it to false
                    // to leave the form open to subsequent manual edits
                    pdfStamper.FormFlattening = true;

                    // close the pdf
                    pdfStamper.Close();

                }
            }



        }
    }
}










using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace PdfGenerator
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器