Exemple #1
0
        public List <staff> SelectAllStaffByComID(string comId, int pageIndex, int PageSize, out long totalNum)
        {
            Companyhandling ch       = new Companyhandling();
            List <company>  companys = ch.SearchSonCompany(comId);
            List <string>   comIds   = new List <string>();

            for (int i = 0; i < companys.Count; i++)
            {
                comIds.Add(companys[i].company_Id);
            }

            totalNum = base.SearchCount(d => comIds.Contains(d.staff_OwnCompanyId) && d.staff_IsDel == false);
            long totalPage = totalNum / PageSize;

            if (totalNum % PageSize != 0)
            {
                totalPage++;
            }
            if (pageIndex > totalPage)
            {
                pageIndex = Convert.ToInt32(totalPage);
            }
            if (pageIndex < 0 || pageIndex == 0)
            {
                pageIndex = 1;
            }


            //获取此ID下的所有子公司

            List <staff> staffs = base.Search(d => comIds.Contains(d.staff_OwnCompanyId) && d.staff_IsDel == false, u => u.staff_Department, pageIndex, PageSize);

            return(staffs);
        }
Exemple #2
0
        public List <object> SendEmail(string id)
        {
            admin              HeadOffice = new Admin().Search(d => d.admin_CompanyID == id && d.admin_IsDel == false)[0];
            List <company>     com        = new Companyhandling().SearchSonCompany(id);
            SendEmailOperation se         = new SendEmailOperation();
            List <object>      result     = new List <object>();

            foreach (company c in com)
            {
                List <staff> sf = base.Search(d => d.staff_OwnCompanyId == c.company_Id && d.staff_IsDel == false);
                testInfo     ti = new TestInfo().Search(d => d.testInfo_OwnComPanyId == c.company_Id && d.testInfo_IsDel == false)[0];
                foreach (staff s in sf)
                {
                    if (!se.SendEmail(s.staff_Email, HeadOffice.company.company_Name, HeadOffice.admin_PhoneNum, ti.testInfo_StartTime.ToString(), ti.testInfo_Deadline.ToString(), s.staff_Username, "123456", "staff"))
                    {
                        if (result.Count == 0)
                        {
                            result.Add(0);
                            result.Add("邮件发送结束,但有有员工发送失败,这可能是网络不通畅造成的,你可以在员工管理处重发邮件或在试一次!");
                        }
                        result.Add(s.staff_Id);
                        result.Add(s.staff_TrueName);
                        result.Add(s.company.company_Name);
                        result.Add(s.staff_Department);
                        result.Add(s.staff_Email);
                    }
                }
            }
            if (result.Count == 0)
            {
                result.Add(1);
                result.Add("邮件全部发送成功!");
            }
            return(result);
        }
Exemple #3
0
        private List <object> InspectionCompanyData(DataTable table, string id)
        {
            List <object> status = new List <object>();

            status.Clear();
            if (table.Rows.Count >= 1 && table.Columns.Count == 5)
            {
                List <company> list          = new Companyhandling().SearchSonCompany(id);
                List <string>  companyIdList = new List <string>();
                foreach (company c in list)
                {
                    companyIdList.Add(c.company_Id);
                }
                Company com = new Company();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if ((!String.IsNullOrEmpty(table.Rows[i][0].ToString())) && InspectionCompanyId(table.Rows[i][0].ToString()) && (!String.IsNullOrEmpty(table.Rows[i][1].ToString())) && table.Rows[i][1].ToString().Length <= 32 && table.Rows[i][2].ToString().Length <= 12 && table.Rows[i][3].ToString().Length <= 12 && (!String.IsNullOrEmpty(table.Rows[i][4].ToString())) && InspectionCompanyId(table.Rows[i][4].ToString()))
                    {
                        string importId = table.Rows[i][0].ToString();
                        if (com.SearchCount(d => d.company_Id == importId && d.company_IsDel == false) != 0)
                        {
                            status.Add(0);
                            status.Add("文件导入失败!公司编号" + table.Rows[i][0] + "已被占用.....");
                            return(status);
                        }
                        for (int k = 0; k < table.Rows.Count; k++)
                        {
                            companyIdList.Add(table.Rows[k][0].ToString());
                        }
                        if (!companyIdList.Contains(table.Rows[i][4].ToString()))
                        {
                            status.Add(0);
                            status.Add("文件导入失败!请检查所属公司编号是否正确.....");
                            return(status);
                        }
                    }
                    else
                    {
                        status.Add(0);
                        status.Add("文件导入失败!请检查公司信息是否正确.....");
                        return(status);
                    }
                }
                status.Add(1);
                status.Add("正在写入文件......");
                return(status);
            }
            else
            {
                status.Add(0);
                status.Add("文件导入失败!请检查公司信息是否正确.....");
                return(status);
            }
        }
