private void dgvDocumentList_CellContentClick(Object sender, DataGridViewCellEventArgs e) { try { DataGridView dgv = sender as DataGridView; string fileName = ""; if (e.RowIndex < 0) { return; } if (e.ColumnIndex == 0) { removePDFControls(); fileName = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); ////string docDir = Main.documentDirectory + "\\" + docID; string subDir = prevsitem.StockItemID + "-" + prevsitem.Name; ////DocumentStorageDB.createFileFromDB(docID, subDir, fileName); fileName = DocumentStorageDB.createFileFromDB(docID, subDir, fileName); ////showPDFFile(fileName); ////dgv.Visible = false; System.Diagnostics.Process.Start(fileName); } } catch (Exception ex) { } }
private void btnListDocument_Click_1(object sender, EventArgs e) { try { removePDFFileGridView(); removePDFControls(); DataGridView dgvDocumentList = new DataGridView(); pnlPDFViewer.Controls.Remove(dgvDocumentList); dgvDocumentList = DocumentStorageDB.getDocumentDetails(docID, prevsitem.StockItemID + "-" + prevsitem.Name); pnlPDFViewer.Controls.Add(dgvDocumentList); dgvDocumentList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDocumentList_CellContentClick); } catch (Exception ex) { } }
//----- //private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e) //{ // try // { // if (lv.CheckedIndices.Count > 1) // { // MessageBox.Show("Cannot select more than one item"); // e.Item.Checked = false; // } // } // catch (Exception) // { // } //} //private void btnSelectJobID_Click(object sender, EventArgs e) //{ // btnSelectJobID.Enabled = false; // if (txtSMRNHeaderNo.Text.Length == 0) // { // MessageBox.Show("Select SMRN Temporary No"); // btnSelectJobID.Enabled = true; // return; // } // if (cmbReportType.SelectedIndex == -1) // { // MessageBox.Show("Select Report Type"); // btnSelectJobID.Enabled = true; // return; // } // removeControlsFromPnlLvPanel(); // pnllv = new Panel(); // pnllv.BorderStyle = BorderStyle.FixedSingle; // pnllv.Bounds = new Rectangle(new Point(100, 100), new Size(600, 300)); // int tempNo = Convert.ToInt32(txtSMRNHeaderNo.Text); // DateTime tempDate = dtSMRNHeaderDate.Value; // int ReportType = Convert.ToInt32(cmbReportType.SelectedItem.ToString().Trim().Substring(0, cmbReportType.SelectedItem.ToString().Trim().IndexOf('-'))); // lv = SMRNHeaderDB.getSMRNJOBIDNoListView(tempNo, tempDate, ReportType); // this.lv.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.listView2_ItemChecked); // lv.Bounds = new Rectangle(new Point(50, 50), new Size(500, 200)); // pnllv.Controls.Add(lv); // Button lvOK = new Button(); // lvOK.Text = "OK"; // lvOK.Location = new Point(50, 270); // lvOK.Click += new System.EventHandler(this.lvOK_Click1); // pnllv.Controls.Add(lvOK); // Button lvCancel = new Button(); // lvCancel.Text = "Cancel"; // lvCancel.Location = new Point(150, 270); // lvCancel.Click += new System.EventHandler(this.lvCancel_Click1); // pnllv.Controls.Add(lvCancel); // pnlAddEdit.Controls.Add(pnllv); // pnllv.BringToFront(); // pnllv.Visible = true; //} //private void lvOK_Click1(object sender, EventArgs e) //{ // try // { // btnSelectJobID.Enabled = true; // pnllv.Visible = false; // ////ArrayList lviItemsArrayList = new ArrayList(); // string trlist; // if (lv.CheckedItems.Count > 0) // { // trlist = ""; // foreach (ListViewItem itemRow in lv.Items) // { // if (itemRow.Checked) // { // btnSelectJobID.Enabled = true; // txtJobIDNo.Text = itemRow.SubItems[1].Text; // } // } // } // } // catch (Exception) // { // } //} //private void lvCancel_Click1(object sender, EventArgs e) //{ // try // { // btnSelectJobID.Enabled = true; // pnllv.Visible = false; // } // catch (Exception) // { // } //} ////----- //private void listView2_ItemChecked(object sender, ItemCheckedEventArgs e) //{ // try // { // if (lv.CheckedIndices.Count > 1) // { // MessageBox.Show("Cannot select more than one item"); // e.Item.Checked = false; // } // } // catch (Exception) // { // } //} private void btnListDocuments_Click(object sender, EventArgs e) { try { removePDFFileGridView(); removePDFControls(); DataGridView dgvDocumentList = new DataGridView(); pnlPDFViewer.Controls.Remove(dgvDocumentList); dgvDocumentList = DocumentStorageDB.getDocumentDetails(docID, prevservlist.ListNo + "-" + prevservlist.ListDate.ToString("yyyyMMddhhmmss")); pnlPDFViewer.Controls.Add(dgvDocumentList); dgvDocumentList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDocumentList_CellContentClick); } catch (Exception ex) { } }
public Boolean PrintReport(Dictionary <Int32, DateTime> ReprotDict, string Dir, string fname, string prodInfo) { Boolean status = true; string pathStr = ""; string ColHeader = ColHeader = "SI No.;Test Description;Expected Result;Result;Status"; string fileName = fname; string footer3 = ""; string subDir = Dir.Substring(0, Dir.IndexOf('-')) + "-" + Dir.Substring(Dir.IndexOf('-') + 1); string dicDir = Main.documentDirectory + "\\" + "PRODUCTTESTREPORT"; string[] ProdInfoStr = prodInfo.Split(';'); HeaderString = "Product Code: " + ProdInfoStr[0].Substring(0, ProdInfoStr[0].IndexOf('-')) + ";Product Description: " + ProdInfoStr[0].Substring(ProdInfoStr[0].IndexOf('-') + 1) + ";ModelNo: " + ProdInfoStr[1].Substring(0, ProdInfoStr[1].IndexOf('-')) + ";ModelName: " + ProdInfoStr[1].Substring(ProdInfoStr[1].IndexOf('-') + 1); //ptrheader.CreateUser ---- // for testDeacriptionID //ptrheader.ForwardUser ---- // for Expected Result //ptrheader.ApproveUser ---- // for Actual Result //ptrheader.Status ---- // for TestStatus try { string dir = dicDir + "\\" + subDir; if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } string Fname = dir + "\\" + fileName; FileStream fs = new FileStream(Fname + ".pdf", FileMode.Create, FileAccess.Write); Rectangle rec = new Rectangle(PageSize.A4); iTextSharp.text.Document doc = new iTextSharp.text.Document(rec); PdfWriter writer = PdfWriter.GetInstance(doc, fs); MyEvent evnt = new MyEvent(); writer.PageEvent = evnt; doc.Open(); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL); img.Alignment = Element.ALIGN_LEFT; Paragraph paragraph = new Paragraph(new Phrase(Title, font2)); paragraph.Alignment = Element.ALIGN_CENTER; paragraph.SpacingAfter = 10f; int temp = 0; foreach (KeyValuePair <Int32, DateTime> report in ReprotDict) { temp++; doc.NewPage(); string prodSerNo = ""; string no = report.Key.ToString(); string val = report.Value.ToString(); string ColDetailString = ""; List <producttestreportheader> ptrhList = ProductTestReportHeaderDB.getReportListForPrint(report.Key, report.Value); var count = ptrhList.Count(); int n = 1; foreach (producttestreportheader ptrh1 in ptrhList) { if (n == count) { ColDetailString = ColDetailString + n + "+" + ptrh1.CreateUser + "+" + ptrh1.ForwardUser + "+" + ptrh1.ApproveUser + "+" + getStatusCode(ptrh1.Status); } else { ColDetailString = ColDetailString + n + "+" + ptrh1.CreateUser + "+" + ptrh1.ForwardUser + "+" + ptrh1.ApproveUser + "+" + getStatusCode(ptrh1.Status) + ";"; } n++; } foreach (producttestreportheader ptrh in ptrhList) { prodSerNo = "Product Serial No: " + ptrh.ProductSerialNo; footer3 = "Prepared By:" + ptrh.CreatorName + ";Approved By:" + ptrh.ApproverName; } //-- string[] HeaderStr = HeaderString.Split(';'); Paragraph pheader = new Paragraph(); ///pheader.SpacingBefore = 20f; foreach (string str in HeaderStr) { Phrase ph = new Phrase(); ph.Add(new Chunk(str.Substring(0, str.IndexOf(':') + 1), font2)); ph.Add(new Chunk(str.Substring(str.IndexOf(':') + 1) + "\n", font1)); pheader.Add(ph); } Paragraph serial = new Paragraph(); Phrase phr = new Phrase(); phr.Add(new Chunk(prodSerNo.Substring(0, prodSerNo.IndexOf(':') + 1), font2)); phr.Add(new Chunk(prodSerNo.Substring(prodSerNo.IndexOf(':') + 1) + "\n", font1)); serial.Add(phr); serial.SpacingBefore = 20f; string[] ColHeaderStr = ColHeader.Split(';'); PdfPTable table1 = new PdfPTable(5); table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.WidthPercentage = 100; float[] width = new float[] { 3f, 3f, 3f, 3f, 3f }; table1.SetWidths(width); table1.SpacingBefore = 10f; for (int i = 0; i < ColHeaderStr.Length; i++) { PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2)); hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.AddCell(hcell); //string str = ColHeaderStr[i]; } PdfPCell foot = new PdfPCell(new Phrase("")); foot.Colspan = 5; foot.BorderWidthTop = 0; foot.MinimumHeight = 0.5f; table1.AddCell(foot); table1.HeaderRows = 2; table1.FooterRows = 1; table1.SkipFirstHeader = false; table1.SkipLastFooter = true; string[] DetailStr = ColDetailString.Split(';'); for (int i = 0; i < DetailStr.Length; i++) { string[] str = DetailStr[i].Split('+'); for (int j = 0; j < str.Length; j++) { PdfPCell pcell; string s = str[j]; pcell = new PdfPCell(new Phrase(str[j], font1)); pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.AddCell(pcell); } } Paragraph pFooter = new Paragraph(); string[] fillFooter = footer3.Split(';'); Phrase Creator = new Phrase(fillFooter[0] + "\n", font1); Phrase Approver = new Phrase(fillFooter[1] + "\n", font1); pFooter.Add(Creator); pFooter.Add(Approver); if (temp == 1) { doc.Add(img); doc.Add(paragraph); doc.Add(pheader); } doc.Add(serial); doc.Add(table1); doc.Add(pFooter); } doc.Close(); pathStr = dir + "\\" + fileName + ".pdf"; documentStorage ds = new documentStorage(); DocumentStorageDB dsdb = new DocumentStorageDB(); ds.DocumentID = "PRODUCTTESTREPORT"; ds.Directory = subDir; ds.FileName = fileName + ".pdf"; ds.Description = "ProductTestReport " + subDir; if (dsdb.validateDocumentDetails(ds)) { if (dsdb.iskDocumentDuplication(ds)) { if (dsdb.UpdateDocumentDetails(ds)) { MessageBox.Show("DocumetnStorage Updated"); } else { MessageBox.Show("failed to update documentStorage"); } } else { if (dsdb.InsertDocumentDetails(ds)) { MessageBox.Show("DocumetnStorage Updated"); } else { MessageBox.Show("failed to update documentStorage"); } } } } catch (Exception ie) { status = false; } return(status); }
private void btnUpload_Click(object sender, EventArgs e) { try { if (txtDescription.Text.Trim().Length == 0) { MessageBox.Show("Please enter the document description"); return; } if (txtShow.Text.Trim().Length == 0) { MessageBox.Show("Please select file to upload"); return; } string path = txtShow.Text.Trim(); string nm = Path.GetFileName(path); documentStorage ds = new documentStorage(); DocumentStorageDB dsdb = new DocumentStorageDB(); ds.DocumentID = docId; ds.Directory = subDir; ds.DocumentSubID = subDir; ds.FileName = nm; ds.Description = txtDescription.Text; //ds.ProtectionLevel = 1; if (dsdb.validateDocumentDetails(ds)) { //------------convert document to binary try { byte[] byteArray = null; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); //byteArray = br.ReadBytes((int)fs.Length); //string byteStr = Convert.ToBase64String(byteArray); //ds.DocumentContent = byteStr; ds.DocumentContent = Convert.ToBase64String(br.ReadBytes((int)fs.Length)); br.Close(); fs.Close(); } catch (Exception) { } //------------ if (dsdb.iskDocumentDuplication(ds)) { DialogResult dialog = MessageBox.Show("Document with same name existing. Replace ?", "Yes", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { if (dsdb.UpdateDocumentDetails(ds)) { MessageBox.Show("Document Replaced Sucessfuly"); } else { MessageBox.Show("Failed to replace Document"); } } } else { if (dsdb.InsertDocumentDetails(ds)) { MessageBox.Show("Document uploaded Sucessfuly"); } else { MessageBox.Show("Failed to Load document. Check"); } } } else { MessageBox.Show("Validation failed. Please verify the details"); } txtShow.Text = ""; txtDescription.Text = ""; btnView.Enabled = false; } catch (Exception ex) { MessageBox.Show("btnUpload_Click() : File upload Failed"); } }
public string PrintServicedList(List <smrndetail> smrnList, smrnservicedlist list) { string pathStr = ""; string HeaderString = "List No:" + list.ListNo + ";List Date:" + list.ListDate + ";Customer:" + list.CustomerID + ";CustomerPO No:" + list.CustomerPONo + ";CustomerPO Date:" + list.CustomerPODate; string ColHeader = ColHeader = "SI No.;Items;itemDetails;SerielNo;ServiceStatus"; string fileName = list.TrackingNo + "-" + list.ListNo; string Title = "List Of Serviced Items"; string subDir = list.ListNo + "-" + list.ListDate.ToString("yyyyMMddhhmmss"); string dicDir = Main.documentDirectory + "\\" + list.DocumentID; int n = 1; string ColDetailString = ""; var count = smrnList.Count(); foreach (smrndetail smrnd in smrnList) { if (n == count) { ColDetailString = ColDetailString + n + "+" + smrnd.StockItemID + "+" + smrnd.ItemDetails + "+" + smrnd.SerialNo + "+" + smrnd.ProductServiceStatus; } else { ColDetailString = ColDetailString + n + "+" + smrnd.StockItemID + "+" + smrnd.ItemDetails + "+" + smrnd.SerialNo + "+" + smrnd.ProductServiceStatus + ";"; } n++; } try { string dir = dicDir + "\\" + subDir; if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } string Fname = dir + "\\" + fileName; FileStream fs = new FileStream(Fname + ".pdf", FileMode.Create, FileAccess.Write); Rectangle rec = new Rectangle(PageSize.A4); iTextSharp.text.Document doc = new iTextSharp.text.Document(rec); PdfWriter writer = PdfWriter.GetInstance(doc, fs); MyEvent evnt = new MyEvent(); writer.PageEvent = evnt; doc.Open(); Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK); Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK); Paragraph paragraph = new Paragraph(new Phrase(Title, font2)); paragraph.Alignment = Element.ALIGN_CENTER; string[] HeaderStr = HeaderString.Split(';'); Paragraph pheader = new Paragraph(); foreach (string str in HeaderStr) { Phrase ph = new Phrase(); ph.Add(new Chunk(str.Substring(0, str.IndexOf(':') + 1), font2)); ph.Add(new Chunk(str.Substring(str.IndexOf(':') + 1) + "\n", font1)); pheader.Add(ph); } string[] ColHeaderStr = ColHeader.Split(';'); PdfPTable table1 = new PdfPTable(5); table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.WidthPercentage = 100; float[] width = new float[] { 3f, 3f, 3f, 3f, 3f }; table1.SetWidths(width); table1.SpacingBefore = 20f; for (int i = 0; i < ColHeaderStr.Length; i++) { PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2)); hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.AddCell(hcell); string str = ColHeaderStr[i]; } PdfPCell foot = new PdfPCell(new Phrase("")); foot.Colspan = 5; foot.BorderWidthTop = 0; foot.MinimumHeight = 0.5f; table1.AddCell(foot); table1.HeaderRows = 2; table1.FooterRows = 1; table1.SkipFirstHeader = false; table1.SkipLastFooter = true; string[] DetailStr = ColDetailString.Split(';'); for (int i = 0; i < DetailStr.Length; i++) { string[] str = DetailStr[i].Split('+'); for (int j = 0; j < str.Length; j++) { PdfPCell pcell; string s = str[j]; pcell = new PdfPCell(new Phrase(str[j], font1)); pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; table1.AddCell(pcell); } } doc.Add(paragraph); doc.Add(pheader); doc.Add(table1); doc.Close(); pathStr = dir + "\\" + fileName + ".pdf"; documentStorage ds = new documentStorage(); DocumentStorageDB dsdb = new DocumentStorageDB(); ds.DocumentID = list.DocumentID; ds.Directory = subDir; ds.FileName = fileName + ".pdf"; ds.Description = "SMRNServiceList" + list.ListNo; if (dsdb.validateDocumentDetails(ds)) { if (dsdb.iskDocumentDuplication(ds)) { if (dsdb.UpdateDocumentDetails(ds)) { MessageBox.Show("DocumetnStorage Updated"); } else { MessageBox.Show("failed to update documentStorage"); } } else { if (dsdb.InsertDocumentDetails(ds)) { MessageBox.Show("DocumetnStorage Updated"); } else { MessageBox.Show("failed to update documentStorage"); } } } } catch (Exception ie) { } return(pathStr); }