针对两表操作

一丶增加

 #region 05-增加操作
/// <summary>
/// 05-增加操作
/// </summary>
/// <param name="studentInfo">用来接收用户信息(涵盖多条件)</param>
/// <param name="student_Photo">用来接收用户信息(涵盖多条件)</param>
/// <returns></returns>
public ActionResult AddExcute(StudentInfo studentInfo, Student_Photo student_Photo)
{
try
{
//为数据库条目赋值
StudentInfo stuInfo = new StudentInfo()
{
id = Guid.NewGuid().ToString("N"),
name = studentInfo.name,
sex = studentInfo.sex,
age = studentInfo.age,
stuAddTime = DateTime.Now,
};
Student_Photo stu_Photo = new Student_Photo()
{
id = stuInfo.id,
photoUrl = student_Photo.photoUrl,
roomNumber = student_Photo.roomNumber,
addTime = DateTime.Now,
};
//进行插入
oc.BllSession.IStudentInfoBLL.AddNo(stuInfo);
oc.BllSession.IStudent_PhotoBLL.AddNo(stu_Photo);
//提交事务
int result = oc.BllSession.IStudentInfoBLL.SaveChange();
if (result > )
{
return Content("ok");
}
else
{
return Content("error");
}
}
catch (Exception ex)
{
Common.Log.LogHelper.Info(ex.Message);
return Content(""); //只为了凑返回值,没有实际用处
} }
#endregion

二丶删除

 #region 06-删除操作
/// <summary>
/// 06-删除操作
/// </summary>
/// <param name="idsStr">id字符串</param>
/// <returns></returns>
public ActionResult DelExcute(string idsStr)
{
try
{
//进行字符串拆分
string[] str = idsStr.Split(new char[] { ',' });
foreach (var item in str)
{ //根据id查找对应行
var stu_Info = oc.BllSession.IStudentInfoBLL.Entities.Where(a => a.id == item).FirstOrDefault();
var stu_Img = oc.BllSession.IStudent_PhotoBLL.Entities.Where(a => a.id == item).FirstOrDefault();
//进行删除
oc.BllSession.IStudentInfoBLL.DelNo(stu_Info);
oc.BllSession.IStudent_PhotoBLL.DelNo(stu_Img);
}
//提交事务
int result = oc.BllSession.IStudentInfoBLL.SaveChange();
if (result > )
{
return Content("ok");
}
else
{
return Content("error");
}
}
catch (Exception ex)
{
Common.Log.LogHelper.Info(ex.Message);
return Content(""); //只为了凑返回值,没有实际用处
}
}
#endregion

三丶修改

 #region 07-修改操作
/// <summary>
/// 07-修改操作
/// </summary>
/// <param name="studentInfo">学生表查询信息</param>
/// <param name="student_Photo">学生图片信息</param>
/// <returns></returns>
public ActionResult UpdateExcute(StudentInfo studentInfo, Student_Photo student_Photo)
{
try
{
//根据id号查询
var stu_Info = oc.BllSession.IStudentInfoBLL.Entities.Where(a => a.id == studentInfo.id).FirstOrDefault();
var stu_Img = oc.BllSession.IStudent_PhotoBLL.Entities.Where(a => a.id == studentInfo.id).FirstOrDefault();
//为学生信息赋值
stu_Info.name = studentInfo.name;
stu_Info.sex = studentInfo.sex;
stu_Info.age = studentInfo.age;
stu_Info.stuAddTime = DateTime.Now; stu_Img.photoUrl = student_Photo.photoUrl;
stu_Img.roomNumber = student_Photo.roomNumber;
stu_Img.addTime = DateTime.Now;
//进行修改
oc.BllSession.IStudentInfoBLL.ModifyNo(stu_Info);
oc.BllSession.IStudent_PhotoBLL.ModifyNo(stu_Img);
//提交事务
int result = oc.BllSession.IStudentInfoBLL.SaveChange();
if (result > )
{
return Content("ok");
}
else
{
return Content("error");
}
}
catch (Exception ex)
{
Common.Log.LogHelper.Info(ex.Message);
return Content(""); //只为了凑返回值,没有实际用处
}
}
#endregion

四丶查询

 #region 04-多条件查询操作
