public void ProcessRequest(HttpContext context) { //清空之前数据 context.Response.Clear(); //检测是否含有session if (context.Session.Count < 5) { //跳转 context.Response.Redirect("/Account/Login", true); //停止加载后续内容 context.Response.End(); //直接返回 return; } //执行基类的方法 if (!base.CheckIsLogin(context)) { return; } //用户传入的批量卡序号、订单序号 string lotId = context.Request["lid"]; string orderId = context.Request["oid"]; //检测传入的批量卡序号 if (!string.IsNullOrEmpty(lotId)) { //数据适配器获取订单信息 using (var da = new t_sample_lot_cardTableAdapter()) using (var tab = da.GetDataByLotId(lotId)) { //检测是否含有数据 if (tab.Rows.Count > 0) { //首行 orderId = tab.Rows[0]["order_id"].ToString(); //待返回的订单信息表内容 string strOrderInfo = CreateLotCardInfoTable(tab); //写入数据到浏览器 context.Response.Write(strOrderInfo); } } } //检测订单序号 if (string.IsNullOrEmpty(orderId)) { return; } //数据适配器获取订单信息 using (var da = new t_sample_orderTableAdapter()) using (var tab = da.GetDataByOrderId(orderId)) { //待返回的订单信息表内容 string strOrderInfo = CreateOrderInfoTable(tab); //写入数据到浏览器 context.Response.Write(strOrderInfo); } }
/// <summary> /// 检测指定的lotid是否存在 /// </summary> /// <param name="lotId">样板lot卡号</param> /// <param name="tran">在指定事务中执行查询</param> /// <returns></returns> internal static bool IsExistSampleLotId(string strLotId, SqlTransaction tran) { //检测样板lot卡id号是否存在于sample所开的样板lot卡记录中 using (var da = new t_sample_lot_cardTableAdapter()) { if (tran != null) { //当前数据库连接 da.Connection = tran.Connection; //设置事务 da.Transaction = tran; } //获取数据 using (var tab = da.GetDataByLotId(strLotId)) { //lotid号存在提示错误 if (tab.Rows.Count > 0) { //报告失败 throw new Exception("待保存的样板lot卡号 " + strLotId + " 已经存在于样板lot卡记录中!"); } } } //检测样板lot卡id号是否存在于样板wip记录中 using (var da = new t_dept_lot_card_balanceTableAdapter()) { if (tran != null) { //当前数据库连接 da.Connection = tran.Connection; //设置事务 da.Transaction = tran; } //获取数据 using (var tab = da.GetFirstRowByLotId(strLotId)) { //lotid号存在提示错误 if (tab.Rows.Count > 0) { //报告失败 throw new Exception("待保存的样板lot卡号 " + strLotId + " 已经存在于样板wip记录中!"); } } } //返回不存在 return false; }
/// <summary> /// 根据输入的LOT格式来保存多条数据到数据库 /// </summary> /// <param name="e">传入的带有数据的事件参数</param> /// <param name="procName">当前部门名称</param> /// <returns></returns> private bool InsertData(FormViewInsertEventArgs e, string procName) { //当前用户输入的批量卡号 string strLotIdBegin = e.Values["lot_id"].ToString(); //当前用户输入的结束批量卡号 string strLotIdEnd = ((TextBox)fvProductRecordAdd.FindControl("txtLotIdEnd")).Text.Trim(); //数据适配器 //当前添加语句对象 //当前数据库连接 using (var da = new t_product_record_wenziTableAdapter()) using (var cmd = da.Adapter.InsertCommand) using (var conn = cmd.Connection) { //打开数据库连接 conn.Open(); //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 da.Transaction = tran; //试运行 try { //检测是否有结束批量卡号 if (strLotIdEnd.Length == 0) { //检测批量卡是否正确 //正则表达式 string strReg = @"^[1-9]\d(0[1-9]|1[012])-S?[1-9]\d{0,4}"; //检测是否正确批量卡号 if (!Regex.IsMatch(strLotIdBegin, strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的批量卡号 " + strLotIdBegin + " !"); } //检测是否最小批量卡号 if (!ydPublicMethod.IsMinLotId(tran, procName, strLotIdBegin)) { //直接返回 return false; } //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, strLotIdBegin, e)) { //失败就直接返回 return false; } } else { //正则表达式 string strReg = @"^[1-9]\d{0,4}$"; //检测是否正确批量卡号 if (!Regex.IsMatch(strLotIdEnd, strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的结束批量卡号 " + strLotIdEnd + " !"); } //检测是否样板 bool isSample = strLotIdBegin.ToUpper().Contains("S"); //批量卡中的年份月份和数字索引号 string strYearMonth; int iLotIdStart; int iLotIdEnd = int.Parse(strLotIdEnd); if (!isSample) { strYearMonth = strLotIdBegin.Substring(0, 5); iLotIdStart = int.Parse(strLotIdBegin.Substring(5)); } else { strYearMonth = strLotIdBegin.Substring(0, 6); iLotIdStart = int.Parse(strLotIdBegin.Substring(6)); } //检测起始和结束批量卡号,让起始批量卡号最小 if (iLotIdStart > iLotIdEnd) { int i = iLotIdStart; iLotIdStart = iLotIdEnd; iLotIdEnd = i; } //批量卡不能太多,不允许超过10张 if (iLotIdEnd - iLotIdStart > 10) { //不允许超过10张 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 的批量卡太多,不允许超过10张!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } //区分生产和样板来执行保存操作 if (!isSample) { //获取订单序号的数据适配器 using (var daGetOrderId = new t_ppc_lot_cardTableAdapter()) { //设置数据库连接 daGetOrderId.Connection = conn; //设置事务 daGetOrderId.Transaction = tran; //订单序号 string orderId = string.Empty; //检测输入的批量卡号段是否在同一个订单序号中 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //获取 var tab = daGetOrderId.GetDataByLotId(strYearMonth + i.ToString()); //检查结果 if (tab.Rows.Count == 0) { //报告失败 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 不存在!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } else { //首张批量卡号只获取不比较 if (i == iLotIdStart) { //取得订单序号 orderId = ((DataSetPpcLotCardMgr.t_ppc_lot_cardRow)tab.Rows[0]).order_id; } else if (orderId != ((DataSetPpcLotCardMgr.t_ppc_lot_cardRow)tab.Rows[0]).order_id) { //报告失败 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 中的{1}{3}跟其之前的批量卡不是一张订单!", strLotIdBegin, strYearMonth, strLotIdEnd, i ) ); } } } //当前报数的pnl数以及pcs数 int pnlQty = Convert.ToInt32(e.Values["pnl_qty"]); int pcsQty = Convert.ToInt32(e.Values["pcs_qty"]); //最后批量卡号 string strLotEnd = strYearMonth + iLotIdEnd.ToString(); //部门结余pnl总数及pcs总数 int totalPnlQty = 0; int totalPcsQty = 0; //检测最后一LOT板的数量必须为本部门结存的全部数量 ydOperateBalanceLotCrad.GetProcBalanceQty( tran, procName, strLotEnd, true, out totalPnlQty, out totalPcsQty ); //检测是否不等于该数量 if (pnlQty == totalPnlQty && pcsQty == totalPcsQty) { } else { //是否一样 bool isSame = false; if (pnlQty != totalPnlQty && pcsQty != totalPcsQty) { //获取pnl含pcs数 int pnlCountPcs = ydOperateBalanceLotCrad.GetPnlCountPcs(tran, strLotEnd); //检测是否一样 if (totalPnlQty * pnlCountPcs == pcsQty) { isSame = true; } } //不一样 if (!isSame) { //抛出错误 if (totalPnlQty > 0) { throw new Exception( string.Format( "如果有报结束批量卡号,则结束批量卡号({0})的数量必须为本部门总结存数 {1} pnl!", strLotEnd, totalPnlQty ) ); } else { throw new Exception( string.Format( "如果有报结束批量卡号,则结束批量卡号({0})的数量必须为本部门总结存数 {1} pcs!", strLotEnd, totalPcsQty ) ); } } } //执行保存 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //当前待保存的批量卡序号 string curLotId = strYearMonth + i.ToString(); //检测是否最小批量卡号 if (!ydPublicMethod.IsMinLotId(tran, procName, curLotId)) { //直接返回 return false; } //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, curLotId, e)) { //失败就直接返回 return false; } } } } else { //获取样板订单序号的数据适配器 using (var daGetOrderId = new t_sample_lot_cardTableAdapter()) { //设置数据库连接 daGetOrderId.Connection = conn; //设置事务 daGetOrderId.Transaction = tran; //样板订单序号 string orderId = string.Empty; //检测输入的批量卡号段是否在同一个订单序号中 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //获取 var tab = daGetOrderId.GetDataByLotId(strYearMonth + i.ToString()); //检查结果 if (tab.Rows.Count == 0) { //报告失败 throw new Exception( string.Format( "您输入的样板批量卡号段 {0} 到 {1}{2} 不存在!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } else { //首张批量卡号只获取不比较 if (i == iLotIdStart) { //取得订单序号 orderId = ((DAL.Sample.DataSetSampleLotCardMgr.t_sample_lot_cardRow)tab.Rows[0]).order_id; } else if (orderId != ((DAL.Sample.DataSetSampleLotCardMgr.t_sample_lot_cardRow)tab.Rows[0]).order_id) { //报告失败 throw new Exception( string.Format( "您输入的样板批量卡号段 {0} 到 {1}{2} 中的{1}{3}跟其之前的批量卡不是一张订单!", strLotIdBegin, strYearMonth, strLotIdEnd, i ) ); } } } //当前报数的pnl数以及pcs数 int pnlQty = Convert.ToInt32(e.Values["pnl_qty"]); int pcsQty = Convert.ToInt32(e.Values["pcs_qty"]); //最后批量卡号 string strLotEnd = strYearMonth + iLotIdEnd.ToString(); //部门结余pnl总数及pcs总数 int totalPnlQty = 0; int totalPcsQty = 0; //检测最后一LOT板的数量必须为本部门结存的全部数量 ydOperateBalanceLotCrad.GetProcBalanceQty( tran, procName, strLotEnd, true, out totalPnlQty, out totalPcsQty ); //检测是否不等于该数量 if (pnlQty == totalPnlQty && pcsQty == totalPcsQty) { } else { //是否一样 bool isSame = false; if (pnlQty != totalPnlQty && pcsQty != totalPcsQty) { //获取pnl含pcs数 int pnlCountPcs = ydOperateBalanceLotCrad.GetPnlCountPcs(tran, strLotEnd); //检测是否一样 if (totalPnlQty * pnlCountPcs == pcsQty) { isSame = true; } } //不一样 if (!isSame) { //抛出错误 if (totalPnlQty > 0) { throw new Exception( string.Format( "如果有报结束批量卡号,则结束批量卡号({0})的数量必须为本部门总结存数 {1} pnl!", strLotEnd, totalPnlQty ) ); } else { throw new Exception( string.Format( "如果有报结束批量卡号,则结束批量卡号({0})的数量必须为本部门总结存数 {1} pcs!", strLotEnd, totalPcsQty ) ); } } } //执行保存 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //当前待保存的批量卡序号 string curLotId = strYearMonth + i.ToString(); //检测是否最小批量卡号 if (!ydPublicMethod.IsMinLotId(tran, procName, curLotId)) { //直接返回 return false; } //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, curLotId, e)) { //失败就直接返回 return false; } } } } } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //非数字返回失败 throw new Exception(ex.Message); } } } }
/// <summary> /// 根据输入的LOT格式来保存多条数据到数据库 /// </summary> /// <param name="e">传入的带有数据的事件参数</param> /// <param name="procName">当前部门名称</param> /// <returns></returns> private bool InsertData(FormViewInsertEventArgs e, string procName) { //当前用户输入的批量卡号 string strLotIdBegin = e.Values["lot_id"].ToString(); //当前用户输入的结束批量卡号 string strLotIdEnd = ((TextBox)fvWaitScrapRecordBackAdd.FindControl("txtLotIdEnd")).Text.Trim(); //数据适配器 //当前添加语句对象 //当前数据库连接 using (var da = new t_wait_scrap_record_backTableAdapter()) using (var cmd = da.Adapter.InsertCommand) using (var conn = cmd.Connection) { //打开数据库连接 conn.Open(); //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 da.Transaction = tran; //试运行 try { //检测是否有结束批量卡号 if (strLotIdEnd.Length == 0) { //检测批量卡是否正确 //正则表达式 string strReg = @"^[1-9]\d(0[1-9]|1[012])-S?[1-9]\d{0,4}"; //检测是否正确批量卡号 if (!Regex.IsMatch(strLotIdBegin, strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的批量卡号 " + strLotIdBegin + " !"); } //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, strLotIdBegin, e, true, null)) { //失败就直接返回 return false; } } else { //正则表达式 string strReg = @"^[1-9]\d{0,4}$"; //检测是否正确批量卡号 if (!Regex.IsMatch(strLotIdEnd, strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的结束批量卡号 " + strLotIdEnd + " !"); } //检测是否样板 bool isSample = strLotIdBegin.ToUpper().Contains("S"); //批量卡中的年份月份和数字索引号 string strYearMonth; int iLotIdStart; int iLotIdEnd = int.Parse(strLotIdEnd); if (!isSample) { strYearMonth = strLotIdBegin.Substring(0, 5); iLotIdStart = int.Parse(strLotIdBegin.Substring(5)); } else { strYearMonth = strLotIdBegin.Substring(0, 6); iLotIdStart = int.Parse(strLotIdBegin.Substring(6)); } //检测起始和结束批量卡号,让起始批量卡号最小 if (iLotIdStart > iLotIdEnd) { int i = iLotIdStart; iLotIdStart = iLotIdEnd; iLotIdEnd = i; } //批量卡不能太多,不允许超过10张 if (iLotIdEnd - iLotIdStart > 10) { //不允许超过10张 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 的批量卡太多,不允许超过10张!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } //区分生产和样板来执行保存操作 if (!isSample) { //获取订单序号的数据适配器 using (var daGetOrderId = new t_ppc_lot_cardTableAdapter()) { //设置数据库连接 daGetOrderId.Connection = conn; //设置事务 daGetOrderId.Transaction = tran; //订单序号 string orderId = string.Empty; //检测输入的批量卡号段是否在同一个订单序号中 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //获取 var tab = daGetOrderId.GetDataByLotId(strYearMonth + i.ToString()); //检查结果 if (tab.Rows.Count == 0) { //报告失败 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 不存在!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } else { //首张批量卡号只获取不比较 if (i == iLotIdStart) { //取得订单序号 orderId = ((DataSetPpcLotCardMgr.t_ppc_lot_cardRow)tab.Rows[0]).order_id; } else if (orderId != ((DataSetPpcLotCardMgr.t_ppc_lot_cardRow)tab.Rows[0]).order_id) { //报告失败 throw new Exception( string.Format( "您输入批量卡号段 {0} 到 {1}{2} 中的{1}{3}跟其之前的批量卡不是一张订单!", strLotIdBegin, strYearMonth, strLotIdEnd, i ) ); } } } //执行保存 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //当前待保存的批量卡序号 string curLotId = strYearMonth + i.ToString(); //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, curLotId, e, true, null)) { //失败就直接返回 return false; } } } } else { //获取样板订单序号的数据适配器 using (var daGetOrderId = new t_sample_lot_cardTableAdapter()) { //设置数据库连接 daGetOrderId.Connection = conn; //设置事务 daGetOrderId.Transaction = tran; //订单序号 string orderId = string.Empty; //检测输入的批量卡号段是否在同一个订单序号中 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //获取 var tab = daGetOrderId.GetDataByLotId(strYearMonth + i.ToString()); //检查结果 if (tab.Rows.Count == 0) { //报告失败 throw new Exception( string.Format( "您输入的样板批量卡号段 {0} 到 {1}{2} 不存在!", strLotIdBegin, strYearMonth, strLotIdEnd ) ); } else { //首张批量卡号只获取不比较 if (i == iLotIdStart) { //取得订单序号 orderId = ((DataSetSampleLotCardMgr.t_sample_lot_cardRow)tab.Rows[0]).order_id; } else if (orderId != ((DataSetSampleLotCardMgr.t_sample_lot_cardRow)tab.Rows[0]).order_id) { //报告失败 throw new Exception( string.Format( "您输入的样板批量卡号段 {0} 到 {1}{2} 中的{1}{3}跟其之前的批量卡不是一张订单!", strLotIdBegin, strYearMonth, strLotIdEnd, i ) ); } } } //执行保存 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //当前待保存的批量卡序号 string curLotId = strYearMonth + i.ToString(); //保存一条记录到数据库 if (!ydOperateBalanceLotCrad.InsertOneRecord(cmd, curLotId, e, true, null)) { //失败就直接返回 return false; } } } } } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //非数字返回失败 throw new Exception(ex.Message); } } } }