Exemple #4
0
        public List <staff> SearchAllStaffsByEmail(string comId, string email)
        {
            Companyhandling ch       = new Companyhandling();
            List <company>  companys = ch.SearchSonCompany(comId);
            List <string>   comIds   = new List <string>();

            for (int i = 0; i < companys.Count; i++)
            {
                comIds.Add(companys[i].company_Id);
            }

            List <staff> staffs = base.Search(d => comIds.Contains(d.staff_OwnCompanyId) && d.staff_Email == email && d.staff_IsDel == false).ToList();

            return(staffs);
        }
Exemple #5
0
        private List <object> InspectionStaffData(DataTable table, string id)
        {
            List <object> status = new List <object>();

            if (table.Rows.Count >= 1 && table.Columns.Count == 4)
            {
                List <company> list          = new Companyhandling().SearchSonCompany(id);
                List <string>  companyIdList = new List <string>();
                foreach (company c in list)
                {
                    companyIdList.Add(c.company_Id);
                }
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (!String.IsNullOrEmpty(table.Rows[i][0].ToString()) && table.Rows[i][0].ToString().Length <= 25 && InspectionEmail(table.Rows[i][1].ToString()) && table.Rows[i][1].ToString().Length <= 25 && !String.IsNullOrEmpty(table.Rows[i][2].ToString()) && table.Rows[i][2].ToString().Length <= 25 && !String.IsNullOrEmpty(table.Rows[i][3].ToString()))
                    {
                        if (!companyIdList.Contains(table.Rows[i][3].ToString()))
                        {
                            status.Add(0);
                            status.Add("文件导入失败!请检查文件员工所属公司编号是否正确.....");
                            return(status);
                        }
                    }
                    else
                    {
                        status.Add(0);
                        status.Add("文件导入失败!请检查员工信息是否正确.....");
                        return(status);
                    }
                }
                status.Add(1);
                status.Add("正在写入文件......");
                return(status);
            }
            else
            {
                status.Add(0);
                status.Add("文件导入失败!请检查文件格式是否正确.....");
                return(status);
            }
        }
