示例#1
0
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     using (BusinessContext context = new BusinessContext())
     {
         var data = context.FamilyMembers.Where(b => !b.IsValid).ToList();
         foreach (FamilyMember family in data)
         {
             if (IDCardValidation.CheckIDCard(family.CardNo))
             {
                 family.IsValid = true;
                 context.Update(family);
             }
         }
         context.SaveChanges();
         var mCount = context.FamilyMembers.Where(b => !b.IsValid).Count();
         MessageBox.Show("共有" + mCount.ToString() + "位同志未通过身份证校验。");
     }
 }
示例#2
0
        private WorkUnit getCollectInfo(string fileName)
        {
            XlsToDb   xlsToDb = new XlsToDb();
            DataTable dt      = xlsToDb.ConvertToDataTable(fileName);
            DataTable dt2     = new DataTable();

            dt2 = dt.Clone();
            Leader         leader         = new Leader();
            List <Leader>  leaders        = new List <Leader>();
            FamilyMember   familyMember   = new FamilyMember();
            ReportBusiness reportBusiness = new ReportBusiness();
            WorkUnit       workUnit       = new WorkUnit();
            int            orderId        = 1;

            try
            {
                workUnit.UnitName = dt.Rows[1][3].ToString();

                if (workUnit.UnitName.Equals(""))
                {
                    throw new Exception("填报单位不能为空!");
                }

                for (int i = 3; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];//9  13

                    if (!(dr[0].ToString().Equals("") && dr[9].ToString().Equals("") && dr[13].ToString().Equals("")))
                    {
                        if (dr[1].ToString().Replace(" ", "").Equals("姓名"))
                        {
                            continue;
                        }

                        //如果表格第1列不为空,说明有领导干部信息
                        if (!dr[0].ToString().Equals(""))
                        {
                            if (dr[0].ToString().IndexOf("填报人") > -1)
                            {
                                workUnit.Filler    = dr[3].ToString();
                                workUnit.Telephone = dr[15].ToString();
                                workUnit.FillDate  = DateTime.Parse(dr[22].ToString());
                                break;
                            }
                            else
                            {
                                if (!dr[1].ToString().Equals(""))
                                {
                                    if (!(leader.CardNo == null || leader.CardNo.Length == 0))
                                    {
                                        if (!(reportBusiness.BusinessName == null || reportBusiness.BusinessName.Length == 0))
                                        {
                                            if (familyMember.ReportBusinesses == null)
                                            {
                                                familyMember.ReportBusinesses = new List <ReportBusiness>();
                                            }
                                            familyMember.ReportBusinesses.Add(reportBusiness);
                                            reportBusiness = new ReportBusiness();
                                        }

                                        if (!(familyMember.CardNo == null || familyMember.CardNo.Length == 0))
                                        {
                                            if (leader.FamilyMembers == null)
                                            {
                                                leader.FamilyMembers = new List <FamilyMember>();
                                            }
                                            leader.FamilyMembers.Add(familyMember);
                                            familyMember = new FamilyMember();
                                        }

                                        leaders.Add(leader);
                                        leader = new Leader();
                                    }
                                    leader.OrderId  = int.Parse(dr[0].ToString());
                                    leader.FullName = dr[1].ToString().Replace(" ", "").Replace(" ", "");
                                    leader.CardNo   = dr[2].ToString();
                                    backgroundWorker1.ReportProgress(0, "正在导入领导干部" + leader.FullName + "信息。\r\n\r\n");

                                    leader.Post = dr[3].ToString();
                                    leader.Rank = dr[4].ToString();
                                    if (dr[5].ToString().Equals("存在"))
                                    {
                                        leader.IsExist = true;
                                    }
                                    else
                                    {
                                        leader.IsExist = false;
                                    }
                                    if (dr[6].ToString().Equals("是"))
                                    {
                                        leader.IsRegulated = true;
                                    }
                                    else
                                    {
                                        leader.IsRegulated = false;
                                    }

                                    if (!dr[7].ToString().Equals(""))
                                    {
                                        leader.ExitModel = dr[7].ToString();
                                    }

                                    familyMember         = new FamilyMember();
                                    orderId              = 1;
                                    familyMember.OrderId = orderId;
                                    orderId++;

                                    familyMember.FullName = leader.FullName;
                                    familyMember.CardNo   = leader.CardNo;
                                    familyMember.Relation = "本人";
                                    familyMember.WorkUnit = "本单位";
                                    familyMember.IsValid  = true;
                                    if (!IDCardValidation.CheckIDCard(familyMember.CardNo))
                                    {
                                        backgroundWorker1.ReportProgress(0, familyMember.FullName + "身份证号码未通过验证。\r\n\r\n");
                                        familyMember.IsValid = false;
                                    }

                                    if (leader.FamilyMembers == null)
                                    {
                                        leader.FamilyMembers = new List <FamilyMember>();
                                    }
                                    leader.FamilyMembers.Add(familyMember);
                                    familyMember = new FamilyMember();
                                }
                            }
                        }

                        if (!dr[9].ToString().Equals(""))
                        {
                            if (!(familyMember.CardNo == null || familyMember.CardNo.Length == 0))
                            {
                                if (!(reportBusiness.BusinessName == null || reportBusiness.BusinessName.Length == 0))
                                {
                                    if (familyMember.ReportBusinesses == null)
                                    {
                                        familyMember.ReportBusinesses = new List <ReportBusiness>();
                                    }
                                    familyMember.ReportBusinesses.Add(reportBusiness);
                                    reportBusiness = new ReportBusiness();
                                }

                                if (leader.FamilyMembers == null)
                                {
                                    leader.FamilyMembers = new List <FamilyMember>();
                                }
                                leader.FamilyMembers.Add(familyMember);
                                familyMember = new FamilyMember();
                            }


                            familyMember.OrderId = orderId;
                            orderId++;
                            familyMember.Relation = dr[8].ToString();
                            familyMember.FullName = dr[9].ToString();
                            familyMember.CardNo   = dr[10].ToString();
                            familyMember.IsValid  = true;
                            backgroundWorker1.ReportProgress(0, "正在导入" + familyMember.Relation + familyMember.FullName + "信息。\r\n\r\n");
                            if (!IDCardValidation.CheckIDCard(familyMember.CardNo))
                            {
                                backgroundWorker1.ReportProgress(0, familyMember.FullName + "身份证号码未通过验证。\r\n\r\n");
                                familyMember.IsValid = false;
                            }
                            familyMember.WorkUnit = dr[11].ToString();
                        }

                        if (!dr[13].ToString().Equals(""))
                        {
                            if (!(reportBusiness.BusinessName == null || reportBusiness.BusinessName.Length == 0))
                            {
                                if (familyMember.ReportBusinesses == null)
                                {
                                    familyMember.ReportBusinesses = new List <ReportBusiness>();
                                }
                                familyMember.ReportBusinesses.Add(reportBusiness);
                                reportBusiness = new ReportBusiness();
                            }


                            reportBusiness.BusinessType  = dr[12].ToString();
                            reportBusiness.BusinessName  = dr[13].ToString();
                            reportBusiness.RegPlace      = dr[14].ToString();
                            reportBusiness.BusinessPlace = dr[15].ToString();
                            reportBusiness.BusinessPost  = dr[16].ToString();

                            if (dr[17].ToString().Equals(""))
                            {
                                reportBusiness.Subscribe = 0;
                            }
                            else
                            {
                                reportBusiness.Subscribe = decimal.Parse(dr[17].ToString());
                            }
                            if (dr[18].ToString().Equals(""))
                            {
                                reportBusiness.PaidinCapital = 0;
                            }
                            else
                            {
                                reportBusiness.PaidinCapital = decimal.Parse(dr[18].ToString());
                            }
                            if (dr[19].ToString().Equals(""))
                            {
                                reportBusiness.Proportion = 0;
                            }
                            else
                            {
                                reportBusiness.Proportion = decimal.Parse(dr[19].ToString());
                            }

                            if (dr[20].ToString().Equals(""))
                            {
                                reportBusiness.EstDate = DateTime.MinValue;
                            }
                            else
                            {
                                reportBusiness.EstDate = DateTime.Parse(dr[20].ToString());
                            }
                            reportBusiness.Nearly3Years1 = dr[21].ToString();
                            reportBusiness.Nearly3Years2 = dr[22].ToString();
                            reportBusiness.Nearly3Years3 = dr[23].ToString();
                            if (dr[24].ToString().Equals("是"))
                            {
                                reportBusiness.IsRelevant = true;
                            }
                            else
                            {
                                reportBusiness.IsRelevant = false;
                            }
                            reportBusiness.Remarks = dr[25].ToString();
                        }
                    }
                }

                if (!(leader.CardNo == null || leader.CardNo.Length == 0))
                {
                    if (!(reportBusiness.BusinessName == null || reportBusiness.BusinessName.Length == 0))
                    {
                        if (familyMember.ReportBusinesses == null)
                        {
                            familyMember.ReportBusinesses = new List <ReportBusiness>();
                        }
                        familyMember.ReportBusinesses.Add(reportBusiness);
                        reportBusiness = new ReportBusiness();
                    }

                    if (!(familyMember.CardNo == null || familyMember.CardNo.Length == 0))
                    {
                        if (leader.FamilyMembers == null)
                        {
                            leader.FamilyMembers = new List <FamilyMember>();
                        }
                        leader.FamilyMembers.Add(familyMember);
                        familyMember = new FamilyMember();
                    }
                    leaders.Add(leader);
                }

                workUnit.Leaders = leaders;

                return(workUnit);
            }
            catch (Exception ex)
            {
                backgroundWorker1.ReportProgress(0, "出错:" + ex.Message + "\r\n\r\n");
                return(null);
            }

            return(null);
        }