Example #1
0
        public override void OnSaveEvent()
        {
            base.OnSaveEvent();

            foreach (DataGridViewRow dgvRow in dgvDetail.Rows)
            {
                if (dgvRow.Cells[1].Value == null || string.IsNullOrEmpty(dgvRow.Cells[1].Value.ToString()))
                {
                    MessageBox.Show("对不起,请输入单位名称!");
                    break;;
                }

                if (dgvRow.Tag != null)
                {
                    //修改
                    ExtFileList efl = (ExtFileList)dgvRow.Tag;

                    //检查是否修改过
                    if (dgvRow.Cells[2].Tag != null)
                    {
                        string sourceFile   = dgvRow.Cells[2].Tag.ToString();
                        string realFileName = DateTime.Now.Ticks + "___" + Path.GetFileName(sourceFile);
                        string destFile     = Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <ProjectReporterPlugin.PluginRoot>().filesDir, realFileName);
                        if (File.Exists(sourceFile))
                        {
                            //旧地址
                            string oldFile = Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <ProjectReporterPlugin.PluginRoot>().filesDir, efl.RealFileName);
                            try
                            {
                                File.Delete(oldFile);
                            }
                            catch (Exception ex) { }

                            //复制新地址
                            File.Copy(sourceFile, destFile, true);

                            //源文件
                            efl.SourceFileName = Path.GetFileName(sourceFile);

                            //真实文件名称
                            efl.RealFileName = realFileName;

                            //是否为军队单位
                            efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                            //单位名称
                            efl.ExtName = dgvRow.Cells[1].Value.ToString();

                            //更新数据
                            efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                        }
                        else
                        {
                            //是否为军队单位
                            efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                            //单位名称
                            efl.ExtName = dgvRow.Cells[1].Value.ToString();

                            //更新数据
                            efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                        }
                    }
                    else
                    {
                        //是否为军队单位
                        efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                        //单位名称
                        efl.ExtName = dgvRow.Cells[1].Value.ToString();

                        //源文件名
                        efl.SourceFileName = string.Empty;

                        //真实文件名
                        efl.RealFileName = string.Empty;

                        //更新数据
                        efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                    }
                }
                else
                {
                    //增加
                    if (dgvRow.Cells[2].Tag != null)
                    {
                        string sourceFile   = dgvRow.Cells[2].Tag.ToString();
                        string realFileName = DateTime.Now.Ticks + "___" + Path.GetFileName(sourceFile);
                        string destFile     = Path.Combine(PublicReporterLib.PluginLoader.getLocalPluginRoot <ProjectReporterPlugin.PluginRoot>().filesDir, realFileName);
                        if (File.Exists(sourceFile))
                        {
                            //复制新地址
                            File.Copy(sourceFile, destFile, true);

                            ExtFileList efll = new ExtFileList();
                            efll.ID             = Guid.NewGuid().ToString();
                            efll.ProjectID      = PublicReporterLib.PluginLoader.getLocalPluginRoot <ProjectReporterPlugin.PluginRoot>().projectObj.ID;
                            efll.ExtName        = dgvRow.Cells[1].Value.ToString();
                            efll.SourceFileName = Path.GetFileName(sourceFile);
                            efll.RealFileName   = realFileName;
                            efll.IsIgnore       = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;
                            efll.copyTo(ConnectionManager.Context.table("ExtFileList")).insert();
                        }
                    }
                    else
                    {
                        ExtFileList efll = new ExtFileList();
                        efll.ID             = Guid.NewGuid().ToString();
                        efll.ProjectID      = PublicReporterLib.PluginLoader.getLocalPluginRoot <ProjectReporterPlugin.PluginRoot>().projectObj.ID;
                        efll.ExtName        = dgvRow.Cells[1].Value.ToString();
                        efll.SourceFileName = string.Empty;
                        efll.RealFileName   = string.Empty;
                        efll.IsIgnore       = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;
                        efll.copyTo(ConnectionManager.Context.table("ExtFileList")).insert();
                    }
                }
            }

            //刷新数据
            RefreshView();
        }
        private void SaveOnly()
        {
            foreach (DataGridViewRow dgvRow in dgvDetail.Rows)
            {
                if (dgvRow.Cells[1].Value == null)
                {
                    dgvRow.Cells[1].Value = string.Empty;
                }

                if (dgvRow.Tag != null)
                {
                    //修改
                    ExtFileList efl = (ExtFileList)dgvRow.Tag;

                    //检查是否修改过
                    if (dgvRow.Cells[2].Tag != null)
                    {
                        string sourceFile   = dgvRow.Cells[2].Tag.ToString();
                        string realFileName = DateTime.Now.Ticks + "___" + Path.GetFileName(sourceFile);
                        string destFile     = Path.Combine(MainForm.ProjectFilesDir, realFileName);
                        if (File.Exists(sourceFile))
                        {
                            //旧地址
                            string oldFile = Path.Combine(MainForm.ProjectFilesDir, efl.RealFileName);
                            try
                            {
                                File.Delete(oldFile);
                            }
                            catch (Exception ex) { }

                            //复制新地址
                            File.Copy(sourceFile, destFile, true);

                            //源文件
                            efl.SourceFileName = Path.GetFileName(sourceFile);

                            //真实文件名称
                            efl.RealFileName = realFileName;

                            //是否为军队单位
                            efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                            //单位名称
                            efl.ExtName = dgvRow.Cells[1].Value.ToString();

                            //更新数据
                            efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                        }
                        else
                        {
                            //是否为军队单位
                            efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                            //单位名称
                            efl.ExtName = dgvRow.Cells[1].Value.ToString();

                            //更新数据
                            efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                        }
                    }
                    else
                    {
                        //是否为军队单位
                        efl.IsIgnore = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;

                        //单位名称
                        efl.ExtName = dgvRow.Cells[1].Value.ToString();

                        //源文件名
                        efl.SourceFileName = string.Empty;

                        //真实文件名
                        efl.RealFileName = string.Empty;

                        //更新数据
                        efl.copyTo(ConnectionManager.Context.table("ExtFileList")).where ("ID='" + efl.ID + "'").update();
                    }
                }
                else
                {
                    //增加
                    if (dgvRow.Cells[2].Tag != null)
                    {
                        string sourceFile   = dgvRow.Cells[2].Tag.ToString();
                        string realFileName = DateTime.Now.Ticks + "___" + Path.GetFileName(sourceFile);
                        string destFile     = Path.Combine(MainForm.ProjectFilesDir, realFileName);
                        if (File.Exists(sourceFile))
                        {
                            //复制新地址
                            File.Copy(sourceFile, destFile, true);

                            ExtFileList efll = new ExtFileList();
                            efll.ID             = Guid.NewGuid().ToString();
                            efll.ProjectID      = MainForm.Instance.ProjectObj.ID;
                            efll.ExtName        = dgvRow.Cells[1].Value.ToString();
                            efll.SourceFileName = Path.GetFileName(sourceFile);
                            efll.RealFileName   = realFileName;
                            efll.IsIgnore       = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;
                            efll.copyTo(ConnectionManager.Context.table("ExtFileList")).insert();
                        }
                    }
                    else
                    {
                        ExtFileList efll = new ExtFileList();
                        efll.ID             = Guid.NewGuid().ToString();
                        efll.ProjectID      = MainForm.Instance.ProjectObj.ID;
                        efll.ExtName        = dgvRow.Cells[1].Value.ToString();
                        efll.SourceFileName = string.Empty;
                        efll.RealFileName   = string.Empty;
                        efll.IsIgnore       = ((bool)dgvRow.Cells[3].Value) ? 1 : 0;
                        efll.copyTo(ConnectionManager.Context.table("ExtFileList")).insert();
                    }
                }
            }
        }