Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            PersonObj obj1 = new PersonObj(123, "Max", "Muster");
            PersonObj obj2 = new PersonObj(123, "Max", "Muster");

            if (obj1 == obj2)
            {
                Console.WriteLine("Wahr"); //wird ausgeführt
            }
            else
            {
                Console.WriteLine("Falsch");
            }

            if (obj1.Equals(obj2))
            {
                Console.WriteLine("Wahr");
            }
            else
            {
                Console.WriteLine("Falsch"); //wird ausgeführt
            }


            Person person1 = new Person(1, "Max", "Mustermann");
            Person person2 = new Person(1, "Max", "Mustermann");

            //Tuple
            var deconstrukct = person1;



            if (person1 == person2)
            {
                Console.WriteLine("Wahr");
            }
            else
            {
                Console.WriteLine("Falsch"); //wird ausgeführt
            }

            if (person1.Equals(person2))
            {
                Console.WriteLine("Wahr"); //wird ausgeführt
            }
            else
            {
                Console.WriteLine("Falsch");
            }
        }
        /// <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());

                //创建单位信息
                ProjectEditor.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) ? PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().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) ? PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().projectObj.Name : subjectName) + "'").select("ID").getValue <string>(string.Empty);
                    task.DisplayOrder = GetMaxDisplayOrder() + 1;
                }

                task.Type = string.IsNullOrEmpty(subjectName) || subjectName == PublicReporterLib.PluginLoader.getLocalPluginRoot <PluginRoot>().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(), "错误");
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (CurrentUnitExt == null)
            {
                btnUnitSelect.Text = "点击选择开户帐号!";
                MessageBox.Show("请选择所属单位开户帐号!");
                return;
            }
            if (string.IsNullOrEmpty(txtUnitName.Text))
            {
                MessageBox.Show("请输入单位名称!");
                return;
            }
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("请输入姓名!");
                return;
            }
            if (string.IsNullOrEmpty(txtIDCard.Text))
            {
                MessageBox.Show("请输入身份证号码!");
                return;
            }
            if (string.IsNullOrEmpty(txtJob.Text))
            {
                MessageBox.Show("请输入职务职称!");
                return;
            }
            if (string.IsNullOrEmpty(txtSpecialty.Text))
            {
                MessageBox.Show("请输入从事专业!");
                return;
            }
            if (string.IsNullOrEmpty(cbxSex.Text))
            {
                MessageBox.Show("请输入性别!");
                return;
            }
            if (deBirthday.DateTime == null)
            {
                MessageBox.Show("请输入生日!");
                return;
            }
            if (string.IsNullOrEmpty(txtTelphone.Text))
            {
                MessageBox.Show("请输入座机!");
                return;
            }
            if (string.IsNullOrEmpty(txtMobilePhone.Text))
            {
                MessageBox.Show("请输入手机!");
                return;
            }
            if (string.IsNullOrEmpty(txtAddress.Text))
            {
                MessageBox.Show("请输入通信地址!");
                return;
            }

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

            PersonObj.UnitID      = CurrentUnitExt.ID;
            PersonObj.Name        = txtName.Text;
            PersonObj.IDCard      = txtIDCard.Text;
            PersonObj.Job         = txtJob.Text;
            PersonObj.Specialty   = txtSpecialty.Text;
            PersonObj.Sex         = cbxSex.Text;
            PersonObj.Birthday    = deBirthday.DateTime;
            PersonObj.Telephone   = txtTelphone.Text;
            PersonObj.MobilePhone = txtMobilePhone.Text;
            PersonObj.Address     = txtAddress.Text;

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

            BuildUnitRecord(PersonObj.UnitID, txtUnitName.Text, "未知...");

            DialogResult = DialogResult.OK;
        }