Ejemplo n.º 1
0
        private void InputDatas(DataTable dt)
        {
            foreach (DataRow row in dt.Rows)
            {
                if (row[2] != null && row[2].ToString().Trim() != "")
                {
                    string workNo = "";
                    try
                    {
                        if (SysUser.FindAllByProperties("WorkNo", row[1].ToString().Trim()).Length == 0)
                        {
                            SysUser sysUser = new SysUser();
                            sysUser.WorkNo = row[1].ToString().Trim();
                            sysUser.Name   = row[2].ToString().Trim();
                            if (row[3].ToString().Trim() == "")
                            {
                                sysUser.LoginName = GetPingyin(row[2].ToString().Trim());
                            }
                            else
                            {
                                sysUser.LoginName = row[3].ToString();
                            }
                            sysUser.Email      = row[5].ToString();
                            sysUser.Remark     = row[6].ToString();
                            sysUser.Status     = 1;
                            sysUser.CreateDate = DateTime.Now;
                            sysUser.Save();
                            if (SysGroup.FindAllByProperties("Name", row[4].ToString().Trim()).Length > 0)
                            {
                                using (new SessionScope())
                                {
                                    SysGroup grp = SysGroup.FindAllByProperties("Name", row[4].ToString().Trim())[0];

                                    IList <string> userIDs = new List <string>();
                                    userIDs.Add(sysUser.UserID);
                                    grp.AddUsers(userIDs);
                                }
                            }
                        }
                        else
                        {
                            if (SysGroup.FindAllByProperties("Name", row[4].ToString().Trim()).Length > 0)
                            {
                                SysUser sysUser = SysUser.FindAllByProperties("WorkNo", row[1].ToString().Trim())[0];
                                using (new SessionScope())
                                {
                                    if (sysUser.RetrieveAllGroup().Where(en => en.Type == 2 && en.Name != row[4].ToString()).Count() == 0)
                                    {
                                        if (sysUser.RetrieveAllGroup().Where(en => en.Type == 2).Count() > 0)
                                        {
                                            foreach (SysGroup gp in sysUser.RetrieveAllGroup().Where(en => en.Type == 2))
                                            {
                                                gp.User.Remove(sysUser);
                                            }
                                        }
                                        SysGroup       grp     = SysGroup.FindAllByProperties("Name", row[4].ToString().Trim())[0];
                                        IList <string> userIDs = new List <string>();
                                        userIDs.Add(sysUser.UserID);
                                        grp.AddUsers(userIDs);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }
            }
        }