public override void OnSaveEvent()
        {
            base.OnSaveEvent();

            if (GetZongZiKetiCount() == 1)
            {
                int     saveCount = 0;
                Project proj      = null;
                foreach (DataGridViewRow dgvRow in dgvDetail.Rows)
                {
                    Person personObj = null;

                    if (dgvRow.Tag == null)
                    {
                        //新行
                        proj = new Project();
                    }
                    else
                    {
                        //已存在数据
                        proj = (Project)dgvRow.Tag;
                    }

                    if (dgvRow.Cells[2].Value == null)
                    {
                        MessageBox.Show("对不起,请输入密级!");
                        return;
                    }

                    if (dgvRow.Cells[1].Value == null)
                    {
                        MessageBox.Show("对不起,请输入课题名称!");
                        return;
                    }

                    if (dgvRow.Cells[3].Value == null)
                    {
                        MessageBox.Show("对不起,请输入负责人姓名");
                        return;
                    }
                    if (dgvRow.Cells[4].Value == null)
                    {
                        MessageBox.Show("对不起,请输入负责人身份证");
                        return;
                    }
                    if (dgvRow.Cells[5].Value == null)
                    {
                        MessageBox.Show("对不起,请输入承担单位名称!");
                        return;
                    }
                    if (dgvRow.Cells[6].Tag == null)
                    {
                        //MessageBox.Show("对不起,请选择承担单位开户帐号!");
                        //return;
                        dgvRow.Cells[6].Tag = Guid.NewGuid().ToString();
                    }

                    decimal totalMoney = 0;
                    if (dgvRow.Cells[7].Value != null && decimal.TryParse(dgvRow.Cells[7].Value.ToString(), out totalMoney) == false)
                    {
                        MessageBox.Show("对不起,请输入正确的研究经费!");
                        return;
                    }

                    saveCount++;
                    if (saveCount >= 11)
                    {
                        MessageBox.Show("对不起,最多只能添加10个课题!");
                        break;
                    }

                    //新的人员ID
                    string newPersonId = Guid.NewGuid().ToString();

                    //查找人员信息
                    personObj = ConnectionManager.Context.table("Person").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").select("*").getItem <Person>(new Person());

                    //删除这条记录
                    ConnectionManager.Context.table("Person").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").delete();

                    //更新人员ID
                    ConnectionManager.Context.table("Task").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").set("PersonID", newPersonId).update();

                    if (personObj == null)
                    {
                        personObj = new Person();
                    }

                    personObj.ID     = newPersonId;
                    personObj.Name   = dgvRow.Cells[3].Value.ToString();
                    personObj.UnitID = dgvRow.Cells[6].Tag.ToString();
                    personObj.IDCard = dgvRow.Cells[4].Value.ToString();
                    //ProjectPersonObj.IDCard = txtMPersonIDCard.Text;
                    //ProjectPersonObj.Sex = cbxMPersonSex.Text;
                    //ProjectPersonObj.Job = txtMPersonJob.Text;
                    //ProjectPersonObj.Birthday = txtMPersonBirthday.DateTime;
                    //ProjectPersonObj.Telephone = txtMPersonTelephone.Text;
                    //ProjectPersonObj.MobilePhone = txtMPersonMobilephone.Text;
                    personObj.copyTo(ConnectionManager.Context.table("Person")).insert();

                    //课题部分
                    proj.Name        = dgvRow.Cells[1].Value.ToString();
                    proj.SecretLevel = dgvRow.Cells[2].Value.ToString();
                    proj.Type        = "课题";
                    proj.ParentID    = MainForm.Instance.ProjectObj.ID;
                    proj.UnitID      = dgvRow.Cells[6].Tag.ToString();
                    proj.Type2       = dgvRow.Cells[8].Value != null ? (((bool)dgvRow.Cells[8].Value) == true ? "总体课题" : "非总体课题") : "非总体课题";

                    //创建课题单位
                    if (dgvRow.Cells[5].Tag != null && ((Unit)dgvRow.Cells[5].Tag).ID != null)
                    {
                        Unit unitObj = (Unit)dgvRow.Cells[5].Tag;
                        unitObj.UnitName = dgvRow.Cells[5].Value.ToString();
                        NewProjectEditor.BuildUnitRecord(dgvRow.Cells[6].Tag.ToString(), unitObj.UnitName, unitObj.UnitName, unitObj.UnitName, unitObj.ContactName, unitObj.Telephone, unitObj.UnitType, unitObj.Address);
                    }
                    else
                    {
                        NewProjectEditor.BuildUnitRecord(dgvRow.Cells[6].Tag.ToString(), dgvRow.Cells[5].Value.ToString(), dgvRow.Cells[5].Value.ToString(), dgvRow.Cells[5].Value.ToString(), "未知", "未知", "课题单位", "未知");
                    }

                    //添加或更新课题数据
                    if (string.IsNullOrEmpty(proj.ID))
                    {
                        //新行
                        if (dgvRow.Cells[0].Tag != null)
                        {
                            //点击了生成标签页,存在已生成的ID
                            proj.ID = dgvRow.Cells[0].Tag.ToString();
                        }
                        else
                        {
                            //没有点击生成标签页,需要生成ID
                            proj.ID = Guid.NewGuid().ToString();
                        }

                        proj.copyTo(ConnectionManager.Context.table("Project")).insert();
                    }
                    else
                    {
                        //更新
                        proj.copyTo(ConnectionManager.Context.table("Project")).where ("ID='" + proj.ID + "'").update();
                    }

                    //任务分工部分
                    Task task = ConnectionManager.Context.table("Task").where ("ProjectID='" + proj.ID + "' and Role = '负责人'").select("*").getItem <Task>(new Task());
                    if (task == null || string.IsNullOrEmpty(task.ID))
                    {
                        //新行
                        task              = new Task();
                        task.ProjectID    = proj.ID;
                        task.DisplayOrder = YanJiuGuGanEditor.GetMaxDisplayOrder() + 1;
                    }

                    task.PersonID   = personObj.ID;
                    task.IDCard     = personObj.IDCard;
                    task.Role       = "负责人";
                    task.Type       = "课题";
                    task.TotalMoney = totalMoney;

                    if (string.IsNullOrEmpty(task.ID))
                    {
                        task.ID = Guid.NewGuid().ToString();
                        task.copyTo(ConnectionManager.Context.table("Task")).insert();
                    }
                    else
                    {
                        task.copyTo(ConnectionManager.Context.table("Task")).where ("ID='" + task.ID + "'").update();
                    }
                }

                //同步阶段数据
                SyncStepList();

                //保存详细页所写的内容
                foreach (KryptonPage kp in ParentNavigator.Pages)
                {
                    if (kp.Tag != null && kp.Tag.ToString() == "KeTiDynamic")
                    {
                        if (kp.Controls.Count >= 1)
                        {
                            try
                            {
                                ((BaseEditor)kp.Controls[0]).OnSaveEvent();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("对不起,课题[" + kp.Text + "]的详细保存失败!Ex:" + ex.ToString());
                            }
                        }
                    }
                }

                //刷新当前页
                RefreshView();

                //刷新课题阶段划分表
                foreach (BaseEditor be in MainForm.Instance.EditorMaps.Values)
                {
                    if (be is KeTiJieDuanHuaFenEditor)
                    {
                        //刷新列表
                        be.RefreshView();
                    }
                    else if (be is YanJiuGuGanEditor)
                    {
                        //刷新列表
                        be.RefreshView();
                    }
                }
            }
            else
            {
                MessageBox.Show("对不起,必须并且只能有一个总体课题!");
            }
        }
        public void SaveOnly()
        {
            if (GetZongZiKetiCount() == 1)
            {
                int     saveCount = 0;
                Project proj      = null;
                foreach (DataGridViewRow dgvRow in dgvDetail.Rows)
                {
                    Person personObj = null;

                    if (dgvRow.Tag == null)
                    {
                        //新行
                        proj = new Project();
                    }
                    else
                    {
                        //已存在数据
                        proj = (Project)dgvRow.Tag;
                    }

                    if (dgvRow.Cells[2].Value == null)
                    {
                        dgvRow.Cells[2].Value = "秘密";
                    }
                    if (dgvRow.Cells[1].Value == null)
                    {
                        dgvRow.Cells[1].Value = string.Empty;
                    }
                    if (dgvRow.Cells[3].Value == null)
                    {
                        dgvRow.Cells[3].Value = string.Empty;
                    }
                    if (dgvRow.Cells[4].Value == null)
                    {
                        dgvRow.Cells[4].Value = string.Empty;
                    }
                    if (dgvRow.Cells[5].Value == null)
                    {
                        dgvRow.Cells[5].Value = string.Empty;
                    }
                    if (dgvRow.Cells[6].Tag == null)
                    {
                        //MessageBox.Show("对不起,请选择承担单位开户帐号!");
                        //return;
                        dgvRow.Cells[6].Tag = Guid.NewGuid().ToString();
                    }

                    decimal totalMoney = 0;
                    if (dgvRow.Cells[7].Value != null && decimal.TryParse(dgvRow.Cells[7].Value.ToString(), out totalMoney) == false)
                    {
                        MessageBox.Show("对不起,请输入正确的研究经费!");
                        return;
                    }

                    saveCount++;
                    if (saveCount >= 11)
                    {
                        MessageBox.Show("对不起,最多只能添加10个课题!");
                        break;
                    }

                    //新的人员ID
                    string newPersonId = Guid.NewGuid().ToString();

                    //查找人员信息
                    personObj = ConnectionManager.Context.table("Person").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").select("*").getItem <Person>(new Person());

                    //删除这条记录
                    ConnectionManager.Context.table("Person").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").delete();

                    //更新人员ID
                    ConnectionManager.Context.table("Task").where ("IDCard = '" + dgvRow.Cells[4].Value + "'").set("PersonID", newPersonId).update();

                    if (personObj == null)
                    {
                        personObj = new Person();
                    }

                    personObj.ID     = newPersonId;
                    personObj.Name   = dgvRow.Cells[3].Value.ToString();
                    personObj.UnitID = dgvRow.Cells[6].Tag.ToString();
                    personObj.IDCard = dgvRow.Cells[4].Value.ToString();
                    //ProjectPersonObj.IDCard = txtMPersonIDCard.Text;
                    //ProjectPersonObj.Sex = cbxMPersonSex.Text;
                    //ProjectPersonObj.Job = txtMPersonJob.Text;
                    //ProjectPersonObj.Birthday = txtMPersonBirthday.DateTime;
                    //ProjectPersonObj.Telephone = txtMPersonTelephone.Text;
                    //ProjectPersonObj.MobilePhone = txtMPersonMobilephone.Text;
                    personObj.copyTo(ConnectionManager.Context.table("Person")).insert();

                    //课题部分
                    proj.Name        = dgvRow.Cells[1].Value.ToString();
                    proj.SecretLevel = dgvRow.Cells[2].Value.ToString();
                    proj.Type        = "课题";
                    proj.ParentID    = MainForm.Instance.ProjectObj.ID;
                    proj.UnitID      = dgvRow.Cells[6].Tag.ToString();
                    proj.Type2       = dgvRow.Cells[8].Value != null ? (((bool)dgvRow.Cells[8].Value) == true ? "总体课题" : "非总体课题") : "非总体课题";

                    //创建课题单位
                    if (dgvRow.Cells[5].Tag != null && ((Unit)dgvRow.Cells[5].Tag).ID != null)
                    {
                        Unit unitObj = (Unit)dgvRow.Cells[5].Tag;
                        unitObj.UnitName = dgvRow.Cells[5].Value.ToString();
                        NewProjectEditor.BuildUnitRecord(dgvRow.Cells[6].Tag.ToString(), unitObj.UnitName, unitObj.UnitName, unitObj.UnitName, unitObj.ContactName, unitObj.Telephone, unitObj.UnitType, unitObj.Address);
                    }
                    else
                    {
                        NewProjectEditor.BuildUnitRecord(dgvRow.Cells[6].Tag.ToString(), dgvRow.Cells[5].Value.ToString(), dgvRow.Cells[5].Value.ToString(), dgvRow.Cells[5].Value.ToString(), "未知", "未知", "课题单位", "未知");
                    }

                    //添加或更新课题数据
                    if (string.IsNullOrEmpty(proj.ID))
                    {
                        //新行
                        if (dgvRow.Cells[0].Tag != null)
                        {
                            //点击了生成标签页,存在已生成的ID
                            proj.ID = dgvRow.Cells[0].Tag.ToString();
                        }
                        else
                        {
                            //没有点击生成标签页,需要生成ID
                            proj.ID = Guid.NewGuid().ToString();
                        }

                        proj.copyTo(ConnectionManager.Context.table("Project")).insert();
                    }
                    else
                    {
                        //更新
                        proj.copyTo(ConnectionManager.Context.table("Project")).where ("ID='" + proj.ID + "'").update();
                    }

                    //任务分工部分
                    Task task = ConnectionManager.Context.table("Task").where ("ProjectID='" + proj.ID + "' and Role = '负责人'").select("*").getItem <Task>(new Task());
                    if (task == null || string.IsNullOrEmpty(task.ID))
                    {
                        //新行
                        task              = new Task();
                        task.ProjectID    = proj.ID;
                        task.DisplayOrder = YanJiuGuGanEditor.GetMaxDisplayOrder() + 1;
                    }

                    task.PersonID   = personObj.ID;
                    task.IDCard     = personObj.IDCard;
                    task.Role       = "负责人";
                    task.Type       = "课题";
                    task.TotalMoney = totalMoney;

                    if (string.IsNullOrEmpty(task.ID))
                    {
                        task.ID = Guid.NewGuid().ToString();
                        task.copyTo(ConnectionManager.Context.table("Task")).insert();
                    }
                    else
                    {
                        task.copyTo(ConnectionManager.Context.table("Task")).where ("ID='" + task.ID + "'").update();
                    }
                }

                //同步阶段数据
                SyncStepList();
            }
            //else
            //{
            //    MessageBox.Show("对不起,必须并且只能有一个总体课题!");
            //}
        }
        /// <summary>
        /// 插入骨干人员信息
        /// </summary>
        /// <param name="dr">行数据</param>
        private void insertPersonFromDataRow(DataRow dr)
        {
            UnitExtService _unitInforService = new UnitExtService();

            try
            {
                //加载字段
                string unitName = dr["单位名称"] != null ? dr["单位名称"].ToString() : string.Empty;
                //string unitType = dr["隶属部门"] != null ? dr["隶属部门"].ToString() : string.Empty;
                string unitType              = "其它";
                string unitAddress           = dr["单位通信地址"] != null ? dr["单位通信地址"].ToString() : string.Empty;
                string unitContact           = dr["单位联系人"] != null ? dr["单位联系人"].ToString() : string.Empty;
                string unitTelephone         = dr["单位联系电话"] != null ? dr["单位联系电话"].ToString() : string.Empty;
                string personName            = dr["姓名"] != null ? dr["姓名"].ToString() : string.Empty;
                string personIDCard          = dr["身份证"] != null ? dr["身份证"].ToString() : string.Empty;
                string personJob             = dr["职务职称"] != null ? dr["职务职称"].ToString() : string.Empty;
                string personSpecialty       = dr["从事专业"] != null ? dr["从事专业"].ToString() : string.Empty;
                string personSex             = dr["性别"] != null ? dr["性别"].ToString() : string.Empty;
                string personBirthday        = dr["出生年月"] != null ? dr["出生年月"].ToString() : string.Empty;
                string personTelephone       = dr["座机"] != null ? dr["座机"].ToString() : string.Empty;
                string personMobilePhone     = dr["手机"] != null ? dr["手机"].ToString() : string.Empty;
                string personAddress         = dr["通信地址"] != null ? dr["通信地址"].ToString() : string.Empty;
                string subjectName           = dr["课题名称"] != null ? dr["课题名称"].ToString() : string.Empty;
                string jobInProjectOrSubject = dr["项目或课题中职务"] != null ? dr["项目或课题中职务"].ToString() : string.Empty;
                string taskInProject         = dr["任务分工"] != null ? dr["任务分工"].ToString() : string.Empty;
                string timeInProject         = dr["每年为本项目工作时间(月)"] != null ? dr["每年为本项目工作时间(月)"].ToString() : string.Empty;

                //进行必要字段的校验

                //检查身份证
                if (string.IsNullOrEmpty(personIDCard))
                {
                    throw new Exception("对不起,'身份证'不能为空");
                }

                //检查出生日期
                DateTime dt = DateTime.MinValue;
                if (DateTime.TryParse(personBirthday, out dt) == false)
                {
                    throw new Exception("对不起,'出生日期'格式错误!");
                }

                //检查项目或课题中职务f
                if (jobInProjectOrSubject != "成员" && jobInProjectOrSubject != "负责人")
                {
                    throw new Exception("对不起,'项目或课题中职务'里只能写成员或负责人!");
                }

                //检查性别
                if (personSex != "男" && personSex != "女")
                {
                    throw new Exception("对不起,性别必须是'男'或'女'");
                }

                //检查每年为本项目工作时间
                int timeResult = 0;
                if (int.TryParse(timeInProject, out timeResult) == false)
                {
                    throw new Exception("对不起,'每年为本项目工作时间'只能是数字!");
                }

                //检查课题名称
                if (!string.IsNullOrEmpty(subjectName))
                {
                    long subjectCount = ConnectionManager.Context.table("Project").where ("Name='" + subjectName + "'").select("count(*)").getValue <long>(0);
                    if (subjectCount <= 0)
                    {
                        throw new Exception("对不起,'" + subjectName + "'不是有效的课题名称!");
                    }
                }

                //检查非空
                foreach (DataColumn dc in dr.Table.Columns)
                {
                    if (dc.ColumnName == "课题名称")
                    {
                        continue;
                    }
                    else if (dr[dc.ColumnName] == null || dr[dc.ColumnName].ToString() == string.Empty)
                    {
                        throw new Exception("对不起,'" + dc.ColumnName + "'不能为空!");
                    }
                }

                #region 插入人员数据

                ////判断是不是需要创建单位
                //UnitExt unitExtObj = ConnectionManager.Context.table("UnitExt").where("UnitBankNo='" + unitBankNo + "'").select("*").getItem<UnitExt>(new UnitExt());

                ////判断是否需要创建单位信息
                //if (string.IsNullOrEmpty(unitExtObj.ID))
                //{
                //    //需要创建单位

                //    //创建帐号信息
                //    if (unitExtObj == null)
                //    {
                //        unitExtObj = new UnitExt();
                //    }
                //    unitExtObj.UnitName = unitName;
                //    unitExtObj.UnitType = unitType;
                //    unitExtObj.UnitBankUser = unitBankUser;
                //    unitExtObj.UnitBankName = unitBankName;
                //    unitExtObj.UnitBankNo = unitBankNo;
                //    unitExtObj.IsUserAdded = 1;
                //    _unitInforService.UpdateUnitInfors(new List<UnitExt>(new UnitExt[] { unitExtObj }));
                //}

                string unitID = string.Empty;
                unitID = ConnectionManager.Context.table("Unit").where ("UnitName='" + unitName + "'").select("ID").getValue <string>(Guid.NewGuid().ToString());

                //创建单位信息
                NewProjectEditor.BuildUnitRecord(unitID, unitName, unitName, unitName, unitContact, unitTelephone, unitType, unitAddress);

                //创建人员
                Person PersonObj    = ConnectionManager.Context.table("Person").where ("IDCard = '" + personIDCard + "'").select("*").getItem <Person>(new Person());
                string newPersonIds = Guid.NewGuid().ToString();

                if (PersonObj != null && PersonObj.ID != null && PersonObj.ID.Length > 1)
                {
                    //删除旧的人员信息
                    ConnectionManager.Context.table("Person").where ("IDCard = '" + personIDCard + "'").delete();

                    //更新人员ID
                    ConnectionManager.Context.table("Task").where ("IDCard = '" + personIDCard + "'").set("PersonID", newPersonIds).update();
                }
                else
                {
                    PersonObj = new Person();
                }

                PersonObj.ID          = newPersonIds;
                PersonObj.UnitID      = unitID;
                PersonObj.Name        = personName;
                PersonObj.Sex         = personSex;
                PersonObj.Birthday    = DateTime.Parse(personBirthday);
                PersonObj.IDCard      = personIDCard;
                PersonObj.Job         = personJob;
                PersonObj.Specialty   = personSpecialty;
                PersonObj.Address     = personAddress;
                PersonObj.Telephone   = personTelephone;
                PersonObj.MobilePhone = personMobilePhone;
                PersonObj.copyTo(ConnectionManager.Context.table("Person")).insert();

                //添加/修改Task
                Task task = ConnectionManager.Context.table("Task").where ("IDCard='" + personIDCard + "' and ProjectID in (select ID from Project where Name = '" + (string.IsNullOrEmpty(subjectName) ? MainForm.Instance.ProjectObj.Name : subjectName) + "')").select("*").getItem <Task>(new Task());
                if (task == null || string.IsNullOrEmpty(task.ID))
                {
                    //新行
                    task              = new Task();
                    task.ProjectID    = ConnectionManager.Context.table("Project").where ("Name = '" + (string.IsNullOrEmpty(subjectName) ? MainForm.Instance.ProjectObj.Name : subjectName) + "'").select("ID").getValue <string>(string.Empty);
                    task.DisplayOrder = GetMaxDisplayOrder() + 1;
                }

                task.Type = string.IsNullOrEmpty(subjectName) || subjectName == MainForm.Instance.ProjectObj.Name ? "项目" : "课题";
                task.Role = jobInProjectOrSubject;

                task.PersonID = PersonObj.ID;
                task.IDCard   = PersonObj.IDCard;

                task.Content   = taskInProject;
                task.TotalTime = int.Parse(timeInProject);

                if (string.IsNullOrEmpty(task.ID))
                {
                    //insert
                    task.ID = Guid.NewGuid().ToString();
                    task.copyTo(ConnectionManager.Context.table("Task")).insert();
                }
                else
                {
                    //update
                    task.copyTo(ConnectionManager.Context.table("Task")).where ("ID='" + task.ID + "'").update();
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("插入错误!Ex:" + ex.ToString(), "错误");
            }
        }