예제 #1
0
        /// <summary>
        /// ����
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                MSExcel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

                try
                {
                    excelApp.Visible = false;
                    excelApp.DisplayAlerts = false;
                    /*excelApp.DisplayClipboardWindow = false;
                    // excelApp.DisplayDocumentActionTaskPane = false;
                    excelApp.DisplayDocumentInformationPanel = false;
                    excelApp.DisplayExcel4Menus = false;
                    excelApp.DisplayFormulaAutoComplete = false;
                    excelApp.DisplayFormulaBar = false;
                    excelApp.DisplayFullScreen = false;
                    excelApp.DisplayFunctionToolTips = false;
                    excelApp.DisplayInfoWindow = false;
                    excelApp.DisplayInsertOptions = false;
                    excelApp.DisplayNoteIndicator = false;
                    excelApp.DisplayPasteOptions = false;
                    excelApp.DisplayRecentFiles = false;
                    excelApp.Interactive = false;*/
                    excelApp.DisplayScrollBars = true;
                    excelApp.DisplayStatusBar = true;

                    MSExcel.Workbooks workBooks = excelApp.Workbooks;

                    // MSExcel.Workbook workbook = workBooks.Add(MSExcel.XlWBATemplate.xlWBATWorksheet);
                    MSExcel.Workbook workbook = (MSExcel.Workbook)workBooks.Open(Server.MapPath("DataTemplate.xlsx"),
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value);

                    MSExcel.Worksheet worksheet = (MSExcel.Worksheet)excelApp.Worksheets.get_Item(1);

                    MSExcel.Range titleRange = worksheet.get_Range("1:1", Missing.Value);
                    titleRange.Font.Bold = true; // ����Ӵ�
                    titleRange.HorizontalAlignment = XlVAlign.xlVAlignCenter;

                    if (worksheet == null)
                    {
                        Console.WriteLine("ERROR in worksheet == null");
                    }

                    System.Collections.Generic.List<string> titles = new System.Collections.Generic.List<string>();
                    DataSet ds = new DataSet();
                    int curRow = 2;
                    string fileDir = Server.MapPath(@"\ResearchData\TmpFiles\");
                    string fileName = String.Empty;

                    #region �����

                    switch (DataType.SelectedValue)
                    {
                        case "1":
                            ExtendBLL.ResearchResult rr = new ExtendBLL.ResearchResult();
                            titles = rr.GetTitles();
                            ds = rr.GetAllList();

                            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                            {
                                worksheet.Cells[curRow, 1] = row["ID"];
                                worksheet.Cells[curRow, 2] = row["ChengGuoMingCheng"];
                                worksheet.Cells[curRow, 3] = row["ChengGuoLeiBie"];
                                worksheet.Cells[curRow, 4] = row["ChengGuoZuoZe"];
                                worksheet.Cells[curRow, 5] = row["DanWeiMingCheng"];
                                worksheet.Cells[curRow, 6] = row["BanZhengShiJian"];
                                worksheet.Cells[curRow, 7] = row["XueYuanShenHe"];
                                worksheet.Cells[curRow, 8] = row["XueXiaoShenHe"];
                                worksheet.Cells[curRow, 9] = row["ChengGuoDengJi"];
                                worksheet.Cells[curRow, 10] = row["ShuMingZuoZe"];
                                worksheet.Cells[curRow, 11] = row["ChengGuoBianHao"];
                                worksheet.Cells[curRow, 12] = row["ShiFouJiangLi"];
                                worksheet.Cells[curRow, 13] = row["ShuMingDanWei"];
                                worksheet.Cells[curRow, 14] = row["ChengGuoLieXing"];

                                curRow += 1;
                            }

                            fileName = "ResearchResult-" + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xlsx";

                            break;
                        case "2":
                            ExtendBLL.ResearchCost rc = new ExtendBLL.ResearchCost();
                            titles = rc.GetTitles();
                            ds = rc.GetAllList();

                            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                            {
                                worksheet.Cells[curRow, 1] = row["ID"];
                                worksheet.Cells[curRow, 2] = row["ChongJingZiHao"];
                                worksheet.Cells[curRow, 3] = row["XiangMuMingCheng"];
                                worksheet.Cells[curRow, 4] = row["XiangMuLieBie"];
                                worksheet.Cells[curRow, 5] = row["FuZeRen"];
                                worksheet.Cells[curRow, 6] = row["DanWeiMingCheng"];
                                worksheet.Cells[curRow, 7] = row["ShiDaoJingFei"];
                                worksheet.Cells[curRow, 8] = row["RuanJianJingFei"];
                                worksheet.Cells[curRow, 9] = row["GuangLiFeiBiLi"];
                                worksheet.Cells[curRow, 10] = row["GuangLiFei"];
                                worksheet.Cells[curRow, 11] = row["JingBanRen"];
                                worksheet.Cells[curRow, 12] = row["ShiDaoShiJian"];
                                worksheet.Cells[curRow, 13] = row["HuiChuYinHang"];

                                curRow += 1;
                            }

                            fileName = "ResearchCost-" + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xlsx";

                            break;
                        case "3":
                            ExtendBLL.ResearchArticle ra = new ExtendBLL.ResearchArticle();
                            titles = ra.GetTitles();
                            ds = ra.GetAllList();

                            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                            {
                                worksheet.Cells[curRow, 1] = row["ID"];
                                worksheet.Cells[curRow, 2] = row["LunWenTiMuZhongWen"];
                                worksheet.Cells[curRow, 3] = row["JiangLiZuoZe"];
                                worksheet.Cells[curRow, 4] = row["JiangLiZuoZeDanWei"];
                                worksheet.Cells[curRow, 5] = row["QiKanMingCheng"];
                                worksheet.Cells[curRow, 6] = row["QiKanNianJuan"];
                                worksheet.Cells[curRow, 7] = row["QiKanChuBanNianYue"];
                                worksheet.Cells[curRow, 8] = row["JianSuoHao"];
                                worksheet.Cells[curRow, 9] = row["XueYuanShenHe"];
                                worksheet.Cells[curRow, 10] = row["XueXiaoShenHe"];
                                worksheet.Cells[curRow, 11] = row["ShuRuRen"];
                                worksheet.Cells[curRow, 12] = row["ShuRuShiJian"];
                                worksheet.Cells[curRow, 13] = row["ShiFouRenLing"];
                                worksheet.Cells[curRow, 14] = row["LunWenShuMingZuoZe"];
                                worksheet.Cells[curRow, 15] = row["EIHeXinJianSuo"];
                                worksheet.Cells[curRow, 16] = row["CSCDKuoZhanQiKan"];
                                worksheet.Cells[curRow, 17] = row["QiKanShuXing"];
                                worksheet.Cells[curRow, 18] = row["QiKanGuoBie"];
                                worksheet.Cells[curRow, 19] = row["CSCDHeXinYuanQiKan"];
                                worksheet.Cells[curRow, 20] = row["SCIEJianSuo"];
                                worksheet.Cells[curRow, 21] = row["GaoShuiPingQiKan"];
                                worksheet.Cells[curRow, 22] = row["LunWenLeiBie"];
                                worksheet.Cells[curRow, 23] = row["CSSCIYuanQiKan"];
                                worksheet.Cells[curRow, 24] = row["EIKuoZhanYuanJianSuo"];

                                curRow += 1;
                            }

                            fileName = "ResearchArticle-" + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xlsx";

                            break;
                        case "4":
                        default:
                            ExtendBLL.ResearchProject rp = new ExtendBLL.ResearchProject();
                            titles = rp.GetTitles();
                            ds = rp.GetAllList();

                            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                            {
                                worksheet.Cells[curRow, 1] = row["ID"];
                                worksheet.Cells[curRow, 2] = row["XiangMuBianHao"];
                                worksheet.Cells[curRow, 3] = row["XiangMuPiZhunHao"];
                                worksheet.Cells[curRow, 4] = row["XiangMuMingCheng"];
                                worksheet.Cells[curRow, 5] = row["FuZeRen"];
                                worksheet.Cells[curRow, 6] = row["DanWeiMingCheng"];
                                worksheet.Cells[curRow, 7] = row["XiangMuLeiBie"];
                                worksheet.Cells[curRow, 8] = row["JingFeiBenHao"];
                                worksheet.Cells[curRow, 9] = row["HeTongJingFei"];
                                worksheet.Cells[curRow, 10] = row["GuoBoJingFei"];
                                worksheet.Cells[curRow, 11] = row["YiDaoJingFei"];
                                worksheet.Cells[curRow, 12] = row["RuanJianJingFei"];
                                worksheet.Cells[curRow, 13] = row["XiangMuKaiShiShiJian"];
                                worksheet.Cells[curRow, 14] = row["XiangMuJieShuShiJian"];
                                worksheet.Cells[curRow, 15] = row["GuangLiRen"];
                                worksheet.Cells[curRow, 16] = row["WeiTuoDanWei"];
                                worksheet.Cells[curRow, 17] = row["KeiTiZuChengYuan"];
                                worksheet.Cells[curRow, 18] = row["WeiTuoDanWeiGuangLiBuMen"];
                                worksheet.Cells[curRow, 19] = row["HeTongNianDu"];
                                worksheet.Cells[curRow, 20] = row["YiJiLeiBie"];

                                curRow += 1;
                            }

                            fileName = "ResearchProject-" + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".xlsx";

                            break;
                    }

                    for (int i = 0; i < titles.Count; i++)
                    {
                        worksheet.Cells[1, i + 1] = titles[i];
                    }

                    #endregion

                    // ���ø�ʽ
                    MSExcel.Range allRange = worksheet.get_Range("A:Z", Missing.Value);
                    allRange.Columns.AutoFit();

                    // excelApp.Save(fileDir + fileName);
                    System.IO.FileInfo file = new System.IO.FileInfo(fileDir + fileName);

                    if (!System.IO.Directory.Exists(fileDir)) { System.IO.Directory.CreateDirectory(fileDir); }

                    // excelApp.Save(file.FullName);
                    workbook.SaveCopyAs(file.FullName);
                    // worksheet.SaveAs(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                    Response.Clear();
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/ms-excel";

                    Response.WriteFile(file.FullName);

                    // file.Delete();
                }
                finally
                {
                    if (excelApp != null)
                    {
                        excelApp.Quit();
                    }
                }
            }
            catch (Exception ex)
            {
                WriteBackScript(string.Format("alert(\"{0}\")", Server.HtmlEncode(ex.Message)));
            }
        }