/// <summary>
/// 04-多条件查询操作
/// </summary>
/// <param name="studentInfo">用来接收用户信息(涵盖多条件)</param>
/// <param name="student_Photo">用来接收用户信息(涵盖多条件)</param>
/// <param name="rows">行数</param>
/// <param name="page">页码</param>
/// <param name="dateStart">起始时间</param>
/// <param name="dateEnd">结束时间</param>
/// <returns></returns>
public ActionResult StuList(StudentInfo studentInfo, Student_Photo student_Photo, int rows, int page, string dateStart, string dateEnd)
{
try
{
//数据源
var stu_Info = oc.BllSession.IStudentInfoBLL.Entities;
var stu_Img = oc.BllSession.IStudent_PhotoBLL.Entities; //下面开始进行过滤查询
//1.根据学生姓名查询
if (!String.IsNullOrEmpty(studentInfo.name))
{
stu_Info = stu_Info.Where(a => a.name.Contains(studentInfo.name));
}
//2.根据学生性别查询
if (!String.IsNullOrEmpty(studentInfo.sex))
{
stu_Info = stu_Info.Where(a => a.sex == studentInfo.sex);
}
//3.对时间进行排序
if (!String.IsNullOrEmpty(dateStart))
{
DateTime dateS = Convert.ToDateTime(dateStart);//开始时间
if (dateS != DateTime.MinValue)
{
stu_Info = stu_Info.Where(a => a.stuAddTime > dateS);
}
}
if (!String.IsNullOrEmpty(dateEnd))
{
DateTime dateE = Convert.ToDateTime(dateEnd);//开始时间
if (dateE != DateTime.MinValue)
{
stu_Info = stu_Info.Where(a => a.stuAddTime < dateE);
}
}
//4.根据学生宿舍号进行查询
if (!String.IsNullOrEmpty(student_Photo.roomNumber))
{
stu_Img = stu_Img.Where(a => a.roomNumber.Contains(student_Photo.roomNumber));
}
//连接查询
var StuList = (from a in stu_Info.ToList()
join b in stu_Img.ToList()
on a.id equals b.id
select new StuInfoAndImg
{
id = a.id,
name = a.name,
sex = a.sex,
age = a.age,
stuAddTime = a.stuAddTime,
delFlag = a.delFlag,
pId = b.pId,
photoUrl = b.photoUrl,
roomNumber = b.roomNumber,
addTime = b.addTime,
delFlag1 = b.delFlag,
}).OrderByDescending(u => u.stuAddTime); var json = new
{
total = StuList.Count(),
rows = StuList.Skip(rows * (page - )).Take(rows).ToList(),
};
return Json(json);
}
catch (Exception ex)
{
Common.Log.LogHelper.Info(ex.Message);
return Content(""); //只为了凑返回值,没有实际用处
}
}
#endregion

五丶附加

 #region 08-上传图片
/// <summary>
/// 08-上传图片
/// </summary>
/// <returns></returns>
public ActionResult Upload()
{
try
{
if (Request.Files.Count == )
{
return PackagingAjaxmsg(new AjaxMsgModel { BackUrl = null, Data = null, Msg = "未找到要上传的图片", Statu = AjaxStatu.err });
}
else
{
//得到上传的图片
var file = Request.Files[];
//要保存的文件路径
var path = Path.Combine(Server.MapPath(Request.ApplicationPath), "Upload", "Image");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//要保存的文件名称
string fileName = string.Format("{0}_{1}{2}", oc.CurrentUser.uId, DateTime.Now.ToString("yyyyMMddHHmmss"), Path.GetExtension(file.FileName));
//保存文件到指定的目录
file.SaveAs(Path.Combine(path, fileName));
//上传之后图片的相对路径
string relativePath = Path.Combine(Request.ApplicationPath, "Upload", "Image", fileName); return PackagingAjaxmsg(new AjaxMsgModel { BackUrl = relativePath, Data = null, Msg = "上传成功", Statu = AjaxStatu.ok });
}
}
catch (Exception ex)
{
Common.Log.LogHelper.Info(ex.Message);
return PackagingAjaxmsg(new AjaxMsgModel { BackUrl = null, Data = null, Msg = "图片上传失败", Statu = AjaxStatu.err });
}
}
#endregion
$("#j_btn1").uploadify({
buttonText: '上传图片',
height: 20,
width: 120,
swf: '/Content/uploadify/uploadify.swf',
uploader: '/Test_Areas/Test/Upload',//通过后台的程序把文件上传到服务器
multi: false,//是否允许同时选择多个文件
fileSizeLimit: '8MB',//文件大小
fileTypeExts: '*.gif;*.png;*.jpg;*jpeg',//可选文件的扩展名
formData: {
'folder': '/Upload', 'ASPSESSID': ASPSESSID, 'AUTHID': auth//测试
}, onUploadSuccess: function (file, data, response) {
var jsonData = $.parseJSON(data);
$.procAjaxMsg(jsonData, function () {
$.alertMsg(jsonData.Msg, '操作提示', function () { $("#j_editForm img").attr("src", jsonData.BackUrl);
$("#j_ImgUrl").val(jsonData.BackUrl);
});
}, function () {
$.alertMsg(jsonData.Msg, '操作提示', null);
});
},
onUploadError: function (file, errorCode, errorMsg, errorString) {
$.alertMsg('文件 ' + file.name + ' 上传失败: ' + errorString, '上传失败', null);
},
onSelectError: function (file, errorCode, errorMsg, errorString) {
$.alertMsg('文件 ' + file.name + ' 不能被上传: ' + errorString, '选择失效', null);
}
})

  

