针对两表操作

一丶增加

 #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. org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected be

    1.错误描写叙述 八月 14, 2015 3:03:05 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn 警告: Request ...

  2. ios之UILabel实现文本自适应方法

    UILabel实现文本自适应方法(ios7) - (void)initUserInterface { UILabel *label = [[UILabel alloc]init]; label.num ...

  3. (一)Java 入门教程

    Java 入门教程 Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言. Java可运行于多个平台,如Windows, Mac OS,及其他多种UNIX版本的系统 ...

  4. springMVC之异常处理

    1. 自己定义一个异常类: UserException.java public class UserException extends RuntimeException { private stati ...

  5. nestedScrollview 嵌套使用recyclerview判断滑动到底部 (嵌套滑动导致 不能使用recyclerview的onscrolled监听)

    NestedScrollView scroller = (NestedScrollView) findViewById(R.id.myScroll); if (scroller != null) { ...

  6. bzoj 3308 九月的咖啡店

    题目大意: 求若干个<=n的数 两两互质 使和最大 求这个最大的和 思路: 显然,得到两个结论 1 最终的所有数都只能分解为两个质因数 2 这两个质因数 一个<根号n 一个>根号n ...

  7. bzoj2521

    最小生成树+最小割 ...我太zz了,没看出来全体减1是一个加1,看见后就是sb题了... 我们发现根据克鲁斯卡尔的过程,我们把边从小到大加入,如果两点已经相连就跳过,那么我们把所有小于等于这条边的边 ...

  8. Java多线程系列五——列表类

    参考资料: http://xxgblog.com/2016/04/02/traverse-list-thread-safe/ 一些列表类及其特性  类 线程安全 Iterator 特性 说明 Vect ...

  9. E20180124-hm

    introspection n.自我反省; 反省,内省; capacity n. 容量; 性能; 才能; 生产能力; synthesize vt. 综合; 人工合成; (通过化学手段或生物过程) 合成 ...

  10. conda命令不能用的问题

    在Windows下安装了Anaconda3-5.0.1-Windows-x86.exe 但是在cmd端下,打命令conda没反应 打pip显示如下错误 这是由于cmd编码为gbk的问题导致的 解决方案 ...