Beispiel #1
0
        private IMemoryBlobStream GetStreamFromFile(string fileName)
        {
            MemoryBlobStreamClass fileBlob = new MemoryBlobStreamClass();

            fileBlob.LoadFromFile(fileName);
            return(fileBlob);
        }
Beispiel #2
0
        private void LoadToolbarControlItems(string filePath)
        {
            IBlobStream blobStream = new MemoryBlobStreamClass();
            IStream     stream     = blobStream;

            blobStream.LoadFromFile(filePath);
            axToolbarControl1.LoadItems(stream);
        }
Beispiel #3
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Exception     exError       = null;
            ITransactions pTransactions = null;

            //保存查询配置文件(由本地向数据库保存)
            try
            {
                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();

                pBlobStream.LoadFromFile(_QueryConfigPath);
                //启动事务
                pTransactions = (ITransactions)_TmpWorkSpace;
                if (!pTransactions.InTransaction)
                {
                    pTransactions.StartTransaction();
                }
                SysGisTable sysTable = new SysGisTable(_TmpWorkSpace);
                Dictionary <string, object> dicData = new Dictionary <string, object>();
                dicData.Add("SETTINGVALUE2", pBlobStream);
                dicData.Add("SETTINGNAME", "统计配置");
                //判断是更新还是添加
                //不存在则添加,已存在则更新
                if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='统计配置'"))
                {
                    if (!sysTable.NewRow("SYSSETTING", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                else
                {
                    if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='统计配置'", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                //提交事务
                if (pTransactions.InTransaction)
                {
                    pTransactions.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                //出错则放弃提交
                if (pTransactions.InTransaction)
                {
                    pTransactions.AbortTransaction();
                }
                MessageBox.Show(exError.Message);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
Beispiel #4
0
 private void LoadToolbarControlItems(string filePath)
 {
     //Create a MemoryBlobStream.
     IBlobStream blobStream = new MemoryBlobStreamClass();
     //Get the IStream interface.
     IStream stream = blobStream;
     //Load the stream from the file.
     blobStream.LoadFromFile(filePath);
     //Load the stream into the ToolbarControl.
     axToolbarControl1.LoadItems(stream);
 }
        private void LoadToolbarControlItems(string filePath)
        {
            //Create a MemoryBlobStream
            IBlobStream blobStream = new MemoryBlobStreamClass();
            //Get the IStream interface
            IStream stream = blobStream;

            //Load the stream from the file
            blobStream.LoadFromFile(filePath);
            //Load the stream into the ToolbarControl
            axToolbarControl1.LoadItems(stream);
        }
Beispiel #6
0
 private void LoadBookmarkDatFile(string filePath, ISceneBookmarks _SceneBookmarks)
 {
     try
     {
         IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
         pMemoryBlobStream.LoadFromFile(filePath);
         IObjectStream pObjectStream = new ObjectStreamClass();
         pObjectStream.Stream = pMemoryBlobStream as IStream;
         _SceneBookmarks.LoadBookmarks(pObjectStream.Stream);
     }
     catch { }
 }
Beispiel #7
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdOpenSceneDoc.OnClick implementation
            //文件名称
            string         pOpenFileName = "";
            OpenFileDialog pOpenDoc      = new OpenFileDialog();

            pOpenDoc.Title  = "打开三维空间";
            pOpenDoc.Filter = "ArcScene Document(*.sxd)|*.sxd";
            if (pOpenDoc.ShowDialog() == DialogResult.OK)
            {
                pOpenFileName = pOpenDoc.FileName;
            }
            try
            {
                if (pSceneControl.CheckSxFile(pOpenFileName))
                {
                    pSceneControl.LoadSxFile(pOpenFileName);
                }
                else
                {
                    IScene        pScene        = pSceneControl.Scene;
                    IObjectStream pObjectStream = new ObjectStreamClass();

                    IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
                    pMemoryBlobStream.LoadFromFile(pOpenFileName);

                    pObjectStream.Stream = pMemoryBlobStream;

                    IPersistStream pPersistStream = pScene as IPersistStream;

                    pPersistStream.Load(pObjectStream);
                }
            }
            catch
            {
                //MessageBox.Show("文件选择为空或者选择格式不正确!");
            }
        }
            private static MemoryBlobStreamClass ToBlob(object object_0)
            {
                MemoryBlobStreamClass class2 = new MemoryBlobStreamClass();

                if (object_0 != null)
                {
                    string path = object_0.ToString();
                    try
                    {
                        if (File.Exists(path))
                        {
                            class2.LoadFromFile(path);
                        }
                        else
                        {
                            return(class2);
                        }
                    }
                    catch
                    {
                    }
                }
                return(class2);
            }
Beispiel #9
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter      = "所有文件|*.*",
                Multiselect = true
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                ITableAttachments  attachments       = (ITableAttachments)this.Object.Class;
                IAttachmentManager attachmentManager = attachments.AttachmentManager;
                ListViewItem       item  = null;
                string[]           items = new string[2];
                foreach (string str in dialog.FileNames)
                {
                    IMemoryBlobStream stream = new MemoryBlobStreamClass();
                    stream.LoadFromFile(str);
                    string          fileName = Path.GetFileName(str);
                    AttachmentClass class2   = new AttachmentClass
                    {
                        ContentType = this.GetType(str),
                        Data        = stream,
                        Name        = fileName
                    };
                    IAttachment attachment = class2;
                    items[0] = attachment.Name;
                    items[1] = attachment.Size.ToString();
                    item     = new ListViewItem(items)
                    {
                        Tag = attachment
                    };
                    this.listView1.Items.Add(item);
                }
            }
        }
Beispiel #10
0
        //本地向数据库保存图层目录
        private bool ImportEagleEyset(IWorkspace pWorkspace, string strPath)
        {
            //判断各个参数是否有效
            if (pWorkspace == null)
            {
                return(false);
            }
            Exception     exError       = null;
            ITransactions pTransactions = null;

            //保存图层树(由本地向数据库保存)
            try
            {
                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();
                ///读取路径下的mxd文件
                // System.IO.FileStream pFileStream = File.Create(strPath);
                //if (pFileStream == null) { return false; }
                // byte[] bytes = new byte[pFileStream.Length];
                // pBlobStream.ImportFromMemory(ref bytes[0], (uint)bytes.GetLength(0));
                // pFileStream.Close();
                // pFileStream.Dispose();
                ///读取路径下的mxd文件转化成MemoryBlobStreamClass
                pBlobStream.LoadFromFile(strPath);
                //启动事务
                pTransactions = (ITransactions)pWorkspace;
                if (!pTransactions.InTransaction)
                {
                    pTransactions.StartTransaction();
                }
                SysGisTable sysTable = new SysGisTable(pWorkspace);
                Dictionary <string, object> dicData = new Dictionary <string, object>();
                dicData.Add("SETTINGVALUE2", pBlobStream);
                dicData.Add("SETTINGNAME", "鹰眼图");
                //判断是更新还是添加
                //不存在则添加,已存在则更新
                if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='鹰眼图'"))
                {
                    if (!sysTable.NewRow("SYSSETTING", dicData, out exError))
                    {
                        ErrorHandle.ShowFrmErrorHandle("提示", "添加失败!");
                        return(false);
                    }
                }
                else
                {
                    if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='鹰眼图'", dicData, out exError))
                    {
                        ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!");
                        return(false);
                    }
                }
                //提交事务
                if (pTransactions.InTransaction)
                {
                    pTransactions.CommitTransaction();
                }
                return(true);
            }
            catch (Exception ex)
            {
                //出错则放弃提交
                if (pTransactions.InTransaction)
                {
                    pTransactions.AbortTransaction();
                }
                ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!");
                return(false);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Loads the photo rows into a GPSPhoto featureclass
        /// </summary>
        /// <param name="featureclass">The featureclass.</param>
        private void LoadPhotoRows(IFeatureClass featureclass)
        {
            IDataset       dataset   = (IDataset)featureclass;
            IWorkspace     workspace = dataset.Workspace;
            IWorkspaceEdit edit      = (IWorkspaceEdit)workspace;

            IFeatureCursor cursor = featureclass.Insert(true);

            try
            {
                edit.StartEditing(true);

                foreach (DataRow row in this.Rows)
                {
                    if (!row["Latitude"].Equals(System.DBNull.Value) &&
                        !row["Longitude"].Equals(System.DBNull.Value))
                    {
                        IPoint pt = new PointClass();

                        pt.PutCoords(
                            row["Longitude"].ToDouble(),
                            row["Latitude"].ToDouble());

                        IFeatureBuffer featureBuffer = featureclass.CreateFeatureBuffer();
                        featureBuffer.Shape = (IGeometry)pt;

                        if (!row["FileName"].Equals(System.DBNull.Value))
                        {
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("Filename"),
                                row["FileName"].ToString());
                        }

                        if (!row["Latitude"].Equals(System.DBNull.Value))
                        {
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("Latitude"),
                                row["Latitude"].ToDouble());
                        }

                        if (!row["Longitude"].Equals(System.DBNull.Value))
                        {
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("Longitude"),
                                row["Longitude"].ToDouble());
                        }

                        if (!row["MagneticDirection"].Equals(System.DBNull.Value))
                        {
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("MagneticNorth"),
                                row["MagneticDirection"].ToFloat());
                        }

                        if (!row["FullPath"].Equals(System.DBNull.Value))
                        {
                            string photofilepath = row["FullPath"].ToString();

                            if (!string.IsNullOrEmpty(photofilepath))
                            {
                                featureBuffer.set_Value(featureBuffer.Fields.FindField("FullPath"), photofilepath);

                                //load in photo into blob field:
                                if (this.LoadPhotoIntoBLOB && File.Exists(photofilepath))
                                {
                                    try
                                    {
                                        IMemoryBlobStream blobstream = new MemoryBlobStreamClass();
                                        blobstream.LoadFromFile(photofilepath);
                                        featureBuffer.set_Value(featureBuffer.Fields.FindField("PhotoBLOB"), blobstream);
                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(blobstream);
                                    }
                                    catch (Exception ex)
                                    {
                                        Trace.Write(ex.StackTrace);
                                    }
                                }
                            }
                        }

                        if (!row["Modified"].Equals(System.DBNull.Value))
                        {
                            DateTime modified = Convert.ToDateTime(row["Modified"]);
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("FileLastModified"),
                                modified);
                        }

                        if (!row["DateTaken"].Equals(System.DBNull.Value))
                        {
                            DateTime datetaken = Convert.ToDateTime(row["DateTaken"]);
                            featureBuffer.set_Value(
                                featureBuffer.Fields.FindField("DatePhotoTaken"),
                                datetaken);
                        }



                        cursor.InsertFeature(featureBuffer);
                    }
                }

                edit.StopEditing(true);
            }
            catch (Exception ex)
            {
                if (edit.IsBeingEdited())
                {
                    edit.StopEditing(false);
                }

                Trace.WriteLine(ex.StackTrace);

                throw;
            }
        }