第三节:执行一些EF的增删改查的更多相关文章

  1. easyui datagrid 禁止选中行 EF的增删改查(转载) C# 获取用户IP地址(转载) MVC EF 执行SQL语句(转载) 在EF中执行SQL语句(转载) EF中使用SQL语句或存储过程 .net MVC使用Session验证用户登录 PowerDesigner 参照完整性约束(转载)

    easyui datagrid 禁止选中行   没有找到可以直接禁止的属性,但是找到两个间接禁止的方式. 方式一: //onClickRow: function (rowIndex, rowData) ...

  2. EF实现增删改查

    从来没想到过能在这个上面翻车,感慨自学没有培训来得系统啊,废话不多说 ORM:对象关系映射(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一 ...

  3. ASP.NET从零开始学习EF的增删改查

           ASP.NET从零开始学习EF的增删改查           最近辞职了,但是离真正的离职还有一段时间,趁着这段空档期,总想着写些东西,想来想去,也不是很明确到底想写个啥,但是闲着也是够 ...

  4. [.NET源码] EF的增删改查

    EF的增删改查 创建上下文对象:WordBoradEntities db = new WordBoradEntities(); 一.添加: //1.1创建实体对象 User uObj = new Us ...

  5. http://www.cnblogs.com/nangong/p/db29669e2c6d72fb3d0da947280aa1ce.htm ASP.NET从零开始学习EF的增删改查

    http://www.cnblogs.com/nangong/p/db29669e2c6d72fb3d0da947280aa1ce.htmlASP.NET从零开始学习EF的增删改查

  6. EF CodeFirst增删改查之‘CRUD’

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精    本篇旨在学习EF增删改查四大操作 上一节讲述了EF ...

  7. [EF]使用EF简单增删改查

    目录 认识EF 添加数据 删除数据 修改数据 查询数据 总结 认识EF ADO.NET Entity Framework 是微软以ADO.NET为基础所发展出来的对象关系对伊(O/R Mapping) ...

  8. ASP.NET MVC学习---(三)EF简单增删改查

    那么现在我们已经大概从本质上了解了ef 巴拉巴拉说了一大堆之后 总算要进入ef的正题了 总在口头说也太不行了是吧~ 没错,现在要用ef进行一些实际的操作 做什么呢? 就做一个入门级的增删改查操作吧 废 ...

  9. MVC学习-用EF做增删改查

    在做增删改查先,先介绍几个知识点: 1.代理类 在将对象方法EF数据上下文时,EF会为该对象封装 一个代理类对象, 同时为该对象的每一个属性添加一个标志:unchanged, 当对该对象某个属性进行操 ...

随机推荐

  1. C中多线程开发

    1 引言  线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期.solaris是这方面的佼佼者.传统的 Unix也支持线程的概念,可是在一个进程(proce ...

  2. field load respone data

    问题: AJAX 使用谷歌浏览器 POST 请求报如下错误 field load respone data 使用 火狐 浏览器就正常 调试1: 发现其实我请求的回调函数能打印出来数据,但是,在netw ...

  3. jQuery通过地址获取经纬度demo

    在开始之前,首先需要登录百度地图API控制台申请密钥ak. 1.登录百度地图开放平台http://lbsyun.baidu.com 注册账号,完善信息,点击网站右上角的“API控制台”,点击,创建应用 ...

  4. CSS总结01

    1 CSS 的作用是? 2 如何引入 CSS 样式? 3 CSS 选择器的基本类型和复合选择器分别是? 4 字体.背景.列表和链接和鼠标的属性有哪些? 5 如何理解盒子模型? 6 浮动的方式有哪些,如 ...

  5. Error:(2, 0) No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices. <

    compile报下面的错误Error:(2, 0) No service of type Factory available in ProjectScopeServices. 点击open file ...

  6. 自定义的Notification

    要创建一个自定义的Notification,可以使用RemoteViews.要定义自己的扩展消息,首先要初始化一个RemoteViews对象,然后将它传递给Notification contentVi ...

  7. 【HDU 2157】 How Many Ways??

    [题目链接] 点击打开链接 [算法] 设A[i][j]为走一条边,从i走到j的方案数 C[i][j]为走两条边,从i走到j的方案数,显然有 : C = A * A = A^2 C'[i][j]为走三条 ...

  8. 杂项:MySQL

    ylbtech-杂项:MySQL 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https://www.mysql.com/ 1. https://bai ...

  9. TI BLE: Advertisement

    #define GAPROLE_ADVERT_ENABLED 0x305 //!< Enable/Disable Advertising. Read/Write. Size is uint8. ...

  10. (DP)51NOD 1085 背包问题

    在N件物品取出若干件放在容量为W的背包里,每件物品的体积为W1,W2……Wn(Wi为整数),与之相对应的价值为P1,P2……Pn(Pi为整数).求背包能够容纳的最大价值. Input 第1行,2个整数 ...