Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                TesterInfoBLL TesterInfoBll = new TesterInfoBLL();
                BLL.RptBLL rptBLL = new BLL.RptBLL();

                int totalrecord = 0;

                BLL.TesterInfoBLL tbll = new TesterInfoBLL();
                DataSet ds = tbll.GetListByGuid(string.Empty);
                if (ds != null)
                {
                    totalrecord = ds.Tables[0].Rows.Count;
                    for (int i = 0; i < totalrecord; i++)
                    {
                        string guid = ds.Tables[0].Rows[i][0].ToString();
                        double score = rptBLL.GetTotalSocre(guid);

                        if(false == score.ToString().Equals("0"))
                        {
                            TesterInfoBll.UpdateTesterInfo(guid, "tester_matching", score.ToString());
                        }
                    }

                    Response.Write("Done!");
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message + ex.StackTrace);
            }
        }
Пример #2
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex = Int32.Parse(e.CommandArgument.ToString());//获取点击了第几行
            int posID = Int32.Parse(grVPositionManage.DataKeys[rowIndex].Values[0].ToString());

            if (e.CommandName == "DimSetting")
            {
                Response.Redirect("~/System/DimensionSet.aspx?mode=0&posid=" + posID.ToString());
            }
            if (e.CommandName.Equals("Export") || e.CommandName.Equals("ExportNewData"))//答题信息导出 or 数据导出
            {
                PositionBLL temp = new PositionBLL();
                DimensionBLL dBll = new DimensionBLL();

                DataSet dimDS = dBll.GetDimensionAll();
                DataSet dsAll = new DataSet();

                for (int i = 0; i < dimDS.Tables[0].Rows.Count; i++)
                {
                    int dimID = Int32.Parse(dimDS.Tables[0].Rows[i][0].ToString());
                    DataSet dsa =  temp.GetExportDSIncAllDim(posID,dimID);
                    dsa.Tables[0].TableName = dBll.GetDimension(dimID.ToString()).Dimnm;
                    dsAll.Tables.Add(dsa.Tables[0].Copy());
                }

                //2012.3.14,岗位导出时删除无关维度表 begin.
                for (int i = dsAll.Tables.Count - 1; i >= 0; i--)
                {
                    if (dsAll.Tables[i].Rows.Count < 1)
                    {
                        dsAll.Tables.Remove(dsAll.Tables[i]);
                    }
                }
                dsAll.AcceptChanges();
                //2012.3.14,岗位导出时删除无关维度表 end.

                //新的导出格式---数据导出
                DataSet dsPivot = new DataSet();
                if (e.CommandName.Equals("ExportNewData"))
                {
                    //开始进行pivot
                    string activityName = string.Empty;
                    string testerName = string.Empty;

                    TesterInfoBLL tbll = new TesterInfoBLL();
                    ActivityBLL abll = new ActivityBLL();
                    GuidBLL gbll = new GuidBLL();

                    foreach (DataTable t in dsAll.Tables)
                    {
                        Pivot p = new Pivot(t);
                        DataTable dt = p.PivotData("序列号", "原始得分", AggregateFunction.Sum, "题目编号");
                        p = null;
                        dt.TableName = t.TableName;
                        dt.Columns.Add("项目名称").SetOrdinal(0);
                        dt.Columns.Add("姓名").SetOrdinal(1);

                        foreach (DataRow row in dt.Rows)
                        {
                            string guid = row["序列号"].ToString();
                            row["项目名称"] = abll.GetActivityNM(gbll.GetActivityId(guid));
                            row["姓名"] = tbll.GetUserNameByGUID(guid);
                        }
                        dsPivot.Tables.Add(dt);
                    }
                    //pivot结束
                }
                string filePath = Server.MapPath("../userfiles") + @"\position_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".xls";
                string fileName = Path.GetFileName(filePath);

                if (e.CommandName.Equals("Export"))//原始格式--答题信息导出
                {
                    //2013.10.22 add by conghui for export issue begin.
                    foreach (DataTable dt in dsAll.Tables)
                    {
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            for (int j = 0; j < dt.Rows.Count; j++)
                            {
                                if (dt.Rows[j][i] == DBNull.Value || dt.Rows[j][i] == null)//如果单元格为空
                                {
                                    if (i == 2)//第二列是日期列
                                    {
                                        dt.Rows[j][i] = "1900-1-1";
                                    }
                                    else
                                    {
                                        dt.Rows[j][i] = "";
                                    }
                                }
                                else//单元格非空
                                {
                                    if (i == 2)//将日期强制转化为字符串
                                    {
                                        dt.Rows[j][i] = dt.Rows[j][i].ToString();
                                    }
                                }
                            }
                        }
                    }
                    //2013.10.22 add by conghui for export issue end.

                    ExcelLibrary.DataSetHelper.CreateWorkbook(filePath, dsAll);
                }
                else if (e.CommandName.Equals("ExportNewData"))//新的格式--答题数据导出
                {
                    ExcelLibrary.DataSetHelper.CreateWorkbook(filePath, dsPivot);
                }

                Stream stream = null;
                stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                long bytesToRead = stream.Length;
                Response.Clear();
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);

                while (bytesToRead > 0)
                {
                    if (Response.IsClientConnected)
                    {
                        byte[] buffer = new Byte[10000];
                        int length = stream.Read(buffer, 0, 10000);
                        Response.OutputStream.Write(buffer, 0, length);
                        Response.Flush();
                        bytesToRead = bytesToRead - length;
                    }
                    else
                    {
                        bytesToRead = -1;
                    }
                }
            }
        }