예제 #2
0
        /// <summary>
        /// ����
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            string fileName = String.Empty;

            try
            {
                #region Validation

                if (!ExcelFile.HasFile)
                {
                    WriteBackScript("alert('�����ļ�����Ϊ��')");
                    return;
                }
                else
                {
                    string extension = ExtendBLL.FileUtility.GetFileExtension(ExcelFile.FileName);
                    if (!extension.Equals("xls") && !extension.Equals("xlsx"))
                    {
                        WriteBackScript("alert('�����ļ���ʽ����ȷ������ΪExcel�ļ�!')");
                        return;
                    }

                    fileName = AppDomain.CurrentDomain.BaseDirectory + "\\ResearchData\\TmpFiles\\" + Guid.NewGuid().ToString() + "." + extension;
                }

                #endregion

                // Upload File
                ExcelFile.SaveAs(fileName);

                #region Get Excel
                MSExcel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

                try
                {
                    excelApp.Visible = false;
                    excelApp.DisplayAlerts = false;

                    MSExcel.Workbooks workBooks = excelApp.Workbooks;

                    MSExcel.Workbook workbook = (MSExcel.Workbook)workBooks.Open(fileName,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value);

                    if (workbook == null)
                    {
                        WriteBackScript("alert('������������!')");
                        return;
                    }

                    MSExcel.Worksheet worksheet = (MSExcel.Worksheet)workbook.ActiveSheet;

                    if (worksheet == null)
                    {
                        WriteBackScript("alert('Excel���������')");
                        return;
                    }

                    // ��ȡ��һ�е�ֵ
                    object[,] firstRow = (object[,])worksheet.get_Range("1:1", Missing.Value).Value2;

                    System.Collections.Generic.List<string> titles = new System.Collections.Generic.List<string>();

                    foreach (object column in firstRow)
                    {
                        if (column != null)
                        {
                            titles.Add(column.ToString());
                        }
                    }

                    System.Collections.Generic.List<string> expectedTitles = new System.Collections.Generic.List<string>();

                    #region �жϱ���

                    switch (DataType.SelectedValue)
                    {
                        case "1":
                            ExtendBLL.ResearchResult rr = new ExtendBLL.ResearchResult();
                            expectedTitles = rr.GetTitles();
                            break;
                        case "2":
                            ExtendBLL.ResearchCost rc = new ExtendBLL.ResearchCost();
                            expectedTitles = rc.GetTitles();
                            break;
                        case "3":
                            ExtendBLL.ResearchArticle ra = new ExtendBLL.ResearchArticle();
                            expectedTitles = ra.GetTitles();
                            break;
                        case "4":
                        default:
                            ExtendBLL.ResearchProject rp = new ExtendBLL.ResearchProject();
                            expectedTitles = rp.GetTitles();
                            break;
                    }

                    if (expectedTitles.Count != titles.Count)
                    {
                        WriteBackScript("alert('Excel�ļ�ģ�岻ƥ��!')");
                        return;
                    }

                    for (int i = titles.Count - 1; i > -1; i--)
                    {
                        if (!titles[i].Equals(expectedTitles[i]))
                        {
                            WriteBackScript("alert('Excel�ļ�ģ�岻ƥ��!')");
                            return;
                        }
                    }

                    #endregion

                    #region ��������

                    bool allOk = true;
                    string type = Request.Params["type"].ToString();
                    LabMS.Model.ResearchImportType importType = type.Equals("1") ? LabMS.Model.ResearchImportType.Add :
                        (type.Equals("2") ? LabMS.Model.ResearchImportType.RecoverAdd : LabMS.Model.ResearchImportType.DeleteAdd);

                    double timeTmp = 0.0d; // ʱ��

                    switch (DataType.SelectedValue)
                    {
                        case "1":
                            ExtendBLL.ResearchResult rr = new ExtendBLL.ResearchResult();

                            System.Collections.Generic.List<LabMS.Model.ResearchResult> models = new System.Collections.Generic.List<LabMS.Model.ResearchResult>();

                            LabMS.Model.ResearchResult rrInfo;

                            for (int i = 2; i < worksheet.Rows.Count; i++)
                            {
                                object[,] row = (object[,])worksheet.get_Range(string.Format("{0}:{0}", i), Missing.Value).Value2;

                                bool allEmpty = true;

                                for (int j = titles.Count - 1; j > -1; j--)
                                {
                                    foreach (object c in row)
                                    {
                                        allEmpty &= (c == null);
                                    }
                                }

                                if (allEmpty) { break; } // ��ֵ

                                if (row[1, 1] == null) // ID
                                {
                                    continue;
                                }

                                rrInfo = new LabMS.Model.ResearchResult();

                                rrInfo.ID = (row[1, 1] == null) ? String.Empty : row[1, 1].ToString();
                                rrInfo.ChengGuoMingCheng = (row[1, 2] == null) ? String.Empty : row[1, 2].ToString();
                                rrInfo.ChengGuoLeiBie = (row[1, 3] == null) ? String.Empty : row[1, 3].ToString();
                                rrInfo.ChengGuoZuoZe = (row[1, 4] == null) ? String.Empty : row[1, 4].ToString();
                                rrInfo.DanWeiMingCheng = (row[1, 5] == null) ? String.Empty : row[1, 5].ToString();
                                rrInfo.BanZhengShiJian = (row[1, 6] == null) ? String.Empty : row[1, 6].ToString();
                                rrInfo.XueYuanShenHe = (row[1, 7] == null) ? String.Empty : row[1, 7].ToString();
                                rrInfo.XueXiaoShenHe = (row[1, 8] == null) ? String.Empty : row[1, 8].ToString();
                                rrInfo.ChengGuoDengJi = (row[1, 9] == null) ? String.Empty : row[1, 9].ToString();
                                rrInfo.ShuMingZuoZe = (row[1, 10] == null) ? String.Empty : row[1, 10].ToString();
                                rrInfo.ChengGuoBianHao = (row[1, 11] == null) ? String.Empty : row[1, 11].ToString();
                                rrInfo.ShiFouJiangLi = (row[1, 12] == null) ? String.Empty : row[1, 12].ToString();
                                rrInfo.ShuMingDanWei = (row[1, 13] == null) ? String.Empty : row[1, 13].ToString();
                                rrInfo.ChengGuoLieXing = (row[1, 14] == null) ? String.Empty : row[1, 14].ToString();

                                if (double.TryParse(rrInfo.BanZhengShiJian, out timeTmp))
                                {
                                    DateTime dt = new DateTime(1900, 1, 1);
                                    rrInfo.BanZhengShiJian = dt.AddDays(timeTmp - 2).ToShortDateString();
                                }
                                else
                                {
                                    allOk = false;
                                    continue;
                                }

                                models.Add(rrInfo);
                            }

                            rr.Insert(models, importType);
                            break;
                        case "2":
                            // worksheet.get_Range("L:L", Missing.Value).AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatNone,
                            //    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                            ExtendBLL.ResearchCost rc = new ExtendBLL.ResearchCost();

                            System.Collections.Generic.List<LabMS.Model.ResearchCost> rcModels = new System.Collections.Generic.List<LabMS.Model.ResearchCost>();

                            LabMS.Model.ResearchCost rcInfo;

                            for (int i = 2; i < worksheet.Rows.Count; i++)
                            {
                                object[,] row = (object[,])worksheet.get_Range(string.Format("{0}:{0}", i), Missing.Value).Value2;

                                bool allEmpty = true;

                                for (int j = titles.Count - 1; j > -1; j--)
                                {
                                    foreach (object c in row)
                                    {
                                        allEmpty &= (c == null);
                                    }
                                }

                                if (allEmpty) { break; } // ��ֵ

                                if (row[1, 1] == null) // ID
                                {
                                    continue;
                                }

                                rcInfo = new LabMS.Model.ResearchCost();

                                rcInfo.ID = (row[1, 1] == null) ? String.Empty : row[1, 1].ToString();
                                rcInfo.ChongJingZiHao = (row[1, 2] == null) ? String.Empty : row[1, 2].ToString();
                                rcInfo.XiangMuMingCheng = (row[1, 3] == null) ? String.Empty : row[1, 3].ToString();
                                rcInfo.XiangMuLieBie = (row[1, 4] == null) ? String.Empty : row[1, 4].ToString();
                                rcInfo.FuZeRen = (row[1, 5] == null) ? String.Empty : row[1, 5].ToString();
                                rcInfo.DanWeiMingCheng = (row[1, 6] == null) ? String.Empty : row[1, 6].ToString();
                                rcInfo.ShiDaoJingFei = (row[1, 7] == null) ? String.Empty : row[1, 7].ToString();
                                rcInfo.RuanJianJingFei = (row[1, 8] == null) ? String.Empty : row[1, 8].ToString();
                                rcInfo.GuangLiFeiBiLi = (row[1, 9] == null) ? String.Empty : row[1, 9].ToString();
                                rcInfo.GuangLiFei = (row[1, 10] == null) ? String.Empty : row[1, 10].ToString();
                                rcInfo.JingBanRen = (row[1, 11] == null) ? String.Empty : row[1, 11].ToString();
                                rcInfo.ShiDaoShiJian = (row[1, 12] == null) ? String.Empty : row[1, 12].ToString();
                                rcInfo.HuiChuYinHang = (row[1, 13] == null) ? String.Empty : row[1, 13].ToString();

                                if (double.TryParse(rcInfo.ShiDaoShiJian, out timeTmp))
                                {
                                    DateTime dttemp = new DateTime(1900, 1, 1);
                                    dttemp = dttemp.AddDays(timeTmp - 2);
                                    rcInfo.ShiDaoShiJian = dttemp.ToShortDateString();
                                }
                                else // ���ڲ���ȷ
                                {
                                    allOk = false;
                                    continue;
                                }

                                rcModels.Add(rcInfo);
                            }

                            rc.Insert(rcModels, importType);
                            break;
                        case "3":
                            ExtendBLL.ResearchArticle ra = new ExtendBLL.ResearchArticle();

                            System.Collections.Generic.List<LabMS.Model.ResearchArticle> raModels = new System.Collections.Generic.List<LabMS.Model.ResearchArticle>();

                            LabMS.Model.ResearchArticle raInfo;

                            for (int i = 2; i < worksheet.Rows.Count; i++)
                            {
                                object[,] row = (object[,])worksheet.get_Range(string.Format("{0}:{0}", i), Missing.Value).Value2;

                                bool allEmpty = true;

                                for (int j = titles.Count - 1; j > -1; j--)
                                {
                                    foreach (object c in row)
                                    {
                                        allEmpty &= (c == null);
                                    }
                                }

                                if (allEmpty) { break; } // ��ֵ

                                if (row[1, 1] == null) // ID
                                {
                                    continue;
                                }

                                raInfo = new LabMS.Model.ResearchArticle();

                                raInfo.ID = (row[1, 1] == null) ? String.Empty : row[1, 1].ToString();
                                raInfo.LunWenTiMuZhongWen = (row[1, 2] == null) ? String.Empty : row[1, 2].ToString();
                                raInfo.JiangLiZuoZe = (row[1, 3] == null) ? String.Empty : row[1, 3].ToString();
                                raInfo.JiangLiZuoZeDanWei = (row[1, 4] == null) ? String.Empty : row[1, 4].ToString();
                                raInfo.QiKanMingCheng = (row[1, 5] == null) ? String.Empty : row[1, 5].ToString();
                                raInfo.QiKanNianJuan = (row[1, 6] == null) ? String.Empty : row[1, 6].ToString();
                                raInfo.QiKanChuBanNianYue = (row[1, 7] == null) ? String.Empty : row[1, 7].ToString();
                                raInfo.JianSuoHao = (row[1, 8] == null) ? String.Empty : row[1, 8].ToString();
                                raInfo.XueYuanShenHe = (row[1, 9] == null) ? String.Empty : row[1, 9].ToString();
                                raInfo.XueXiaoShenHe = (row[1, 10] == null) ? String.Empty : row[1, 10].ToString();
                                raInfo.ShuRuRen = (row[1, 11] == null) ? String.Empty : row[1, 11].ToString();
                                raInfo.ShuRuShiJian = (row[1, 12] == null) ? String.Empty : row[1, 12].ToString();
                                raInfo.ShiFouRenLing = (row[1, 13] == null) ? String.Empty : row[1, 13].ToString();
                                raInfo.LunWenShuMingZuoZe = (row[1, 14] == null) ? String.Empty : row[1, 14].ToString();
                                raInfo.EIHeXinJianSuo = (row[1, 15] == null) ? String.Empty : row[1, 15].ToString();
                                raInfo.CSCDKuoZhanQiKan = (row[1, 16] == null) ? String.Empty : row[1, 16].ToString();
                                raInfo.QiKanShuXing = (row[1, 17] == null) ? String.Empty : row[1, 17].ToString();
                                raInfo.QiKanGuoBie = (row[1, 18] == null) ? String.Empty : row[1, 18].ToString();
                                raInfo.CSCDHeXinYuanQiKan = (row[1, 19] == null) ? String.Empty : row[1, 19].ToString();
                                raInfo.SCIEJianSuo = (row[1, 20] == null) ? String.Empty : row[1, 20].ToString();
                                raInfo.GaoShuiPingQiKan = (row[1, 21] == null) ? String.Empty : row[1, 21].ToString();
                                raInfo.LunWenLeiBie = (row[1, 22] == null) ? String.Empty : row[1, 22].ToString();
                                raInfo.CSSCIYuanQiKan = (row[1, 23] == null) ? String.Empty : row[1, 23].ToString();
                                raInfo.EIKuoZhanYuanJianSuo = (row[1, 24] == null) ? String.Empty : row[1, 24].ToString();

                                if (double.TryParse(raInfo.ShuRuShiJian, out timeTmp))
                                {
                                    DateTime dt = new DateTime(1900, 1, 1);
                                    raInfo.ShuRuShiJian = dt.AddDays(timeTmp - 2).ToShortDateString();
                                }
                                else
                                {
                                    allOk = false;
                                    continue;
                                }

                                raModels.Add(raInfo);
                            }

                            ra.Insert(raModels, importType);
                            break;
                        case "4":
                        default:
                            ExtendBLL.ResearchProject rp = new ExtendBLL.ResearchProject();

                            System.Collections.Generic.List<LabMS.Model.ResearchProject> rpModels = new System.Collections.Generic.List<LabMS.Model.ResearchProject>();

                            LabMS.Model.ResearchProject rpInfo;

                            for (int i = 2; i < worksheet.Rows.Count; i++)
                            {
                                object[,] row = (object[,])worksheet.get_Range(string.Format("{0}:{0}", i), Missing.Value).Value2;

                                bool allEmpty = true;

                                for (int j = titles.Count - 1; j > -1; j--)
                                {
                                    foreach (object c in row)
                                    {
                                        allEmpty &= (c == null);
                                    }
                                }

                                if (allEmpty) { break; } // ��ֵ

                                if (row[1, 1] == null) // ID
                                {
                                    continue;
                                }

                                rpInfo = new LabMS.Model.ResearchProject();

                                rpInfo.ID = (row[1, 1] == null) ? String.Empty : row[1, 1].ToString();
                                rpInfo.XiangMuBianHao = (row[1, 2] == null) ? String.Empty : row[1, 2].ToString();
                                rpInfo.XiangMuPiZhunHao = (row[1, 3] == null) ? String.Empty : row[1, 3].ToString();
                                rpInfo.XiangMuMingCheng = (row[1, 4] == null) ? String.Empty : row[1, 4].ToString();
                                rpInfo.FuZeRen = (row[1, 5] == null) ? String.Empty : row[1, 5].ToString();
                                rpInfo.DanWeiMingCheng = (row[1, 6] == null) ? String.Empty : row[1, 6].ToString();
                                rpInfo.XiangMuLeiBie = (row[1, 7] == null) ? String.Empty : row[1, 7].ToString();
                                rpInfo.JingFeiBenHao = (row[1, 8] == null) ? String.Empty : row[1, 8].ToString();
                                rpInfo.HeTongJingFei = (row[1, 9] == null) ? String.Empty : row[1, 9].ToString();
                                rpInfo.GuoBoJingFei = (row[1, 10] == null) ? String.Empty : row[1, 10].ToString();
                                rpInfo.YiDaoJingFei = (row[1, 11] == null) ? String.Empty : row[1, 11].ToString();
                                rpInfo.RuanJianJingFei = (row[1, 12] == null) ? String.Empty : row[1, 12].ToString();
                                rpInfo.XiangMuKaiShiShiJian = (row[1, 13] == null) ? String.Empty : row[1, 13].ToString();
                                rpInfo.XiangMuJieShuShiJian = (row[1, 14] == null) ? String.Empty : row[1, 14].ToString();
                                rpInfo.GuangLiRen = (row[1, 15] == null) ? String.Empty : row[1, 15].ToString();
                                rpInfo.WeiTuoDanWei = (row[1, 16] == null) ? String.Empty : row[1, 16].ToString();
                                rpInfo.KeiTiZuChengYuan = (row[1, 17] == null) ? String.Empty : row[1, 17].ToString();
                                rpInfo.WeiTuoDanWeiGuangLiBuMen = (row[1, 18] == null) ? String.Empty : row[1, 18].ToString();
                                rpInfo.HeTongNianDu = (row[1, 19] == null) ? String.Empty : row[1, 19].ToString();
                                rpInfo.YiJiLeiBie = (row[1, 20] == null) ? String.Empty : row[1, 20].ToString();

                                #region ʱ��

                                if (double.TryParse(rpInfo.XiangMuJieShuShiJian, out timeTmp))
                                {
                                    DateTime dt = new DateTime(1900, 1, 1);
                                    rpInfo.XiangMuJieShuShiJian = dt.AddDays(timeTmp - 2).ToShortDateString();
                                }
                                else
                                {
                                    allOk =false;
                                    continue;
                                }

                                if (double.TryParse(rpInfo.XiangMuKaiShiShiJian, out timeTmp))
                                {
                                    DateTime dt = new DateTime(1900, 1, 1);
                                    rpInfo.XiangMuKaiShiShiJian = dt.AddDays(timeTmp - 2).ToShortDateString();
                                }
                                else
                                {
                                    allOk = false;
                                    continue;
                                }

                                if (double.TryParse(rpInfo.HeTongNianDu, out timeTmp))
                                {
                                    DateTime dt = new DateTime(1900, 1, 1);
                                    rpInfo.HeTongNianDu = dt.AddDays(timeTmp - 2).ToShortDateString();
                                }
                                else
                                {
                                    allOk = false;
                                    continue;
                                }

                                #endregion

                                rpModels.Add(rpInfo);
                            }

                            rp.Insert(rpModels, importType);
                            break;
                    }

                    if (!allOk)
                    {
                        WriteBackScript("alert('�����е�ʱ���ʽ����ȷ,���޸��ļ���ѡ��[׷�ӵ���(���������ظ�����)]��ʽ���µ�������!');");
                        return;
                    }

                    #endregion

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (excelApp != null)
                    {
                        excelApp.Quit();
                    }
                }

                #endregion

                WriteBackScript("alert('�������ݳɹ�!')");

            }
            catch (Exception ex)
            {
                WriteBackScript(string.Format("alert('{0}')", Server.HtmlEncode(ex.Message)));
            }
        }