public void createReport(string sYear, string sMonth, string templatePath, DataGridView dgvIn, DateTime delieveryDate, string route) { string tmp = ""; dgv = dgvIn; string savepath = CCFBGlobal.pathCSFP + sYear + @"\"; CCFBGlobal.verifyPath(savepath); Object saveAs = savepath + sYear + sMonth + "-" + "CSFP PickList" + "-" + route + ".doc"; CCFBGlobal.DeleteFile(saveAs.ToString()); Object oMissing = System.Reflection.Missing.Value; Object missing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Document oWordDoc = new Document(); oWord.Visible = true; Object oTemplatePath = templatePath; try { oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); //Save so that the template is free to be used by the next user oWordDoc.SaveAs(ref saveAs, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); oWordDoc.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageHeader; oWordDoc.ActiveWindow.Selection.Find.Execute("Picklist"); oWordDoc.ActiveWindow.Selection.TypeText(FBName + " - CSFP Picklist - " + sYear + "-" + sMonth); oWordDoc.ActiveWindow.Selection.Find.Execute("Planned"); oWordDoc.ActiveWindow.Selection.MoveRight(WdUnits.wdCell, 1); oWordDoc.ActiveWindow.Selection.TypeText(delieveryDate.ToShortDateString()); oWordDoc.ActiveWindow.Selection.MoveRight(WdUnits.wdCell, 2); oWordDoc.ActiveWindow.Selection.TypeText(route); oWordDoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument; Table mytable = oWordDoc.Tables[1]; //if (CCFBPrefs.EnableCSFPShowRoutes == false) //{ // table.Cell(1, 5).Range.Text = "Previous Svc"; //} int row = 2; for (int i = 0; i < dgv.Rows.Count; i++) { if (row > mytable.Rows.Count) { mytable.Rows.Add(Type.Missing); } mytable.Cell(row, 1).Range.Text = (row - 1).ToString() + ": " + dgv.Rows[i].Cells["HouseholdID"].Value.ToString(); mytable.Cell(row, 2).Range.Text = dgv.Rows[i].Cells["clmName"].Value.ToString(); tmp = dgv.Rows[i].Cells["Address"].Value.ToString(); if (dgv.Rows[i].Cells["AptNbr"].Value.ToString() != "") { tmp += " unit " + dgv.Rows[i].Cells["AptNbr"].Value.ToString(); } mytable.Cell(row, 3).Range.Text = tmp; tmp = dgv.Rows[i].Cells["clmPhone"].Value.ToString(); if (tmp != "( ) -") { mytable.Cell(row, 4).Range.Text = dgv.Rows[i].Cells["clmPhone"].Value.ToString(); } //if (dgv.Rows[i].Cells["CSFPExpiration"].Style.BackColor == System.Drawing.Color.Yellow) //{ // table.Cell(row, 4).Range.HighlightColorIndex = WdColorIndex.wdYellow; //} //else //{ // table.Cell(row, 4).Range.HighlightColorIndex = WdColorIndex.wdNoHighlight; //} mytable.Cell(row, 5).Range.Text = dgv.Rows[i].Cells["clmCSFPComments"].Value.ToString(); mytable.Cell(row, 7).Range.Text = dgv.Rows[i].Cells["clmDateServed"].Value.ToString(); //table.Cell(row, 7).Range.Text = dgv.Rows[i].Cells["clmLbs"].Value.ToString(); row += 1; } oWordDoc.Save(); //oWordDoc.SaveAs(ref saveAs, ref missing, ref missing, ref missing, ref missing, // ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, // ref missing, ref missing, ref missing, ref missing, ref missing); ((_Application)oWord).Quit(SaveChanges: false, OriginalFormat: false, RouteDocument: false); System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord); CCFBGlobal.openDocumentOutsideCCFB(saveAs.ToString()); } catch (Exception ex) { CCFBGlobal.appendErrorToErrorReport("File Path = " + oTemplatePath.ToString(), ex.GetBaseException().ToString()); ((_Application)oWord).Quit(SaveChanges: false, OriginalFormat: false, RouteDocument: false); System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord); } }
private void btnSave_Click(object sender, EventArgs e) { int newTrxId = 0; object osavename = savePath + idText + ".pdf"; object oFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; if (okToSave() == true) { btnSave.Enabled = false; if (sigPadInputCtrl1.Visible == true) { if (sigPadInputCtrl1.IsSigned == true) { if (sigPadInputCtrl1.SaveSigImage(constSigFile)) { oWord.Selection.EndKey(WdUnits.wdStory, WdMovementType.wdExtend); oWord.Selection.MoveRight(WdUnits.wdCharacter, 1); oWord.Selection.InlineShapes.AddPicture(constSigFile, false, true); oWordDoc.Save(); filename = oWordDoc.FullName; if (chkPrintOnSave.Checked == true) { CCFBGlobal.appendErrorToErrorReport(osavename.ToString(), "Sign and Print Family Card"); oWord.Options.PrintBackground = false; oWordDoc.PrintOut(ref oFalse, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(100); } oWordDoc.SaveAs2(ref osavename, ref oFileFormat); ((_Application)oWord).Quit(SaveChanges: true, OriginalFormat: false, RouteDocument: false); System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord); if (chkCloseOnSave.Checked == false) { CCFBGlobal.openDocumentOutsideCCFB(osavename.ToString()); } CCFBGlobal.DeleteFile(filename); } //picSignature.Visible = true; ////cmsLog.Visible = false; //MessageBox.Show(this, "Close Signature Display"); //picSignature.Visible = false; FamilyCardSig clsFCSig = new FamilyCardSig(CCFBGlobal.connectionString); clsFCSig.LoadImage(newTrxId, clsHH.ID); clsFCSig.UID = newTrxId; clsFCSig.HhID = clsHH.ID; clsFCSig.SigDate = Convert.ToDateTime(sigPadInputCtrl1.GetSigDate()); clsFCSig.DocPath = osavename.ToString(); clsFCSig.SigImage = sigPadInputCtrl1.GetImage(); clsFCSig.SigString = sigPadInputCtrl1.GetSignature(); if (clsFCSig.HaveSignature == true) { clsFCSig.Update(); } else { clsFCSig.Insert(); } } sigPadInputCtrl1.ResetTablet(); } this.Close(); } else { MessageBox.Show("Signature is missing", "Saqve Signature"); } btnSave.Enabled = true; }