Пример #1
0
 public bool ImportPeople(List <string> strs, string unitcode, string pid, out string errorMsg)
 {
     errorMsg = string.Empty;
     using (var db = dbFactory.Open())
     {
         using (var dbTran = db.OpenTransaction())
         {
             try
             {
                 foreach (var item in strs)
                 {
                     t_D_UserTableSix six = new t_D_UserTableSix()
                     {
                         gzjl     = item,
                         staitc   = 0,
                         unitcode = unitcode,
                         pid      = pid
                     };
                     db.Insert(six);
                 }
                 dbTran.Commit();
                 return(true);
             }
             catch (Exception ex)
             {
                 dbTran.Rollback();
                 errorMsg = ex.Message;
                 return(false);
             }
         }
     }
 }
        public ActionResult Save(ApplyQualifySixSaveModel model)
        {
            ControllerResult          result  = ControllerResult.SuccResult;
            List <ApplyQualifSixData> peoples = new List <ApplyQualifSixData>();

            var root = XElement.Parse(model.gridStr);
            //  var updataPath = XElement.Parse(model.updatapath);
            List <int?> Ids = new List <int?>();//存储所有的人员编号,方便在后续的对数据库的操作中对人员编号赋值

            var customId = repOne.GetById(model.PId).unitCode;

            foreach (var rowElem in root.Elements("row"))
            {
                var id = (int?)rowElem.Attribute("id");
                if (Ids.Contains(id))//如果已经有这个人员信息,直接下一个
                {
                    continue;
                }

                Ids.Add(id);

                var text  = (string)rowElem;
                var index = 0;
                ApplyQualifSixData people = new ApplyQualifSixData();
                foreach (var cellElem in rowElem.Elements("cell"))
                {
                    switch (index)
                    {
                    case 0:
                        people.xm = (string)cellElem;
                        break;

                    case 1:
                        people.xb = (string)cellElem;
                        break;

                    case 2:
                        people.nl = (string)cellElem;
                        break;

                    case 3:
                        people.zw = (string)cellElem;
                        break;

                    case 4:
                        people.xl = (string)cellElem;
                        break;

                    case 5:
                        people.zy = (string)cellElem;
                        break;

                    case 6:
                        people.zc = (string)cellElem;
                        break;

                    case 7:
                        people.sfzhm = (string)cellElem;
                        break;

                    case 8:
                        people.sgzsh = (string)cellElem;
                        break;

                    case 9:
                        people.csjflb = (string)cellElem;
                        break;

                    case 10:
                        people.csjfnx = (string)cellElem;
                        break;

                    case 11:
                        people.shbxzh = (string)cellElem;
                        break;

                    case 12:
                        people.xlpath = (string)cellElem;
                        break;

                    case 13:
                        people.zcpath = (string)cellElem;
                        break;

                    case 14:
                        people.sfzhmpath = (string)cellElem;
                        break;

                    case 15:
                        people.sgzshpath = (string)cellElem;
                        break;
                    }
                    index++;
                }
                peoples.Add(people);
            }


            using (var db = dbFactory.Open())
            {
                using (var dbTrans = db.OpenTransaction())
                {
                    try
                    {
                        db.Delete <t_D_UserTableSix>(t => t.pid == model.PId && t.unitcode == customId);
                        var index = 0;
                        foreach (var item in peoples)
                        {
                            t_D_UserTableSix oneSxi = new t_D_UserTableSix()
                            {
                                PeopleId = Ids[index],
                                gzjl     = item.ToJson(),
                                unitcode = customId,
                                pid      = model.PId,
                                staitc   = 0
                            };
                            db.Insert(oneSxi);
                            index++;
                        }
                        dbTrans.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbTrans.Rollback();
                        result.ErroMsg = ex.Message;
                        result         = ControllerResult.FailResult;
                    }
                }
            }

            return(Content(result.ToJson()));
        }