3. string c = "";
x = 2;
comando = "SELECT m.nm_materia_prima INGREDIENTE,i.qt_materia_prima
QTDE,truncate( ((i.qt_materia_prima)-( ( ((m.qt_ipc_materia_prima -1) *100)
* i.qt_materia_prima ) /100)),3),
m.qt_ipc_materia_prima,m.vl_unitario_materia_prima AS 'VALOR UNITARIO'";
comando += " from materia_prima m join ingrediente_receita i";
comando += " on (i.cd_materia_prima=m.cd_materia_prima)";
comando += " join unidade_medida u on
(u.cd_unidade_medida=i.cd_unidade_medida)";
comando += " where i.cd_prato=" + cboCodigo.Text;
Insere(comando);
double total = 0;
int _i;
for (int i = 2; i <= listBox1.Items.Count + 1; i++)
{
_i = i - 2;
string aa = listBox1.Items[_i].ToString(),
bb = listBox2.Items[_i].ToString(),
cc = listBox3.Items[_i].ToString(),
dd = listBox4.Items[_i].ToString(),
ee = listBox5.Items[_i].ToString();
aa = aa.Replace(",", ".");
bb = bb.Replace(",", ".");
cc = cc.Replace(",", ".");
dd = dd.Replace(",", ".");
ee = ee.Replace(",", ".");
oTable.Cell(i, 1).Range.Text = aa;
oTable.Cell(i, 2).Range.Text = bb;
oTable.Cell(i, 3).Range.Text = cc;
oTable.Cell(i, 4).Range.Text = dd;
oTable.Cell(i, 5).Range.Text = ee;
}
oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Range.Font.Italic = 1;
WORD.Selection.TypeParagraph();
Word.Paragraph modo_preparo;
oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
modo_preparo = oDoc.Content.Paragraphs.Add(ref oRng);
modo_preparo.Format.SpaceAfter = 10;
modo_preparo.Range.Font.Bold = 1;
modo_preparo.Range.InsertParagraphAfter();
conexao = new OdbcConnection(strConex);
conexao.Open();
cSQL = new OdbcCommand("select ds_modo_preparo from prato where
cd_prato =" + cboCodigo.Text, conexao);
dados = cSQL.ExecuteReader();
if (dados.HasRows)
while (dados.Read())
modo_preparo.Range.Text = "MODO DE PREPARO: " +
dados[0].ToString();
dados.Close();
conexao.Close();
dados.Dispose();
conexao.Dispose();
Word.Paragraph valor_prato;
oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
valor_prato = oDoc.Content.Paragraphs.Add(ref oRng);
valor_prato.Format.SpaceAfter = 20;
valor_prato.Range.Font.Bold = 1;
valor_prato.Range.InsertParagraphAfter();
conexao = new OdbcConnection(strConex);
4. conexao.Open();
cSQL = new OdbcCommand("select vl_prato from prato where cd_prato ="
+ cboCodigo.Text, conexao);
dados = cSQL.ExecuteReader();
if (dados.HasRows)
while (dados.Read())
valor_prato.Range.Text = "VALOR : " + dados[0].ToString();
valor_prato.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphRight;
dados.Close();
conexao.Close();
dados.Dispose();
conexao.Dispose();
Word.Paragraph valor_sugerido;
oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
valor_sugerido = oDoc.Content.Paragraphs.Add(ref oRng);
valor_sugerido.Format.SpaceAfter = 20;
valor_sugerido.Range.Font.Bold = 1;
valor_sugerido.Range.InsertParagraphAfter();
conexao = new OdbcConnection(strConex);
conexao.Open(); string
conta = "SELECT truncate( sum((i.qt_materia_prima *
m.vl_unitario_materia_prima)/1000),2) from materia_prima m join
ingrediente_receita i ";
conta += "on (m.cd_materia_prima = i.cd_materia_prima) where
i.cd_prato =" + cboCodigo.Text;
cSQL = new OdbcCommand(conta,conexao);
dados = cSQL.ExecuteReader();
if (dados.HasRows)
while (dados.Read())
valor_sugerido.Range.Text = "PREÇO SUGERIDO : " +
dados[0].ToString();
valor_sugerido.Range.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphRight;
dados.Close();
conexao.Close();
dados.Dispose();
conexao.Dispose();
try
{
conexao = new OdbcConnection(strConex);
conexao.Open();
cSQL = new OdbcCommand("select nm_imagem_prato from prato where
cd_prato =" + cboCodigo.Text, conexao);
dados = cSQL.ExecuteReader();
if (dados.HasRows)
while (dados.Read())
oRng =
oDoc.Application.Selection.InlineShapes.AddPicture(dados[0].ToString()).ScaleHei
ght = 30;
oRng = oDoc.Application.Selection.Paragraphs.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
dados.Close();
conexao.Close();
dados.Dispose();
conexao.Dispose();
}
catch
{
}
WORD.Selection.TypeParagraph();
5. WORD.Selection.TypeParagraph();
//SALVAR
oDoc.SaveAs(Application.StartupPath.Substring(0,
Application.StartupPath.Length - 10) + "Documentos
Temporarios"+nomeprato+".docx" );
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
WORD.Quit(ref oMissing, ref oMissing, ref oMissing);
oDoc = null;
WORD = null;
// Converte para PDF
// Create a new Microsoft Word application object
Microsoft.Office.Interop.Word.Application word = new
Microsoft.Office.Interop.Word.Application();
// C# doesn't have optional arguments so we'll need a dummy value
object oMissing1 = System.Reflection.Missing.Value;
// Get list of Word files in specified directory
DirectoryInfo dirInfo = new
DirectoryInfo(Application.StartupPath.Substring(0,
Application.StartupPath.Length - 10) + "Documentos Temporarios");
FileInfo[] wordFiles = dirInfo.GetFiles("*.docx");
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles)
{
// Cast as Object for word Open method
Object filename = (Object)wordFile.FullName;
// Use the dummy value as a placeholder for optional arguments
Word.Document doc = word.Documents.Open(ref filename, ref
oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".docx",
".pdf");
object fileFormat = Word.WdSaveFormat.wdFormatPDF;
// Save document into PDF Format
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing1, ref oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1,
ref oMissing1, ref oMissing1, ref oMissing1, ref oMissing1);
// Close the Word document, but leave the Word application open.
// doc has to be cast to type _Document so that it will find the
// correct Close method.
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
((Word.Document)doc).Close(ref saveChanges, ref oMissing1, ref
oMissing1);
doc = null;
}
// word has to be cast to type _Application so that it will find
// the correct Quit method.