Exemple #6
0
        public string OutPut(string id, string rootPath, out string zipPath)
        {
            zipPath = null;
            try
            {
                bool complete = new Company().Search(k => k.company_Id == id)[0].company_Status == 2;
                if (!complete)
                {
                    return("调查未完成,如需导出请手动结束调查!");
                }

                //查找出所有公司
                List <company> companys = new Companyhandling().SearchSonCompany(id);

                //1.0 根据公司id找到问卷
                long testInfoId = new TestInfo().Search(k => k.testInfo_OwnComPanyId == id && k.testInfo_IsDel == false)[0].testInfo_Id;
                //1.1 根据问卷找到题目

                List <test> tests = new Test().Search(k => k.test_TestInfoId == testInfoId, u => u.test_Id);

                List <int> plags = new List <int>();
                for (int i = 0; i < tests.Count; i++)
                {
                    if (tests[i][email protected]_Id == 1)
                    {
                        plags.Add(i);
                    }
                }

                string directoryPath = rootPath + @"\" + id;
                if (Directory.Exists(directoryPath))
                {
                    //如果文件夹存在
                    Directory.Delete(directoryPath, true);
                }
                Directory.CreateDirectory(directoryPath);
                foreach (company c in companys)
                {
                    string cid = c.company_Id;
                    //2.0 由公司Id找到所有员工 、spare字段不为 1(有效问卷的员工)
                    List <staff> staffs = new Staff().Search(k => k.staff_OwnCompanyId == cid && k.staff_IsDel == false && string.IsNullOrEmpty(k.staff_Spare) && k.staff_IsWrite == true);
                    //3.0 由员工找到 答案,此答案与问卷表中问题对应
                    key[] keys = new key[staffs.Count];
                    System.Data.DataTable dt  = new System.Data.DataTable("答案");
                    DataColumn            dc1 = new DataColumn("序号", typeof(int));
                    DataColumn            dc2 = new DataColumn("问题", typeof(string));
                    dt.Columns.Add(dc1);
                    dt.Columns.Add(dc2);

                    for (int s = 0; s < staffs.Count; s++)
                    {
                        long sid = staffs[s].staff_Id;
                        keys[s] = new Key().Search(k => k.key_IsDel == false && k.key_StaffId == sid)[0];
                        DataColumn dc = new DataColumn(staffs[s].staff_TrueName, typeof(string));
                        dt.Columns.Add(dc);
                    }
                    DataRow dr = dt.NewRow();
                    dr["问题"] = "一、基础问题";
                    dt.Rows.Add(dr);
                    for (int i = 0; i < plags.Count; i++)
                    {
                        DataRow dr1 = dt.NewRow();
                        dr1["问题"] = tests[plags[i]].question.qusetion_Stem;
                        dr1["序号"] = i + 1;
                        for (int s = 0; s < staffs.Count; s++)
                        {
                            Type   myData = typeof(key);
                            string value  = "key_key" + (plags[i] + 1);

                            foreach (PropertyInfo info in myData.GetProperties())
                            {
                                if (info.Name == value)
                                {
                                    dr1[staffs[s].staff_TrueName] = info.GetValue(keys[s]);
                                }
                            }
                        }
                        dt.Rows.Add(dr1);
                    }
                    DataRow dr2 = dt.NewRow();
                    dr2["问题"] = "二、专业问题";
                    dt.Rows.Add(dr2);
                    int j = 1;
                    for (int i = 0; i < tests.Count; i++)
                    {
                        if (!plags.Contains(i))
                        {
                            DataRow dr1 = dt.NewRow();
                            dr1["序号"] = j++;
                            dr1["问题"] = tests[i].question.qusetion_Stem;

                            for (int s = 0; s < staffs.Count; s++)
                            {
                                Type   myData = typeof(key);
                                string value  = "key_key" + (i + 1);

                                foreach (PropertyInfo info in myData.GetProperties())
                                {
                                    if (info.Name == value)
                                    {
                                        dr1[staffs[s].staff_TrueName] = info.GetValue(keys[s]);
                                    }
                                }
                            }
                            dt.Rows.Add(dr1);
                        }
                    }

                    //4.0 导出到Excel表中,随机命名;
                    //定义一个COM中空类型的对象
                    object            missing = System.Reflection.Missing.Value;
                    Excel.Application app     = new Excel.Application();
                    app.Application.Workbooks.Add(true);
                    Excel.Workbook  book  = (Excel.Workbook)app.ActiveWorkbook;
                    Excel.Worksheet sheet = (Excel.Worksheet)book.ActiveSheet;
                    sheet.Cells[1, 1] = "序号";
                    sheet.Cells[1, 2] = "问题";
                    for (int i = 0; i < staffs.Count; i++)
                    {
                        sheet.Cells[1, i + 3] = staffs[i].staff_TrueName;
                    }
                    //将DataTable赋值给excel
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            sheet.Cells[k + 2, i + 1] = dt.Rows[k][i];
                        }
                    }
                    //保存excel文件
                    string filename = directoryPath + "\\" + c.company_Id + ".xlsx";
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                    book.SaveCopyAs(filename);
                    //关闭文件
                    book.Close(false, missing, missing);
                    //退出excel
                    app.Quit();
                }
                zipPath = rootPath + "\\" + id + ".zip";
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }

                ZipFile.CreateFromDirectory(directoryPath, zipPath);
            }
            catch {
                zipPath = null;
                return("未知错误!");
            }
            return("ok");
        }