Как передать два идентификатора MySQL в c # .exe?

Я пытаюсь сделать программу для заполнения форм PDF. Программа должна получить 2 идентификатора из скрипта PHP, выполнить поиск в базе данных MySQL и заполнить формы информацией, основанной на этих двух идентификаторах, но я не могу заставить скрипт PHP передавать аргументы в исполняемый файл c #. Может быть, вы можете помочь мне 🙂

PHP скрипт:

<?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

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector