首页 技术 正文
技术 2022年11月19日
0 收藏 307 点赞 2,260 浏览 6328 个字

针对两表操作

一丶增加

 #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);
}
})

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,474
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,889
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,724
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,479
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,118
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,278