Exemplo n.º 1
0
        private void toolStripMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            DataGridView dgv             = null;
            Form         activeChildForm = this.ActiveMdiChild;

            switch (e.ClickedItem.Name)
            {
            case "tsbtnPrint":     //Printing Gridview
                dgv = getDGVCOntrol();
                if (dgv != null)
                {
                    PrintDGV.Print_DataGridView(dgv);
                }
                else
                {
                    lblDMMsg.Text = "There is no grid found on Active form";
                }
                break;

            case "tsbtnExcel":     //Export to Excel
                dgv = getDGVCOntrol();
                if (dgv != null)
                {
                    saveFileDlgExport.Title    = "Save file [Export to Excel]";
                    saveFileDlgExport.Filter   = "Excel (*.xls)|*.xls|XLSX (*.xlsx)|*.xlsx|XLSB (*.xlsb)|*.xlsb|XLSM (*.xlsm)|*.xlsm";
                    saveFileDlgExport.FileName = CommonDoubleM._sDefaultExcelFile;

                    if (saveFileDlgExport.ShowDialog() == DialogResult.OK)
                    {
                        System.IO.FileInfo f = new System.IO.FileInfo(saveFileDlgExport.FileName);
                        switch (f.Extension.ToLower())
                        {
                        case ".xls":
                        case "xlsx":
                        case "xlsb":
                        case "xlsm":
                            DataTable dt = new DataTable();
                            dt = CommonDoubleM.getDataTable(dgv);
                            DoubleM.ExportExcel.Export(f.ToString(), dt, dt.TableName);
                            break;

                        default:
                            MessageBox.Show("Unable to Export - Invalid file type");
                            break;
                        }
                    }
                }
                else
                {
                    lblDMMsg.Text = "There is no grid found on Active form";
                }

                break;

            case "tsbtnBSE":
                break;

            case "tsbtnNSE":
                break;
            }
        }