示例#1
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, AssessmentChaptersEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#2
0
        public string ImportCase()
        {
            int    error        = 0;
            string message      = "请选择格式正确的文件再导入!";
            string falseMessage = "";
            int    count        = HttpContext.Request.Files.Count;

            if (count > 0)
            {
                HttpPostedFileBase file = HttpContext.Request.Files[0];
                if (string.IsNullOrEmpty(file.FileName))
                {
                    return(message);
                }
                if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx")))
                {
                    return(message);
                }
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName);
                file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName));
                DataTable dt   = ExcelHelper.ExcelImport(Server.MapPath("~/Resource/temp/" + fileName));
                Hashtable hast = new Hashtable();
                List <AssessmentChaptersEntity> listEntity = new List <AssessmentChaptersEntity>();
                AssessmentChaptersEntity        chapter    = new AssessmentChaptersEntity();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(dt.Rows[i][0].ToString()))
                    {
                        chapter              = new AssessmentChaptersEntity();
                        chapter.MajorNumber  = dt.Rows[i][0].ToString();
                        chapter.Id           = Guid.NewGuid().ToString();
                        chapter.ChaptersName = dt.Rows[i][1].ToString();
                        if (hast.Keys.Count > 0)
                        {
                            string   m   = dt.Rows[i][0].ToString();
                            string[] b   = new string[20];
                            string   key = "";
                            if (m.Contains("."))
                            {
                                b = m.Split('.');
                                if (b.Length > 2)
                                {
                                    key = b[0] + "." + b[1];
                                }
                            }
                            object obj = hast[key];
                            if (obj == null)
                            {
                                chapter.ChaptersParentID = "-1";
                            }
                            else
                            {
                                chapter.ChaptersParentID = obj.ToString();
                                if (!string.IsNullOrEmpty(dt.Rows[i][4].ToString()))
                                {
                                    //评分标准
                                    AssessmentStandardEntity aentity = new AssessmentStandardEntity();
                                    aentity.AChapters = chapter.Id;
                                    aentity.Content   = dt.Rows[i][4].ToString();
                                    assessmentstandardbll.SaveForm("", aentity);
                                }
                                if (!string.IsNullOrEmpty(dt.Rows[i][5].ToString()))
                                {
                                    chapter.ReviewWay = dt.Rows[i][5].ToString();
                                }
                            }
                        }
                        else
                        {
                            chapter.ChaptersParentID = "-1";
                        }
                        chapter.Content = dt.Rows[i][2].ToString();
                        chapter.Score   = Convert.ToInt32(dt.Rows[i][3].ToString());
                        hast.Add(chapter.MajorNumber, chapter.Id);
                        listEntity.Add(chapter);
                    }
                    else
                    {
                        chapter.ChaptersName += dt.Rows[i][1].ToString();
                        chapter.Content      += dt.Rows[i][2].ToString();
                        if (!string.IsNullOrEmpty(dt.Rows[i][4].ToString()))
                        {
                            //评分标准
                            AssessmentStandardEntity aentity = new AssessmentStandardEntity();
                            aentity.AChapters = chapter.Id;
                            aentity.Content   = dt.Rows[i][4].ToString();
                            assessmentstandardbll.SaveForm("", aentity);
                        }
                    }
                }
                for (int j = 0; j < listEntity.Count; j++)
                {
                    try
                    {
                        assessmentchaptersbll.SaveForm("", listEntity[j]);
                    }
                    catch (Exception ex)
                    {
                        error++;
                    }
                }
                count    = listEntity.Count;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }
            return(message);
        }
示例#3
0
 public ActionResult SaveForm(string keyValue, AssessmentChaptersEntity entity)
 {
     assessmentchaptersbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }