Esempio n. 1
0
        //删除
        private void deleteDataBtn_Click(object sender, EventArgs e)
        {
            int         rowIndex = this.dataGridView1.CurrentCell.RowIndex;
            rasterTable ts       = this.dataGridView1.Rows[rowIndex].DataBoundItem as rasterTable;

            if (ts != null)
            {
                MessageBoxButtons messageBoxButtons = MessageBoxButtons.YesNo;
                string            str = string.Format("确定删除路径为{0}的记录吗?", ts.path);
                DialogResult      dr  = MessageBox.Show(str, "取消删除", messageBoxButtons);
                if (dr == DialogResult.Yes)
                {
                    int result = DataAccess.DeletData(ts);
                    if (result > 0)
                    {
                        this.SearchData();
                        MessageBox.Show("删除成功!");
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择需要修改的行");
            }
        }
        /// <summary>
        /// 获取窗口中填写的影像信息,并做初步验证
        /// </summary>
        /// <returns></returns>
        private rasterTable GetImgInfo()
        {
            rasterTable imgInfo = new rasterTable();

            if (!String.IsNullOrEmpty(this.imgPathtxb.Text.Trim()))
            {
                imgInfo.path = this.imgPathtxb.Text.Trim();
            }

            imgInfo.sensor = this.imgSensorTypecomboBox.SelectedItem.ToString();
            imgInfo.rstime = this.imgDateTimePicker.Value;

            if (MyValidateUtil.IsShort(this.imgRowIdtxb.Text))
            {
                imgInfo.rowID = short.Parse(this.imgRowIdtxb.Text);
            }
            if (MyValidateUtil.IsShort(this.imgColIdtxb.Text))
            {
                imgInfo.colID = short.Parse(this.imgColIdtxb.Text);
            }
            if (MyValidateUtil.IsDouble(this.imgCloudtxb.Text))
            {
                imgInfo.cloudage = double.Parse(this.imgCloudtxb.Text);
            }

            return(imgInfo);
        }
 /// <summary>
 /// 根据路径打开文件夹
 /// </summary>
 /// <param name="dataGridView"></param>
 public static void OpenSelectDir(DataGridView dataGridView)
 {
     try
     {
         int         rowIndex = dataGridView.CurrentCell.RowIndex;
         rasterTable ts       = dataGridView.Rows[rowIndex].DataBoundItem as rasterTable;
         if (ts != null)
         {
             string path = ts.path.Trim();
             string dir  = Path.GetDirectoryName(path);
             if (Directory.Exists(dir))
             {
                 System.Diagnostics.Process.Start("Explorer.exe", dir);
             }
             else
             {
                 MessageBox.Show("文件夹不存在!");
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("打开失败,请检查路径是否正确!");
     }
 }
Esempio n. 4
0
        //修改
        private void editDataBtn_Click(object sender, EventArgs e)
        {
            int         rowIndex = this.dataGridView1.CurrentCell.RowIndex;
            rasterTable ts       = this.dataGridView1.Rows[rowIndex].DataBoundItem as rasterTable;

            if (ts != null)
            {
                ModifyDataForm modifyDataForm = new ModifyDataForm(ts, this.dataGridView1, this.GetSearchCondition());
                modifyDataForm.Show();
                this.SearchData();
            }
            else
            {
                MessageBox.Show("请选择需要修改的行");
            }
        }
        //初始化窗口
        private void InitForm(rasterTable ts)
        {
            this.imgPathtxb.Text = ts.path.Trim();
            int index = this.imgSensorTypecomboBox.FindString(ts.sensor.Trim());

            this.imgSensorTypecomboBox.SelectedIndex = index;
            this.imgDateTimePicker.Value             = ts.rstime;
            if (ts.rowID != null)
            {
                this.imgRowIdtxb.Text = ts.rowID.ToString();
            }
            if (ts.colID != null)
            {
                this.imgColIdtxb.Text = ts.colID.ToString();
            }
            if (ts.cloudage != null)
            {
                this.imgCloudtxb.Text = ts.cloudage.ToString();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="imginfo"></param>
        /// <returns></returns>
        public static int  AddImgData(rasterTable imginfo)
        {
            rasterDBEntities rsDbEntities = new rasterDBEntities();
            int resultState = 0;

            try
            {
                rsDbEntities.rasterTable.Add(imginfo);
                resultState = rsDbEntities.SaveChanges();
                return(resultState);
            }
            catch (Exception e)
            {
                MessageBox.Show("添加数据发生异常:" + e.Message);
                return(resultState);
            }
            finally
            {
                rsDbEntities.Dispose();
            }
        }
        /// <summary>
        /// 确认添加按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void confirmAddBtn_Click(object sender, EventArgs e)
        {
            rasterTable rasterTable = this.GetImgInfo();

            if (rasterTable.path != null)
            {
                int result = DataAccess.AddImgData(rasterTable);
                if (result > 0)
                {
                    MessageBox.Show("添加成功!");
                    if (this._dataGridView != null && this._condition != null)
                    {
                        this.UpdateDataGridView();
                    }
                }
            }
            else
            {
                MessageBox.Show("影像路径不能为空!");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="imgTable"></param>
        /// <returns></returns>
        public static int DeletData(rasterTable imgTable)
        {
            rasterDBEntities rsEntities = new rasterDBEntities();
            int resultState             = 0;

            try
            {
                rsEntities.rasterTable.Attach(imgTable);
                rsEntities.rasterTable.Remove(imgTable);
                resultState = rsEntities.SaveChanges();
                return(resultState);
            }
            catch (Exception e)
            {
                MessageBox.Show("删除出现错误:" + e.Message);
                return(resultState);
            }
            finally
            {
                rsEntities.Dispose();
            }
        }
        //修改
        private void confirmAddBtn_Click(object sender, EventArgs e)
        {
            rasterTable modifyTable = this.GetImgInfo();

            if (modifyTable.path != null)
            {
                int resultState = DataAccess.ModifyData(modifyTable);
                if (resultState > 0)
                {
                    MessageBox.Show("数据修改成功");
                    this.UpdateDataGridView();
                }
                else
                {
                    MessageBox.Show("数据修改失败");
                }
            }
            else
            {
                MessageBox.Show("影像路径不能为空!");
            }
        }
        /// <summary>
        /// 添加至显示
        /// </summary>
        /// <param name="dataGridView"></param>
        /// <returns></returns>
        public static IRasterLayer AddImgToShow(DataGridView dataGridView)
        {
            IRasterLayer pRasterLayer = new RasterLayerClass();

            try
            {
                int         rowIndex = dataGridView.CurrentCell.RowIndex;
                rasterTable ts       = dataGridView.Rows[rowIndex].DataBoundItem as rasterTable;
                if (ts != null)
                {
                    string imgPath = ts.path.Trim();
                    pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromFilePath(imgPath);
                }
                return(pRasterLayer);
            }
            catch (Exception exception)
            {
                MessageBox.Show("显示失败,请检查路径或格式是否正确!\n格式为tif或arcgis支持的格式");
                return(null);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="imgInfoTable"></param>
        /// <returns></returns>
        public static int ModifyData(rasterTable imgInfoTable)
        {
            rasterDBEntities rsDbEntities = new rasterDBEntities();
            int resultState = 0;

            try
            {
                //将实体附加到对象管理器中
                rsDbEntities.rasterTable.Attach(imgInfoTable);
                //把当前实体的状态改为Modified
                rsDbEntities.Entry(imgInfoTable).State = EntityState.Modified;
                resultState = rsDbEntities.SaveChanges();
                return(resultState);
            }
            catch (Exception e)
            {
                MessageBox.Show("修改数据发生异常:" + e.Message);
                return(resultState);
            }
            finally
            {
                rsDbEntities.Dispose();
            }
        }
 public ModifyDataForm(rasterTable ts, DataGridView dg, SearchCondition sc)
 {
     InitializeComponent();
     this._selecData = ts;
     InitForm(ts);
 }