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; } //用户传入的lot卡号、订单序号 string lotId = context.Request["lid"]; string orderId = context.Request["oid"]; //检测传入的lot卡号 if (!string.IsNullOrWhiteSpace(lotId)) { //数据适配器获取订单信息 using (var da = new t_ppc_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.IsNullOrWhiteSpace(orderId)) { return; } //数据适配器获取订单信息 using (var da = new t_pmc_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 IsExistLotId(string strLotId, SqlTransaction tran) { //检测lot卡id号是否存在于ppc所开的lot卡记录中 using (var da = new t_ppc_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); } } } }
protected void fvLotCardMgrSupplementAdd_ItemCreated(object sender, EventArgs e) { //新增状态 if (fvLotCardMgrSupplementAdd.CurrentMode == FormViewMode.Insert) { //当前批量卡id号 var tb = (TextBox)fvLotCardMgrSupplementAdd.FindControl("txtLotId"); if (tb != null) { //获取最大id号 using (var da = new t_ppc_lot_cardTableAdapter()) { //获取结果 object obj = da.GetLastLotId(); //获取最大id号 string str = string.Empty; if (obj != null) { //获取最大id号 str = obj.ToString(); } if (!Regex.IsMatch(str, @"^[1-9]\d(0[1-9]|1[012])-[1-9]\d{0,4}$") || DateTime.Now.ToString("yyMM") != str.Substring(0, 4)) { //本月第一张批量卡 str = DateTime.Now.ToString("yyMM-1"); } else { //修改批量卡号+1 str = str.Substring(0, 5) + (int.Parse(str.Substring(5)) + 1).ToString(); } //设置起始批量卡号为最大id号+1 tb.Text = str; } } //设置默认订单序号 tb = (TextBox)fvLotCardMgrSupplementAdd.FindControl("txtOrderId"); if (tb != null) { //获取当前已经开批量卡的最大订单序号 using (var da = new t_ppc_lot_cardTableAdapter()) { //获取 object obj = da.GetLastOrderId(); string strMaxId = "A0"; if (obj != null && obj.ToString().Trim().Length > 0) { strMaxId = obj.ToString(); } //设置为最大id号+1 tb.Text = strMaxId.Substring(0, 1) + (int.Parse(strMaxId.Substring(1)) + 1).ToString(); } } //当前编号首部门 tb = (TextBox)fvLotCardMgrSupplementAdd.FindControl("txtFirstProc"); if (tb != null) { //检查用户提供的首部门参数标识 string strProc = Request["fproc"]; if (strProc != null && strProc.Length > 0) { //设置默认用户提供的首部门 tb.Text = strProc; } else { //当前用户所在部门id byte procId = Convert.ToByte(Session["proc_id"]); //从数据库中获取PMC的下个部门 using (var da = new t_procTableAdapter()) using (var tab = da.GetDataByProcId(procId)) { //检查是否存在数据 if (tab.Rows.Count > 0) { var row = tab.Rows[0] as DataSetProc.t_procRow; //设置到文本框 if (!row.Isnext_proc_nameNull()) { tb.Text = row.next_proc_name; } } } } } } //当前订单序号获取焦点 var txtOrderId = (TextBox)fvLotCardMgrSupplementAdd.FindControl("txtOrderId"); if (txtOrderId != null) { //设置焦点 txtOrderId.Focus(); } //当前状态 if (fvLotCardMgrSupplementAdd.CurrentMode == FormViewMode.Insert) { //设置默认补料单为true var chk = (CheckBox)fvLotCardMgrSupplementAdd.FindControl("chkIsSupplement"); if (chk != null) { chk.Checked = true; } } }
//根据传入的参数处理事情 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; } //用户传入的lot卡号 string lotId = context.Request["lid"]; //检测lot卡号 if (lotId == null || lotId.Length < 6) { throw new Exception("未提供lot卡号参数或者lot卡号参数长度太短!"); } //待输出到浏览器的数据 string strResult = string.Empty; try { //根据lot卡号获取lot卡和订单信息 using (var da = new v_ppc_lot_card_join_orderTableAdapter()) using (var tab = da.GetDataByLotId(lotId)) { //检测获取到的数据数据 if (tab.Rows.Count <= 0) { strResult = "打印失败:PMC录入的lot卡不存在!"; } else { //首行 var row = (DataSetPpcLotCardMgr.v_ppc_lot_card_join_orderRow)tab.Rows[0]; //取得生产编号 string productNum = row.product_num.Trim().ToUpper(); //检测生产编号的正确性 string strReg = @"^TY(?!Y)[A-Z]-[1-9]\d{0,7}[0A-Z][0-9]$"; if (!Regex.IsMatch(productNum, strReg)) { strResult = string.Format("打印失败:{0}生产编号不符合规则,必须为 TYZ-100A0 格式!", productNum); } else { //生产编号中的层数起始字符索引 int iNumStart = productNum.IndexOf("-") + 1; //抓取生产编号中的数字序号串和版本 int pNum = int.Parse(productNum.Substring(iNumStart, productNum.Length - iNumStart - 2)); string pVersion = productNum.Substring(productNum.Length - 2); //根目录编号段 int iNumBegin = (pNum / 3000) * 3000 + 1; int iNumEnd = iNumBegin + 3000 - 1; //拼接文件夹路径 var sb = new StringBuilder("E:\\工程"); //确定顶级文件夹名称 sb.Append(iNumBegin.ToString("0000") + "-" + iNumEnd.ToString("0000")); //确定次级文件夹名称 sb.Append("\\" + productNum + "\\" + productNum + ".xls"); //得到lot卡文件全路径 string lotCardFullPath = sb.ToString(); //检查文件是否存在 if (!File.Exists(lotCardFullPath)) { strResult = "打印失败:工程lot卡不存在!路径为:" + lotCardFullPath; } else { //excel对象 var xlApp = new Excel.Application(); //打开该excel文件 xlApp.Visible = true; xlApp.DisplayAlerts = false; try { //打开工作簿 var xlBook = xlApp.Workbooks.Open(lotCardFullPath, ReadOnly: true); foreach (Excel.Worksheet item in xlBook.Worksheets) { if (item.Name != "normal") { item.Delete(); } } var xlSheet = (Excel.Worksheet)xlBook.Worksheets[1]; //设置为活动 ((Excel._Worksheet)xlSheet).Select(); //设置值 //订单序号 xlSheet.Range["S1"].Value = row.order_id; //LOT卡号 xlSheet.Range["S2"].Value = row.lot_id; //客户名称 xlSheet.Range["C3"].Value = row.Iscust_nameNull() ? string.Empty : row.cust_name; //下单日期 xlSheet.Range["F3"].Value = row.Isorder_dateNull() ? string.Empty : row.order_date.ToString("yyyy-MM-dd"); //需求日期 xlSheet.Range["K3"].Value = row.Isneed_dateNull() ? string.Empty : row.need_date.ToString("yyyy-MM-dd"); //生产日期 xlSheet.Range["S3"].Value = row.Isproduct_dateNull() ? string.Empty : row.product_date.ToString("yyyy-MM-dd"); //订单数量 xlSheet.Range["C6"].Value = row.Isorder_pcs_qtyNull() ? string.Empty : row.order_pcs_qty.ToString(); //投产数量 using (var da2 = new t_ppc_lot_cardTableAdapter()) { xlSheet.Range["F6"].Value = da2.SumPcsQtyByOrderId(row.order_id).ToString(); } //当前开料lot卡pnl长宽 var strPnlLength = row.pnl_length.ToString(); var strPnlWidth = row.pnl_width.ToString(); //当前工程lot卡pnl长宽A var strPnlLengthA = xlSheet.Range["I5"].Text.ToString(); var strPnlWidthA = xlSheet.Range["L5"].Text.ToString(); //当前工程lot卡pnl长宽B var strPnlLengthB = xlSheet.Range["I6"].Text.ToString(); var strPnlWidthB = xlSheet.Range["L6"].Text.ToString(); //检测使用的是哪种工程MI尺寸 string strPnlSize = string.Empty; //检测是否符合工程MI中填写的pnl尺寸 if ((strPnlLength == strPnlLengthA && strPnlWidth == strPnlWidthA) || (strPnlLength == strPnlWidthA && strPnlWidth == strPnlLengthA)) { strPnlSize = "A板"; } else if ((strPnlLength == strPnlLengthB&& strPnlWidth == strPnlWidthB) || (strPnlLength == strPnlWidthB && strPnlWidth == strPnlLengthB)) { strPnlSize = "B板"; } else { strPnlSize = "B板"; xlSheet.Range["I6"].Value = strPnlLength; xlSheet.Range["L6"].Value = strPnlWidth; xlSheet.Range["N6"].Value = string.Empty; xlSheet.Range["Q6"].Value = string.Empty; xlSheet.Range["T6"].Value = row.pnl_count_pcs; } //本卡数量 xlSheet.Range["K7"].Value = strPnlSize + row.pnl_qty; //本卡面积 xlSheet.Range["R7"].Value = row.total_pnl_area; //订单编号 xlSheet.Range["C64"].Value = row.Isorder_numNull() ? string.Empty : row.order_num; //只打印为一页 xlSheet.PageSetup.FitToPagesWide = 1; xlSheet.PageSetup.FitToPagesTall = 1; //打印lot卡 xlSheet.PrintOut(From: 1, To: 1, Copies: 1, Collate: true); //关闭工作表 xlBook.Close(SaveChanges: false); //待返回的状态结果 strResult = "打印成功!"; //注销excel相关对象 xlSheet = null; xlBook = null; } catch (Exception exx) { throw exx; } finally { //关闭excel文档 foreach (Excel.Workbook itm in xlApp.Workbooks) { itm.Close(SaveChanges: false); } xlApp.Quit(); //关闭excel进程 ydPublicMethod.KillExcel(xlApp); xlApp = null; } } } } } } catch (Exception ex) { strResult = "打印失败:" + ex.Message; } //写入数据到浏览器 context.Response.Write(strResult); }
/// <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); } } } }
/// <summary> /// 获取pnl含pcs数 /// </summary> /// <param name="tran">当前事务</param> /// <param name="lotId">lot卡号</param> /// <returns></returns> internal static Int16 GetPnlCountPcs( SqlTransaction tran, string lotId ) { //当前数据库连接对象 var conn = tran.Connection; //检测lot卡号 if (lotId.Length < 6) { throw new Exception("提供的lot卡号不正确!"); } //检测是否样板 bool isSample = lotId.ToUpper().Contains("S"); if (!isSample) { //实例化查询适配器对象 using (var da = new t_ppc_lot_cardTableAdapter()) { //重新设置数据库连接 da.Connection = conn; //设置事务 da.Transaction = tran; //获取pnl含pcs数 return (Int16)da.GetPnlCountPcs(lotId); } } else { //实例化查询适配器对象 using (var da = new t_sample_lot_cardTableAdapter()) { //重新设置数据库连接 da.Connection = conn; //设置事务 da.Transaction = tran; //获取pnl含pcs数 return (Int16)da.GetPnlCountPcs(lotId); } } }
/// <summary> /// 删除指定的lot卡 /// </summary> /// <param name="orderId">当前要删除的序号</param> /// <returns></returns> internal static bool DeleteLotCardRecordByOrderId(string orderId) { //当前要删除的id号和lot卡号 List<Int64> lId = new List<Int64>(); List<string> lLotId = new List<string>(); //实例化数据适配器 using (var da = new t_ppc_lot_cardTableAdapter()) using (var tab = da.GetDataByOrderId(orderId)) { if (tab.Rows.Count > 0) { //首行 foreach (DataSetPpcLotCardMgr.t_ppc_lot_cardRow row in tab.Rows) { //获取序号 lId.Add(row.id); //获取lot卡号 lLotId.Add(row.lot_id); } } else { throw new Exception("未找到指定的lot卡,可能已经被其他用户删除,请刷新后重试!"); } } //保存数据到部门lot卡记录中的sql添加语句 string sqlstr = "DELETE FROM [t_dept_lot_card_balance] WHERE [lot_id]=@lotId"; //数据适配器 //当前数据库连接 //当前更新语句对象 using (var da = new t_ppc_lot_cardTableAdapter()) using (var conn = da.Connection) using (var cmd = da.Adapter.DeleteCommand) using (var cmdDept = new SqlCommand(sqlstr, conn)) { //打开数据库连接 conn.Open(); //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 da.Transaction = tran; cmdDept.Transaction = tran; //试运行 try { //循环执行删除 foreach (Int64 itm in lId) { //设置参数 cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Original_id", itm); //执行从ppc所开lot卡中删除 cmd.ExecuteNonQuery(); } foreach (string itm in lLotId) { //设置参数 cmdDept.Parameters.Clear(); cmdDept.Parameters.AddWithValue("@lotId", itm); //执行从部门结余lot卡中删除 cmdDept.ExecuteNonQuery(); } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw new Exception(ex.Message); } } } }
/// <summary> /// 根据输入的LOT格式来保存多条数据到数据库 /// </summary> /// <param name="e">传入的带有数据的事件参数</param> /// <param name="orderPnlQty">订单开料数量</param> /// <param name="lotPnlQty">lot卡每lot数量</param> /// <returns></returns> internal static bool InsertLotCardRecord(FormViewInsertEventArgs e, int orderPnlQty, int lotPnlQty) { //当前用户输入的lot卡号 string strInput = e.Values["lot_id"].ToString().Trim().Replace("-", "-").Replace("—", "-"); //检测是否只输入了一个lot卡号 string[] strLotIds = strInput.Split(new string[] { "--" }, StringSplitOptions.None); //检测是否正确lot卡号并转换 if (!ydOperateLotCard.IsLotCardId(ref strLotIds[0])) { //返回失败 throw new Exception("您输入了一个不合格的lot卡号 " + strLotIds[0] + " !"); } //生产编号 string productNum = string.Empty; //获取订单中的生产编号 using (var da = new t_pmc_orderTableAdapter()) using (var tab = da.GetDataByOrderId(e.Values["order_id"].ToString())) { //检测有数据 if (tab.Rows.Count > 0) { //首行 var row = (DataSetPmcOrderMgr.t_pmc_orderRow)tab.Rows[0]; //获取生产编号 productNum = row.product_num; } } //检测是否获取到生产编号 if (string.IsNullOrWhiteSpace(productNum)) { throw new Exception("未从订单中获取到生产编号!"); } //保存数据到部门lot卡记录中的sql添加语句 string sqlstr = "INSERT INTO [t_dept_lot_card_balance](" + "[prev_dept_name],[dept_name],[lot_id],[product_num],[pnl_qty],[pcs_qty]," + "[remark],[add_person],[add_time],[last_change_time]" + ") VALUES (" + "@prevDeptName,@deptName,@lotId,@productNum,@pnlQty,@pcsQty," + "@remark,@addPerson,@addTime,@lastChangeTime" + ")"; //数据适配器 //当前数据库连接 //当前更新语句对象 using (var da = new t_ppc_lot_cardTableAdapter()) using (var conn = da.Connection) using (var cmd = da.Adapter.InsertCommand) using (var cmdDept = new SqlCommand(sqlstr, conn)) { //打开数据库连接 conn.Open(); //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 da.Transaction = tran; cmdDept.Transaction = tran; //试运行 try { //按照单条添加 if (strLotIds.Length == 1) { //当前输入的lot卡号 string lotId = e.Values["lot_id"].ToString().Trim(); //保存一条记录到数据库 if (!InsertOneRecord(cmd, cmdDept, productNum, lotId, lotPnlQty, e)) { //失败就直接返回 return false; } } else { //写入lot卡后剩余待写入数量 int balancePnlQty = orderPnlQty; //检测结束lot卡号 if (strLotIds[1].Length == 0) { //使用最大编号作为结束lot卡号 strLotIds[1] = int.MaxValue.ToString(); } else { //正则检测 string strReg = @"^[1-9]\d{0,4}$"; //检测是否正确lot卡号 if (!Regex.IsMatch(strLotIds[1], strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的lot卡号 " + strLotIds[1] + " !"); } } //lot卡中的年份月份和数字索引号 string strYear = strLotIds[0].Substring(0, 5); int iLotIdStart = int.Parse(strLotIds[0].Substring(5)); int iLotIdEnd = int.Parse(strLotIds[1]); //检测起始和结束lot卡号,让起始lot卡号最小 if (iLotIdStart > iLotIdEnd) { int i = iLotIdStart; iLotIdStart = iLotIdEnd; iLotIdEnd = i; } //循环设置lot卡号执行保存 for (int i = iLotIdStart; i <= iLotIdEnd; i++) { //只剩下lot卡1.5倍数量就一次性开一张卡 if (balancePnlQty <= lotPnlQty * 1.5) { lotPnlQty = balancePnlQty; } ////检测当前应该写入的pnl数量 //if (balancePnlQty < lotPnlQty) //{ // lotPnlQty = balancePnlQty; //} //当前要添加的lot卡号 string lotId = strYear + i.ToString(); //保存一条记录到数据库 if (!InsertOneRecord(cmd, cmdDept, productNum, lotId, lotPnlQty, e)) { //失败就直接返回 return false; } else { //当前剩余数量 balancePnlQty -= lotPnlQty; //检测剩余数量小于或等于0则退出循环 if (balancePnlQty <= 0) { break; } } } } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //非数字返回失败 throw new Exception(ex.Message); } } } }
protected void fvLotCardMgrAdd_ItemCreated(object sender, EventArgs e) { //新增状态 if (fvLotCardMgrAdd.CurrentMode == FormViewMode.Insert) { //当前lot卡id号 var tb = (TextBox)fvLotCardMgrAdd.FindControl("txtLotId"); if (tb != null) { //获取最大id号 using (var da = new t_ppc_lot_cardTableAdapter()) { //获取结果 object obj = da.GetLastLotId(); //获取最大id号 string str = string.Empty; if (obj != null) { //获取最大id号 str = obj.ToString(); } if (!Regex.IsMatch(str, @"^[1-9]\d(0[1-9]|1[012])-[1-9]\d{0,4}$") || DateTime.Now.ToString("yyMM") != str.Substring(0, 4)) { //本年度第一张lot卡 str = DateTime.Now.ToString("yyMM-1"); } else { //修改lot卡号+1 str = str.Substring(0, 5) + (int.Parse(str.Substring(5)) + 1).ToString(); } //设置起始lot卡号 tb.Text = str; } } //设置默认订单序号 tb = (TextBox)fvLotCardMgrAdd.FindControl("txtOrderId"); if (tb != null) { //获取当前已经开lot卡的最大订单序号 using (var da = new t_ppc_lot_cardTableAdapter()) { //获取 object obj = da.GetLastOrderId(); string strMaxId = "A0"; if (obj != null && obj.ToString().Trim().Length > 0) { strMaxId = obj.ToString(); } //设置为最大id号+1 tb.Text = strMaxId.Substring(0, 1) + (int.Parse(strMaxId.Substring(1)) + 1).ToString(); } } //设置lot卡默认pnl数量 tb = (TextBox)fvLotCardMgrAdd.FindControl("txtEveryCardPnlQty"); if (tb != null) { //设置lot卡默认pnl数量 tb.Text = "200"; } //当前编号首部门 tb = (TextBox)fvLotCardMgrAdd.FindControl("txtFirstDeptName"); if (tb != null) { //检查用户提供的首部门参数标识 string strDept = Request["fdept"]; if (strDept != null && strDept.Length > 0) { //设置默认用户提供的首部门 tb.Text = strDept; } else { //当前用户所在部门id byte deptId = Convert.ToByte(Session["dept_id"]); //从数据库中获取PMC的下个部门 using (var da = new t_deptTableAdapter()) using (var tab = da.GetDataByDeptId(deptId)) { //检查是否存在数据 if (tab.Rows.Count > 0) { var row = tab.Rows[0] as DataSetDept.t_deptRow; //设置到文本框 if (!row.Isnext_dept_nameNull()) { tb.Text = row.next_dept_name; } } } } } } //当前订单序号获取焦点 var txtOrderId = (TextBox)fvLotCardMgrAdd.FindControl("txtOrderId"); if (txtOrderId != null) { //设置焦点 txtOrderId.Focus(); } }
protected void fvLotCardMgrAdd_ModeChanged(object sender, EventArgs e) { //检测是否含有session if (Session.Count < 5) { //跳转 Response.Redirect("/Account/Login", true); //停止加载后续内容 Response.End(); //直接返回 return; } //当前用户所在部门 string deptName = Session["dept_name"].ToString(); //当前角色id Int16 roleId = Convert.ToInt16(Session["role_id"]); //当前状态 if (fvLotCardMgrAdd.CurrentMode != FormViewMode.ReadOnly) { //检测是否有权限 if (deptName != mustDeptName || roleId < 0 || (roleId > 4 && roleId != 6)) { //跳转页面到查看状态 fvLotCardMgrAdd.ChangeMode(FormViewMode.ReadOnly); //将当前formview的状态显示到formview属性中 fvLotCardMgrAdd.Attributes.Add("state", "查看"); //不执行后续语句 return; } } //修改状态 string str = "错误"; //当前模式修改就要执行相关js过程使模态窗口的标题产生变化 switch (fvLotCardMgrAdd.CurrentMode) { case FormViewMode.Edit: //修改状态 //检查用户提供的操作参数标识 string strId = Request["id"]; //转换后的id号 Int64 id; //标题加入id号 if (Int64.TryParse(strId, out id)) { str = "修改 - " + id.ToString(); } break; case FormViewMode.Insert: //新增状态 str = "新增"; //设置初始值 using (var da = new t_ppc_lot_cardTableAdapter()) { //取得最大一张卡号 string lastLotId = da.GetLastLotId().ToString(); //检测卡号 if (lastLotId.Length <= 6) { lastLotId = DateTime.Now.ToString("yyMM-1"); } else { lastLotId = lastLotId.Substring(0, 5) + (int.Parse(lastLotId.Substring(5)) + 1); } //设置值 ((TextBox)fvLotCardMgrAdd.FindControl("txtLotIdStart")).Text = lastLotId; } break; case FormViewMode.ReadOnly: //查看状态 //检查用户提供的操作参数标识 strId = Request["id"]; //标题加入id号 if (Int64.TryParse(strId, out id)) { str = "查看 - " + id.ToString(); } //检测是否有权限 if (deptName != mustDeptName || roleId < 0 || (roleId > 4 && roleId != 6)) { //设置删除按钮不可用 var tb = (Button)fvLotCardMgrAdd.FindControl("btnDelete"); if (tb != null) { tb.Enabled = false; } //设置添加按钮不可用 tb = (Button)fvLotCardMgrAdd.FindControl("btnAdd"); if (tb != null) { tb.Enabled = false; } //设置编辑按钮不可用 tb = (Button)fvLotCardMgrAdd.FindControl("btnEdit"); if (tb != null) { tb.Enabled = false; } } break; } //将当前formview的状态显示到formview属性中 fvLotCardMgrAdd.Attributes.Add("data-yd-state", str); }
/// <summary> /// 保存多条lot卡开卡记录数据到数据库 /// </summary> /// <param name="e">传入的带有数据的事件参数</param> /// <returns></returns> private bool InsertData(FormViewInsertEventArgs e) { //当前用户输入的lot卡号 string strLotIdBegin = e.Values["lot_id"].ToString(); //正则表达式 string strReg = @"^[1-9]\d(0[1-9]|1[012])-[1-9]\d{0,4}"; //检测是否正确lot卡号 if (!Regex.IsMatch(strLotIdBegin, strReg)) { //非数字返回失败 throw new Exception("您输入了一个不合格的结束lot卡号 " + strLotIdBegin + " !"); } //数据适配器 //当前添加语句对象 //当前数据库连接 using (var da = new t_ppc_lot_cardTableAdapter()) using (var daOrder = new t_pmc_orderTableAdapter()) using (var daBalance = new t_dept_lot_card_balanceTableAdapter()) using (var conn = da.Connection) { //打开数据库连接 conn.Open(); //设置数据库连接 daOrder.Connection = daBalance.Connection = conn; //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 daOrder.Transaction = da.Transaction = daBalance.Transaction = tran; //试运行 try { //订单序号 string orderId = ((TextBox)fvLotCardMgrAdd.FindControl("txtOrderId")).Text; //取得生产编号 string productNum = daOrder.GetProductNumByOrderId(orderId).ToString(); //lot卡中的年份月份和数字索引号 string strYearMonth = strLotIdBegin.Substring(0, 5); int iLotId = int.Parse(strLotIdBegin.Substring(5)); //每卡开多少pnl Int16 iEveryCardPnlQty = Int16.Parse(((TextBox)fvLotCardMgrAdd.FindControl("txtEveryCardPnlQty")).Text); //是否补料单 bool isSupplement = Convert.ToBoolean(e.Values["is_supplement"]); //首部门 string firstDeptName = ((TextBox)fvLotCardMgrAdd.FindControl("txtFirstDeptName")).Text; //备注 string remark = e.Values["remark"].ToString(); //录入员 string addPerson = e.Values["add_person"].ToString(); //录入时间 DateTime addTime = Convert.ToDateTime(e.Values["add_time"]); //录入时间 DateTime lastChangeTime = Convert.ToDateTime(e.Values["last_change_time"]); //遍历pnl数 foreach (var item in new string[] { "A", "B", "C", "D" }) { //pnl开料数 string pnlQty = ((TextBox)fvLotCardMgrAdd.FindControl("txtPnlQty" + item)).Text; if (pnlQty.Length <= 0) { continue; } int iPnlQty = int.Parse(pnlQty); //pnl长 Int16 iPnlLength = Int16.Parse(((TextBox)fvLotCardMgrAdd.FindControl("txtPnlLength" + item)).Text); //pnl宽 Int16 iPnlWidth = Int16.Parse(((TextBox)fvLotCardMgrAdd.FindControl("txtPnlWidth" + item)).Text); //pnl含pcs数 Int16 iPnlCountPcs = Int16.Parse(((TextBox)fvLotCardMgrAdd.FindControl("txtPnlCountPcs" + item)).Text); //开卡数 int iCountCard = iPnlQty / iEveryCardPnlQty; //尾卡数量太多,卡数+1 if (iPnlQty - iCountCard * iEveryCardPnlQty >= iEveryCardPnlQty * 0.5) { iCountCard++; } //开卡数至少一张 if (iCountCard <= 0) { iCountCard = 1; } //lot卡逐个往数据库填写 for (int i = iLotId; i < iLotId + iCountCard; i++) { //当前lot卡号 string lotId = strYearMonth + i; //当前卡开pnl数 Int16 iPnlQtyThis = i == iLotId + iCountCard - 1 ? (Int16)(iPnlQty - (iCountCard - 1) * iEveryCardPnlQty) : iEveryCardPnlQty; //写入当前lot卡 if (da.Insert( orderId, lotId, isSupplement, iPnlLength, iPnlWidth, iPnlCountPcs, iPnlQtyThis, firstDeptName, remark, addPerson, addTime, lastChangeTime ) <= 0) { //返回失败 throw new Exception(string.Format("插入lot卡 {0} 到数据库失败!", lotId)); } //写入部门结存 if (daBalance.Insert( "计划", firstDeptName, lotId, productNum, iPnlQtyThis, 0, null, true, addPerson, addTime, lastChangeTime ) <= 0) { //返回失败 throw new Exception(string.Format("插入lot卡 {0} 到部门结存失败!", lotId)); } } //当前iLotId iLotId = iLotId + iCountCard; } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //非数字返回失败 throw new Exception(ex.Message); } } } }
/// <summary> /// 删除指定的批量卡 /// </summary> /// <param name="id">当前要删除的序号</param> /// <returns></returns> internal static bool DeleteLotCardRecordById(Int64 id) { //当前要删除的批量卡序号 string strLotId; //实例化数据适配器 using (var da = new t_ppc_lot_cardTableAdapter()) using (var tab = da.GetDataById(id)) { //检查有无此序号 if (tab.Rows.Count > 0) { //首行 var row = (DataSetPpcLotCardMgr.t_ppc_lot_cardRow)tab.Rows[0]; //获取批量卡序号 strLotId = row.lot_id; } else { throw new Exception("未找到指定的批量卡,可能已经被其他用户删除,请刷新后重试!"); } } //保存数据到部门批量卡记录中的sql添加语句 string sqlstr = "DELETE FROM [t_proc_lot_card_balance] WHERE [lot_id]=@lotId"; //数据适配器 //当前数据库连接 //当前更新语句对象 using (var da = new t_ppc_lot_cardTableAdapter()) using (var conn = da.Connection) using (var cmd = da.Adapter.DeleteCommand) using (var cmdProc = new SqlCommand(sqlstr, conn)) { //打开数据库连接 conn.Open(); //开启事务 using (var tran = conn.BeginTransaction()) { //设置事务 da.Transaction = tran; cmdProc.Transaction = tran; //试运行 try { //设置参数 cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Original_id", id); //执行从ppc所开批量卡中删除 cmd.ExecuteNonQuery(); //设置参数 cmdProc.Parameters.Clear(); cmdProc.Parameters.AddWithValue("@lotId", strLotId); //执行从部门结余批量卡中删除 cmdProc.ExecuteNonQuery(); //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw new Exception(ex.Message); } } } }