Beispiel #12
0
        //更新系统参数表
        private void buttonXOK_Click(object sender, EventArgs e)
        {
            if (textBoxSettingName.Text.Trim() == "")
            {
                MessageBox.Show("请输入参数名");
                return;
            }
            SysGisTable mSystable            = new SysCommon.Gis.SysGisTable(_TmpWorkSpace);
            Dictionary <string, object> pDic = new Dictionary <string, object>();

            //参数名
            pDic.Add("SETTINGNAME", textBoxSettingName.Text);
            //参数数据类型
            pDic.Add("DATATYPE", comboBoxDataType.Text);
            //参数描述
            pDic.Add("DESCRIPTION", textBoxSettingDescription.Text);
            //参数值(分简单参数值和文件型参数值)
            if (!comboBoxDataType.Text.Contains("File"))
            {
                pDic.Add("SETTINGVALUE", textBoxSettingValue.Text);
            }
            else
            {
                if (File.Exists(textBoxSettingValue.Text))
                {
                    IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();

                    pBlobStream.LoadFromFile(textBoxSettingValue.Text);
                    pDic.Add("SETTINGVALUE2", pBlobStream);
                }
            }
            Exception err  = null;
            bool      bRes = false;

            if (!_isAdd)
            {
                bRes = mSystable.UpdateRow("SYSSETTING", "SETTINGNAME='" + this.textBoxSettingName.Text + "'", pDic, out err);
            }
            else
            {
                bRes = mSystable.NewRow("SYSSETTING", pDic, out err);
            }
            if (!bRes)
            {
                MessageBox.Show(err.Message);
                mSystable = null;
                return;
            }
            if (!_isAdd)    //修改参数
            {
                _CurListItem.SubItems[2].Text = comboBoxDataType.Text;
                _CurListItem.SubItems[3].Text = textBoxSettingDescription.Text;
                if (!comboBoxDataType.Text.Contains("File"))
                {
                    _CurListItem.SubItems[1].Text = textBoxSettingValue.Text;
                }
            }
            else    //添加参数
            {
                ListViewItem pItem = new ListViewItem();
                pItem.SubItems[0].Text = textBoxSettingName.Text;
                pItem.SubItems.Add(""); pItem.SubItems.Add(""); pItem.SubItems.Add("");

                pItem.SubItems[2].Text = comboBoxDataType.Text;
                pItem.SubItems[3].Text = textBoxSettingDescription.Text;
                if (!comboBoxDataType.Text.Contains("File"))
                {
                    pItem.SubItems[1].Text = textBoxSettingValue.Text;
                }
                listView.Items.Add(pItem);
                _CurListItem = pItem;
            }
            _isAdd    = false; //添加完以后,添加状态消失
            mSystable = null;
        }
        private void SaveInitState()
        {
            Plugin.Application.IAppDBIntegraRef _pDBIntegra = _hook as Plugin.Application.IAppDBIntegraRef;
            string strTmpPath  = Application.StartupPath + "\\..\\Temp\\Tmpmxd" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".mxd";
            string strTmpPath2 = Application.StartupPath + "\\..\\Temp\\Tmpmxd" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + "_.mxd";

            if (!System.IO.Directory.Exists(Application.StartupPath + "\\..\\Temp"))
            {
                System.IO.Directory.CreateDirectory(Application.StartupPath + "\\..\\Temp");
            }
            IMxdContents pMxdC;

            pMxdC = _pDBIntegra.MapControl.Map as IMxdContents;

            IMapDocument pMapDocument = new MapDocumentClass();

            //创建地图文档
            pMapDocument.New(strTmpPath);

            //保存信息
            IActiveView pActiveView = _pDBIntegra.MapControl.Map as IActiveView;

            pMapDocument.ReplaceContents(pMxdC);

            try//yjl20110817 防止保存时,其他程序也在打开这个文档而导致共享冲突从而使系统报错
            {
                pMapDocument.Save(true, true);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pMapDocument);
                pMapDocument = null;
                pMapDocument = new MapDocumentClass();
                pMapDocument.Open(strTmpPath, "");
                GeoLayerTreeLib.LayerManager.ModuleMap.SetLayersVisibleAttri(pMapDocument, true);
                ModPublicFun.WriteLog("pMapDocument.Save start");
                pMapDocument.SaveAs(strTmpPath2, true, true);
                ModPublicFun.WriteLog("pMapDocument.Save false");
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    ModPublicFun.WriteLog(ex.Message);
                }
            }
            pMapDocument.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pMapDocument);
            pMapDocument = null;
            try
            {
                System.IO.File.Delete(strTmpPath);
            }
            catch (Exception err2)
            {
            }
            if (System.IO.File.Exists(strTmpPath2))
            {
                SysGisTable mSystable            = new SysCommon.Gis.SysGisTable(Plugin.ModuleCommon.TmpWorkSpace);
                Dictionary <string, object> pDic = new Dictionary <string, object>();
                //参数名
                pDic.Add("SETTINGNAME", "初始加载地图文档");
                //参数数据类型
                pDic.Add("DATATYPE", "MxdFile");
                //参数描述
                //pDic.Add("DESCRIPTION", textBoxSettingDescription.Text);
                //参数值(分简单参数值和文件型参数值)

                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();
                pBlobStream.LoadFromFile(strTmpPath2);
                pDic.Add("SETTINGVALUE2", pBlobStream);

                Exception err  = null;
                bool      bRes = false;
                if (mSystable.ExistData("SYSSETTING", "SETTINGNAME='初始加载地图文档'"))
                {
                    bRes = mSystable.UpdateRow("SYSSETTING", "SETTINGNAME='初始加载地图文档'", pDic, out err);
                }
                else
                {
                    bRes = mSystable.NewRow("SYSSETTING", pDic, out err);
                }
                if (!bRes)
                {
                    MessageBox.Show("保存出错:" + err.Message);
                }
                try
                {
                    System.IO.File.Delete(strTmpPath2);
                }
                catch (Exception err2)
                {
                }
            }
        }
        private void CreateAttachTable(IFeatureClass pFeatureClass,int pID,string pFilePath,string pFileType)
        {
            //要素表是否有附件表,数据库只能是10版本的
             ITableAttachments pTableAtt = pFeatureClass as ITableAttachments;

             if (pTableAtt.HasAttachments == false)
             {
                 pTableAtt.AddAttachments();
             }

             //获取附件管理器
             IAttachmentManager pAttachmentManager = pTableAtt.AttachmentManager;

             //用二进制流读取数据
             IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
             pMemoryBlobStream.LoadFromFile(pFilePath);

             //创建一个附件
             IAttachment pAttachment = new AttachmentClass();

             pAttachment.ContentType=pFileType;

             pAttachment.Name = System.IO.Path.GetFileName(pFilePath);

             pAttachment.Data = pMemoryBlobStream;

             //添加到表中
             pAttachmentManager.AddAttachment(pID, pAttachment);
        }