Ejemplo n.º 1
0
        // edit button
        private void edit_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView.RowCount > 0 && dataGridView.SelectedRows.Count > 0)
                {
                    bool editFile = true;
                    MSOpenKMCore.ws.document doc = (MSOpenKMCore.ws.document)dataGridView.Rows[dataGridView.SelectedRows[0].Index].Tag;

                    // We try to advice user in case selects some document extension that seems not be good to be opened with MS Word
                    if (formType.Equals(OKMDocumentType.TYPE_WORD))
                    {
                        if (!Util.isDocumentValidToOpenWithMSWord(doc))
                        {
                            String msg = String.Format(resources.GetString("word_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_EXCEL))
                    {
                        if (!Util.isDocumentValidToOpenWithMSExcel(doc))
                        {
                            String msg = String.Format(resources.GetString("excel_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_POWER_POINT))
                    {
                        if (!Util.isDocumentValidToOpenWithMSPowerPoint(doc))
                        {
                            String msg = String.Format(resources.GetString("powerpoint_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_VISIO))
                    {
                        if (!Util.isDocumentValidToOpenWithMSVisio(doc))
                        {
                            String msg = String.Format(resources.GetString("visio_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }

                    if (editFile)
                    {
                        MSOpenKMCore.bean.OKMDocument oKMDocument = DocumentLogic.checkoutDocument(doc, formType, configXML.getHost(), configXML.getUser(), configXML.getPassword());
                        if (oKMDocument != null)
                        {
                            documentXML.add(oKMDocument);
                            object missingValue = Type.Missing;
                            object readOnly     = false;
                            object fileName     = oKMDocument.getLocalFilename();

                            if (application is Word.Documents)
                            {
                                ((Word.Documents)application).Open(ref fileName,
                                                                   ref missingValue, ref readOnly, ref missingValue, ref missingValue, ref missingValue,
                                                                   ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue,
                                                                   ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
                            }
                            else if (application is Excel.Workbooks)
                            {
                                ((Excel.Workbooks)application).Open(oKMDocument.getLocalFilename(),
                                                                    missingValue, readOnly, missingValue, missingValue, missingValue,
                                                                    missingValue, missingValue, missingValue, missingValue, missingValue,
                                                                    missingValue, missingValue, missingValue, missingValue);
                            }
                            else if (application is PowerPoint.Presentations)
                            {
                                ((PowerPoint.Presentations)application).Open(oKMDocument.getLocalFilename(), Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,
                                                                             Office.MsoTriState.msoTrue);
                            }
                            else if (application is Visio.Documents)
                            {
                                ((Visio.Documents)application).Open(oKMDocument.getLocalFilename());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                String errorMsg = "ExplorerForm - (edit_Click)\n" + ex.Message + "\n\n" + ex.StackTrace;
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Hide();
            }
        }