本文整理汇总了C#中DAL.TranRollBack方法的典型用法代码示例。如果您正苦于以下问题:C# DAL.TranRollBack方法的具体用法?C# DAL.TranRollBack怎么用?C# DAL.TranRollBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DAL
的用法示例。
在下文中一共展示了DAL.TranRollBack方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IcInfoSave
/// <summary>
/// 绑定保存 IC卡人员
/// </summary>
/// <param name="context"></param>
public void IcInfoSave(HttpContext context)
{
string retext = "{\"ok\":@[email protected],\"msg\":\"@[email protected]\"}"; ;
string jsont = context.Request["jsont"];
var ics = Json.Json_转换到对象<List<user_Ic>>(jsont);
var dal = new DAL();
try
{
string SQL = "UPDATE [CNGTZ].[dbo].[IC_绑定]SET[人员] [email protected]人员,[更新时间] = getdate() WHERE 卡号[email protected]卡号";
dal.TranBegin();
foreach (var ic in ics)
{
var par1 = new SqlParameter("@人员", ic.name);
var par2 = new SqlParameter("@卡号", ic.icno);
dal.ExeSql(SQL, new SqlParameter[] { par1, par2 });
}
dal.TranCommit();
retext = retext.Replace("@[email protected]", "true");
retext = retext.Replace("@[email protected]", "IC卡绑定操作成功!");
}
catch (Exception e)
{
dal.TranRollBack();
retext = retext.Replace("@[email protected]", "false");
retext = retext.Replace("@[email protected]", "IC卡绑定操作失败!<br/>" + e.Message);
}
context.Response.Write(retext);
}
示例2: ProcessRequest
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
var file = context.Request.Files["Filedata"];//文件 对象
string userID = context.Request["userID"];//上传用户
string user = context.Request["user"];//上传用户
string imgname = context.Request["imgname"];//图片名
string imgID = context.Request["imgID"];//相片ID 如果为0 表示 没有上传记录
string savePaht = context.Request.PhysicalApplicationPath + "CNGTZ\\userimg\\" + imgname + ".jpg"; //略缩图储存路径
string sourcePaht = context.Request.PhysicalApplicationPath + "CNGTZ\\userimg\\source\\" + imgname + ".jpg"; //原图储存路径
//string xnpath =context.Request.Path;
DAL dal = new DAL();
if (file != null)
{
file.SaveAs(sourcePaht);
ImageClass.MakeThumbnail(sourcePaht, savePaht, 100, 130, "HW");//生成略缩图
FileItem fi = FileManager.GetItemInfo(savePaht);
if (fi.Name.Length > 0)//判断略缩图是否创建完成
{
string SQL1 = "", SQL2 = "", SQL3 = "";
if (imgID != "0")
{
SQL1 = "UPDATE [CNGTZ].[dbo].[TZ_图片]SET [类型] [email protected]类型,[图片] [email protected]图片,[备注] [email protected]备注,[上传用户] [email protected]上传用户,[所属用户] [email protected]所属用户,[更新时间] = getdate() WHERE ID=" + imgID;
}
else
{
SQL1 = @"INSERT INTO [CNGTZ].[dbo].[TZ_图片]([类型],[图片],[备注],[上传用户],[所属用户],[更新时间])VALUES(@类型,@图片,@备注,@上传用户,@所属用户,getdate())";
SQL2 = @"SELECT [ID] FROM [CNGTZ].[dbo].[TZ_图片]where 类型='人员' AND [所属用户]='" + imgname + "'";//查询是否已经上传过相片
SQL3 = @"UPDATE [CNGTZ].[dbo].[TZ_人员_基本信息] SET [相片ID] ={0}, 更新时间 = getdate() WHERE ID=" + userID;
}
try
{
dal.TranBegin();//开始事务
SqlParameter par1 = new SqlParameter("@类型", "人员");
SqlParameter par2 = new SqlParameter("@图片", savePaht);
SqlParameter par3 = new SqlParameter("@备注", "");
SqlParameter par4 = new SqlParameter("@上传用户", user);
SqlParameter par5 = new SqlParameter("@所属用户", imgname);
dal.ExeSql(SQL1, new SqlParameter[] { par1, par2, par3, par4, par5 });//执行语句
if (imgID == "0")
{
string ID = dal.RunSqlGetID(SQL2);
SQL3 = string.Format(SQL3, ID);
dal.ExeSql(SQL3);
}
dal.TranCommit();//提交事务
Sys.addSteps(user, "上传员工相片:[" + fi.Name + "]", "人员台账");
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write("1");
}
catch (Exception)
{
dal.TranRollBack();//回滚事务
context.Response.Write("0");//数据库操作失败
}
}
else
{
context.Response.Write("0"); //如果创建文件失败
}
}
else
{
context.Response.Write("0");//上传文件失败
}
}
示例3: user_cut
/// <summary>
/// 删除人员
/// </summary>
/// <param name="context"></param>
public void user_cut(HttpContext context)
{
string ID = context.Request["ID"];
string SQL1 = "DELETE FROM [CNGTZ].dbo.TZ_人员_基本信息 WHERE ID=" + ID;
string SQL2 = "DELETE FROM [CNGTZ].dbo.TZ_人员_档案1 WHERE ID=" + ID;
string SQL3 = "DELETE FROM [CNGTZ].dbo.TZ_人员_档案2 WHERE ID=" + ID;
string SQL4 = "DELETE FROM [CNGTZ].[dbo].[TZ_人员_资质证书] WHERE 人员ID=" + ID;
string SQL5 = "DELETE FROM [CNGTZ].[dbo].[IC_绑定] WHERE 人员=(SELECT 姓名 FROM [CNGTZ].[dbo].TZ_人员 where ID=" +
ID + ")";
string SQL6 = "DELETE FROM [CNGTZ].[dbo].[TZ_人员] WHERE ID=" + ID;
DAL dal = new DAL();
string retext = "{\"ok\":@[email protected],\"msg\":\"@[email protected]\"}";
try
{
dal.TranBegin();
dal.ExeSql(SQL1);
dal.ExeSql(SQL2);
dal.ExeSql(SQL3);
dal.ExeSql(SQL4);
dal.ExeSql(SQL5);
dal.ExeSql(SQL6);
dal.TranCommit();
retext = retext.Replace("@[email protected]", "true");
retext = retext.Replace("@[email protected]", "删除操作执行成功!");
}
catch (Exception e)
{
dal.TranRollBack();
retext = retext.Replace("@[email protected]", "false");
retext = retext.Replace("@[email protected]", "发现异常错误,所有提交操作已经终止!<br/>" + e.Message);
}
Sys.DebugMes(retext);
context.Response.Write(retext);
}
示例4: user_lizhi
/// <summary>
/// 员工离职操作
/// </summary>
/// <param name="context"></param>
public void user_lizhi(HttpContext context)
{
string ID = context.Request["ID"];
string msg = context.Request["msg"];
string SQL1 = "UPDATE [CNGTZ].[dbo].[TZ_人员] SET [所属部门] ='02',[更新时间] = getdate() WHERE [email protected]";
string SQL2 = "UPDATE [CNGTZ].[dbo].[TZ_人员_档案2] SET [离职日期] = getdate(),[离职原因] [email protected]离职原因,[更新时间] = getdate() WHERE [email protected]";
DAL dal = new DAL();
SqlParameter par1 = new SqlParameter("@ID", ID);
SqlParameter par2 = new SqlParameter("@离职原因", msg);
string retext = "{\"ok\":@[email protected],\"msg\":\"@[email protected]\"}";
try
{
dal.TranBegin();//开始事务
dal.ExeSql(SQL1, new SqlParameter[] { par1 });//执行语句
dal.ExeSql(SQL2, new SqlParameter[] { par1, par2 });//执行语句
dal.TranCommit();//提交事务
retext = retext.Replace("@[email protected]", "true");
retext = retext.Replace("@[email protected]", "离职操作执行成功!");
}
catch (Exception e)
{
dal.TranRollBack();//回滚事务
retext = retext.Replace("@[email protected]", "false");
retext = retext.Replace("@[email protected]", "发现执行错误,所有提交操作已经终止!");
}
Sys.DebugMes(retext);
context.Response.Write(retext);
}
示例5: update_jbxx
//.........这里部分代码省略.........
,[民族] = @民族
,[籍贯] = @籍贯
,[户口] = @户口
,[婚姻] = @婚姻
,[学历] = @学历
,[政治面貌] = @政治面貌
,[身份证号] = @身份证号
,[更新时间] = getdate()
WHERE [email protected]";
SqlParameter par1 = new SqlParameter("@性别", _基本信息.性别);
SqlParameter par2 = _基本信息.出生年月 == "" ? new SqlParameter("@出生年月", DBNull.Value) : new SqlParameter("@出生年月", DateTime.Parse(_基本信息.出生年月));
SqlParameter par3 = new SqlParameter("@民族", _基本信息.民族);
SqlParameter par4 = new SqlParameter("@籍贯", _基本信息.籍贯);
SqlParameter par5 = new SqlParameter("@户口", _基本信息.户口);
SqlParameter par6 = new SqlParameter("@婚姻", _基本信息.婚姻);
SqlParameter par7 = new SqlParameter("@学历", _基本信息.学历);
SqlParameter par8 = new SqlParameter("@政治面貌", _基本信息.政治面貌);
SqlParameter par9 = new SqlParameter("@身份证号", _基本信息.身份证号);
SqlParameter par10 = new SqlParameter("@ID", id);
#endregion
#region 档案1
SQL2 = @"UPDATE [CNGTZ].[dbo].[TZ_人员_档案1]
SET [行政级别] = @行政级别
,[职务] = @职务
,[职称] = @职称
,[岗位工种] = @岗位工种
,[用工形式] = @用工形式
,[工资等级] = @工资等级
,[手机] = @手机
,[联系电话] = @联系电话
,[电子邮件] = @电子邮件
,[家庭住址] = @家庭住址
,[邮编] = @邮编
,[发卡银行] = @发卡银行
,[银行卡号] = @银行卡号
,[更新时间] = getdate()
WHERE [email protected]";
SqlParameter parA1 = new SqlParameter("@行政级别", _档案1.行政级别);
SqlParameter parA2 = new SqlParameter("@职务", _档案1.职务);
SqlParameter parA3 = new SqlParameter("@职称", _档案1.职称);
SqlParameter parA4 = new SqlParameter("@岗位工种", _档案1.岗位工种);
SqlParameter parA5 = new SqlParameter("@用工形式", _档案1.用工形式);
SqlParameter parA6 = new SqlParameter("@工资等级", _档案1.工资等级);
SqlParameter parA7 = new SqlParameter("@手机", _档案1.手机);
SqlParameter parA8 = new SqlParameter("@联系电话", _档案1.联系电话);
SqlParameter parA9 = new SqlParameter("@电子邮件", _档案1.电子邮件);
SqlParameter parA10 = new SqlParameter("@家庭住址", _档案1.家庭住址);
SqlParameter parA11 = new SqlParameter("@邮编", _档案1.邮编);
SqlParameter parA12 = new SqlParameter("@发卡银行", _档案1.发卡银行);
SqlParameter parA13 = new SqlParameter("@银行卡号", _档案1.银行卡号);
SqlParameter parA14 = new SqlParameter("@ID", id);
#endregion
#region 档案2
SQL3 = @"UPDATE [CNGTZ].[dbo].[TZ_人员_档案2]
SET [毕业院校] = @毕业院校
,[毕业时间] = @毕业时间
,[专业] = @专业
,[入工会日期] = @入工会日期
,[入党日期] = @入党日期
,[入团日期] = @入团日期
,[入职日期] = @入职日期
,[离职日期] = @离职日期
,[离职原因] = @离职原因
,[参加工作日期] = @参加工作日期
,[入职前工龄] = @入职前工龄
,[更新时间] = getdate()
WHERE [email protected]";
SqlParameter parB1 = new SqlParameter("@毕业院校", _档案2.毕业院校);
SqlParameter parB2 = _档案2.毕业时间 == "" ? new SqlParameter("@毕业时间", DBNull.Value) : new SqlParameter("@毕业时间", DateTime.Parse(_档案2.毕业时间));
SqlParameter parB3 = new SqlParameter("@专业", _档案2.专业);
SqlParameter parB4 = _档案2.入工会日期 == "" ? new SqlParameter("@入工会日期", DBNull.Value) : new SqlParameter("@入工会日期", DateTime.Parse(_档案2.入工会日期));
SqlParameter parB5 = _档案2.入党日期 == "" ? new SqlParameter("@入党日期", DBNull.Value) : new SqlParameter("@入党日期", DateTime.Parse(_档案2.入党日期));
SqlParameter parB6 = _档案2.入团日期 == "" ? new SqlParameter("@入团日期", DBNull.Value) : new SqlParameter("@入团日期", DateTime.Parse(_档案2.入团日期));
SqlParameter parB7 = _档案2.入职日期 == "" ? new SqlParameter("@入职日期", DBNull.Value) : new SqlParameter("@入职日期", DateTime.Parse(_档案2.入职日期));
SqlParameter parB8 = _档案2.离职日期 == "" ? new SqlParameter("@离职日期", DBNull.Value) : new SqlParameter("@离职日期", DateTime.Parse(_档案2.离职日期));
SqlParameter parB9 = new SqlParameter("@离职原因", _档案2.离职原因);
SqlParameter parB10 = _档案2.参加工作日期 == "" ? new SqlParameter("@参加工作日期", DBNull.Value) : new SqlParameter("@参加工作日期", DateTime.Parse(_档案2.参加工作日期));
SqlParameter parB11 = new SqlParameter("@入职前工龄", int.Parse(_档案2.入职前工龄));
SqlParameter parB12 = new SqlParameter("@ID", id);
#endregion
DAL dal = new DAL();
try
{
dal.TranBegin();//开始事务
dal.ExeSql(SQL1, new SqlParameter[] { par1, par2, par3, par4, par5, par6, par7, par8, par9, par10 });//执行语句
dal.ExeSql(SQL2, new SqlParameter[] { parA1, parA2, parA3, parA4, parA5, parA6, parA7, parA8, parA9, parA10, parA11, parA12, parA13, parA14 });//执行语句
dal.ExeSql(SQL3, new SqlParameter[] { parB1, parB2, parB3, parB4, parB5, parB6, parB7, parB8, parB9, parB10, parB11, parB12 });//执行语句
dal.TranCommit();//提交事务
}
catch (Exception e)
{
dal.TranRollBack();//回滚事务
throw e;
}
}
示例6: tkDel
/// <summary>
/// 删除试题
/// </summary>
/// <param name="context"></param>
public void tkDel(HttpContext context)
{
string id = context.Request["id"];//所选中ID 数组
string SQL = "DELETE FROM [CNGTZ].[dbo].[TK_选项] WHERE 所属ID IN(" + id + ")";
string retext = "{{ \"ok\":{0},\"msg\":\"{1}\",\"data\":[] }}";
DAL dal = new DAL();
var ok = false;
string msg = "";
try
{
dal.TranBegin();
dal.ExeSql(SQL);
SQL = "DELETE FROM [CNGTZ].[dbo].[TK_题目] WHERE ID IN(" + id + ")";
dal.ExeSql(SQL);
dal.TranCommit();
ok = true;
msg = "删除成功!";
}
catch (Exception e)
{
ok = false;
msg = e.Message;
}
if (ok == false)
{
dal.TranRollBack();
}
retext = string.Format(retext, ok.ToString().ToLower(), msg);
Sys.DebugMes(retext);
context.Response.Write(retext);
}
示例7: _sjTextAdd
//随机生成试题
private string _sjTextAdd(string ID)
{
string SQL = "SELECT [分类ID],[难度配置] FROM [CNGTZ].[dbo].[TK_试卷] where ID=" + ID;
DAL dal = new DAL();
string[] x = dal.RunSqlStrings(SQL);
x[0] = x[0].Substring(1, x[0].Length - 2);
x[1] = x[1].Substring(1, x[1].Length - 2);
DataTable dt1 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=1 and 所属分类 IN(" + x[0] + ") ");//简单题组
DataTable dt2 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=2 and 所属分类 IN(" + x[0] + ") ");//适中题组
DataTable dt3 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=3 and 所属分类 IN(" + x[0] + ") ");//困难题组
DataTable[] dt = new DataTable[] { dt1, dt2, dt3 };
string[] nds = x[1].Split(Convert.ToChar(","));
int[] nd = new int[3];
nd[0] = int.Parse(nds[0]);
nd[1] = int.Parse(nds[1]);
nd[2] = int.Parse(nds[2]);
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < nd.Length; i++)
{
if (dt[i].Rows.Count > nd[i])//当试题组 题目数量>难度配置 题目数量
{
int xhcs = dt[i].Rows.Count - nd[i];
for (int j = 0; j < xhcs; j++)//随机删除 多余行数
{
int h = ra.Next(0, dt[i].Rows.Count);
if (h >= 0 && h < dt[i].Rows.Count)
{
dt[i].Rows.RemoveAt(h);
}
}
}
}
DataTable dtx = null;
try
{
dal.TranBegin();
dal.ExeSql("create table #testst (id int)");//创建临时表
for (int i = 0; i < dt.Length; i++)
{
foreach (DataRow row in dt[i].Rows)//将 3组 (普通,适中,困难) 题目ID写入临时表
{
SQL = "INSERT INTO #testst (id) VALUES(" + row["ID"].ToString() + ")";
dal.ExeSql(SQL);
}
}
dtx = dal.ExeSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where ID IN (SELECT id FROM #testst) ORDER BY 题类型,NEWID()");//随机排序后 生成DataTable
dal.ExeSql("DROP TABLE #testst");
dal.TranCommit();
}
catch (Exception)
{
dal.TranRollBack();
}
string retext = "";
if (dtx != null)
{
foreach (DataRow row in dtx.Rows)
{
retext += row["id"].ToString() + ",";
}
retext = "[" + retext.Substring(0, retext.Length - 1) + "]";
}
Sys.DebugMes(retext);
return retext;
}
示例8: treeDle
/// <summary>
/// 删除分类
/// </summary>
public void treeDle(HttpContext context)
{
int id = int.Parse(context.Request["id"]);
string path = context.Request["path"];
string retext = "{{ \"ok\":{0},\"msg\":\"{1}\",\"data\":[] }}";
DAL dal = new DAL();
int[] delID = null;
List<int> all = new List<int>();
all.Add(id);
_treeDell(id.ToString(), ref all);
delID = all.ToArray();//需要删除 分类树
string SQL = @"";
dal.TranBegin();
var ok = true;
var msg = "删除操作成功!";
try
{
//删除 分类下 所有子分类的题目的答案选项
SQL = @"DELETE FROM [CNGTZ].[dbo].[TK_选项] where 分类路径 LIKE '" + path + "%'";
dal.ExeSql(SQL);
//删除 分类下 所有子分类题目
SQL = @"DELETE FROM [CNGTZ].[dbo].[TK_题目] WHERE 分类路径 LIKE '" + path + "%'";
dal.ExeSql(SQL);
SQL = @"create table #delid (id int)";
dal.ExeSql(SQL);
foreach (int i in delID)
{
SQL = "INSERT INTO #delid (id)VALUES(" + i.ToString() + ")";
dal.ExeSql(SQL);
}
SQL = @"DELETE FROM [CNGTZ].[dbo].[TK_分类] where 编号 in (select id from #delid)";
dal.ExeSql(SQL);
dal.ExeSql("DROP TABLE #delid");
}
catch (Exception)
{
ok = false;
msg = dal.ErrorMsg;
dal.TranRollBack();
}
if (ok)
{
dal.TranCommit();
}
retext = string.Format(retext, ok.ToString().ToLower(), msg);
context.Response.Write(retext);
}
示例9: tkGuiLei
/// <summary>
/// 题库归类
/// </summary>
/// <param name="context"></param>
public void tkGuiLei(HttpContext context)
{
string ids = context.Request["ids"];//所选中ID 数组
int id = int.Parse(context.Request["id"]);//新分类的 ID
string path = context.Request["path"];//新分类的 ID 路径
string name = context.Request["name"];//新分类的 ID 路径
string SQL = "UPDATE [CNGTZ].[dbo].[TK_题目] SET [所属分类] = @所属分类,[分类路径] = @分类路径,[修改时间] =GETDATE(),[修改人] = @修改人 WHERE ID IN (" + ids + ")";
string retext = "{{ \"ok\":{0},\"msg\":\"{1}\",\"data\":[] }}";
DAL dal = new DAL();
SqlParameter par1 = new SqlParameter("所属分类", id);
SqlParameter par2 = new SqlParameter("分类路径", path);
SqlParameter par3 = new SqlParameter("修改人", name);
var ok = true;
var msg = "更改分类成功!";
try
{
dal.TranBegin();
dal.ExeSql(SQL, new SqlParameter[] { par1, par2, par3 });//更新题库 所属分类
SQL = "UPDATE [CNGTZ].[dbo].[TK_选项] SET [分类路径] = @分类路径 WHERE 所属ID IN (" + ids + ")"; //更新答案选项 分类路径
dal.ExeSql(SQL, new SqlParameter[] { par2 });
}
catch (Exception e)
{
dal.TranRollBack();
ok = false;
msg = e.Message;
}
if (ok)
{
dal.TranCommit();
}
retext = string.Format(retext, ok.ToString().ToLower(), msg);
Sys.DebugMes(retext);
context.Response.Write(retext);
}