Пример #3
0
        protected void grVActivityManage_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            TesterInfoBLL tinfoBLL = new TesterInfoBLL();
            int rowIndex = Int32.Parse(e.CommandArgument.ToString());//获取点击了第几行
            string usrID = Request.QueryString["users_id"];
            string aID = grVActivityManage.DataKeys[rowIndex].Values["activity_id"].ToString();
            string activityNM = grVActivityManage.DataKeys[rowIndex].Values["activity_name"].ToString();

            DataSet ds = tinfoBLL.GetListByEnterprise(usrID, aID);

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                ds.Tables[0].Columns.Add("项目名称");
                for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
                {
                    ds.Tables[0].Rows[k]["项目名称"] = activityNM;
                    string guid = ds.Tables[0].Rows[k]["tester_sn"].ToString();
                    DataTable dt = GetDimScore(guid);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            if (ds.Tables[0].Columns.IndexOf(dt.Rows[j]["DIMNM"].ToString()) != -1)
                            {
                                ds.Tables[0].Rows[k][dt.Rows[j]["DIMNM"].ToString()] = dt.Rows[j]["DIMSCORE"].ToString();
                            }
                            else
                            {
                                ds.Tables[0].Columns.Add(dt.Rows[j]["DIMNM"].ToString());
                                ds.Tables[0].Rows[k][dt.Rows[j]["DIMNM"].ToString()] = dt.Rows[j]["DIMSCORE"].ToString();
                            }
                        }
                    }
                }

                ds.Tables[0].Columns["tester_sn"].ColumnName = "测试序列号";
                ds.Tables[0].Columns["tester_email"].ColumnName = "E-Mail";
                ds.Tables[0].Columns["tester_name"].ColumnName = "姓名";
                ds.Tables[0].Columns["tester_sex"].ColumnName = "性别";
                ds.Tables[0].Columns["tester_birthdate"].ColumnName = "出生日期";
                ds.Tables[0].Columns["tester_education"].ColumnName = "学历";
                ds.Tables[0].Columns["tester_enterprise"].ColumnName = "公司名称";
                ds.Tables[0].Columns["tester_mobile"].ColumnName = "联系电话";
                ds.Tables[0].Columns["tester_experience"].ColumnName = "工作年龄";
                ds.Tables[0].Columns["tester_application"].ColumnName = "职务";
                ds.Tables[0].Columns["tester_matching"].ColumnName = "匹配度";
                ds.Tables[0].Columns["tester_consistencyscore"].ColumnName = "作答一致性";
                ds.Tables[0].Columns["tester_teststarttime"].ColumnName = "测试开始时间";
                ds.Tables[0].Columns["tester_testendtime"].ColumnName = "测试结束时间";
                ds.Tables[0].Columns["tester_experienceinner"].ColumnName = "本店工作经验";
                ds.Tables[0].Columns["tester_dealer"].ColumnName = "经销商名称";
                ds.Tables[0].Columns["tester_department"].ColumnName = "部门";

                ds.Tables[0].Columns.Remove("tester_enterpriseid");
                ds.Tables[0].Columns["项目名称"].SetOrdinal(0);//放置在第一列

                //清空DBNull.Value值 2011.12.25
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foreach (DataColumn dc in ds.Tables[0].Columns)
                    {
                        if (dr[dc] == DBNull.Value)
                        {
                            dr[dc] = string.Empty;
                        }
                    }
                }

                //开始导出
                string filePath = Server.MapPath("../userfiles") + @"\" +
                    activityNM + "_测评结果_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + ".xls";
                string fileName = Path.GetFileName(filePath);
                ExcelLibrary.DataSetHelper.CreateWorkbook(filePath, ds);
                Stream stream = null;
                stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                long bytesToRead = stream.Length;
                Response.Clear();
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=" +
                    HttpUtility.UrlEncode(fileName, Encoding.UTF8));

                while (bytesToRead > 0)
                {
                    if (Response.IsClientConnected)
                    {
                        byte[] buffer = new Byte[10000];
                        int length = stream.Read(buffer, 0, 10000);
                        Response.OutputStream.Write(buffer, 0, length);
                        Response.Flush();
                        bytesToRead = bytesToRead - length;
                    }
                    else
                    {
                        bytesToRead = -1;
                    }
                }
            }
        }