Example #1
0
 /// <summary>
 /// 执行删除数据并处理相关数据一致性
 /// </summary>
 /// <param name="e">传入的带有数据的事件参数</param>
 /// <returns></returns>
 private bool DeleteData(ListViewDeleteEventArgs e)
 {
     //实例化数据适配器
     using (var da = new v_mantissa_lot_card_loseTableAdapter())
     //取得数据库连接
     using (var conn = da.Connection)
     {
         //打开数据库连接
         conn.Open();
         //事务
         using (var tran = conn.BeginTransaction())
         {
             //设置事务
             da.Transaction = tran;
             try
             {
                 //当前盘亏单号
                 string billNum = e.Keys[0].ToString();
                 //当前行号
                 byte rowId = Convert.ToByte(e.Keys[1]);
                 //取得该条盘亏单清单记录
                 var tab = da.GetDataByBillNumAndRowId(billNum, rowId);
                 //检测是否存在数据
                 if (tab.Rows.Count <= 0)
                 {
                     throw new Exception(
                         string.Format(
                             "当前单据:\n单号:{0}\n行号:{1}\n已经被其他用户删除!",
                             billNum,
                             rowId
                         )
                     );
                 }
                 //单据内容、尾数结存和已入库结存数据适配器
                 using (var daContent = new t_mantissa_lot_card_lose_contentTableAdapter())
                 using (var daBalance = new t_mantissa_lot_card_balanceTableAdapter())
                 {
                     //设置连接对象
                     daContent.Connection = daBalance.Connection = tran.Connection;
                     //设置事务
                     daContent.Transaction = daBalance.Transaction = tran;
                     //遍历行执行删除各行的结存记录和写回已入库结存记录
                     foreach (DataSetMantissaLose.v_mantissa_lot_card_loseRow row in tab.Rows)
                     {
                         //执行插入到尾数结存清单
                         daBalance.InsertData(
                             row.prev_proc_name,
                             row.proc_name,
                             row.lot_id,
                             row.product_num,
                             row.pnl_qty,
                             row.pcs_qty,
                             "尾数盘亏单写回" + (row.IsremarkNull() ? string.Empty : ":" + row.remark),
                             Session["user_name"].ToString()
                         );
                     }
                     //根据盘亏单号和行号删除盘亏记录
                     daContent.Delete(billNum, rowId);
                     //检测当前盘亏记录内容行数
                     int? iCount = daContent.CountByBillNum(billNum);
                     if (iCount.HasValue && iCount.Value <= 0)
                     {
                         //表头适配器
                         using (var daHead = new t_mantissa_lot_card_lose_headTableAdapter())
                         {
                             //删除表头
                             daHead.Delete(billNum);
                         }
                     }
                 }
                 //提交事务
                 tran.Commit();
                 //返回成功
                 return true;
             }
             catch (Exception ex)
             {
                 //回滚事务
                 tran.Rollback();
                 //抛出错误
                 throw new Exception("删除尾数盘亏单记录出现错误:\n" + ex.Message);
             }
         }
     }
 }
Example #2
0
 protected void fvMantissaBackAdd_DataBound(object sender, EventArgs e)
 {
     //设置单据清单可见
     tabDataListSon.Visible = true;
     //清空盘盈单内容清单
     for (int i = 0; i < 10; i++)
     {
         //清空清单数据到控件
         ClearBillContent(i);
     }
     //新增状态
     switch (fvMantissaBackAdd.CurrentMode)
     {
         //新增状态
         case FormViewMode.Insert:
             //当前单号文本框
             var tb = (TextBox)fvMantissaBackAdd.FindControl("txtBillDate");
             if (tb != null)
             {
                 //检查用户提供的单据日期参数标识
                 string strBillDate = Request["bdate"];
                 DateTime billDate;
                 if (strBillDate != null && strBillDate.Length > 0 &&
                     DateTime.TryParse(strBillDate, out billDate))
                 {
                     //设置默认单据日期为传入的日期
                     tb.Text = billDate.ToString("yyyy-MM-dd");
                 }
                 else
                 {
                     //设置默认单据日期为当前日期
                     tb.Text = DateTime.Now.ToString("yyyy-MM-dd");
                 }
             }
             //当前单号文本框
             tb = (TextBox)fvMantissaBackAdd.FindControl("txtBillNum");
             if (tb != null)
             {
                 //户提供的单号参数标识
                 string strBillNum = Request["bnum"];
                 Int64 billNum;
                 if (strBillNum != null && strBillNum.Trim().Length >= 12 &&
                     Int64.TryParse(strBillNum, out billNum))
                 {
                     //设置默认单号为传入的单号加1
                     tb.Text = (billNum + 1).ToString();
                 }
                 else
                 {
                     //当前单号前缀字符串
                     string billNumPrefix = DateTime.Now.ToString("yyyyMMdd");
                     //数据适配器
                     using (var da = new t_mantissa_lot_card_back_headTableAdapter())
                     {
                         //获取已经使用的最大单号
                         string maxBillNum = da.GetMaxBillNumLikeBillNum(billNumPrefix + "%").ToString();
                         //检测取得的值
                         if (maxBillNum.Trim().Length < 12)
                         {
                             //执行转换
                             billNum = Int64.Parse(billNumPrefix + "0001");
                             //设置默认单号为传入的单号加1
                             tb.Text = billNum.ToString();
                         }
                         else
                         {
                             //执行转换
                             billNum = Int64.Parse(maxBillNum);
                             //设置默认单号为传入的单号加1
                             tb.Text = (billNum + 1).ToString();
                         }
                     }
                 }
             }
             //当前部门名称
             var lit = (Literal)fvMantissaBackAdd.FindControl("litProcName");
             if (lit != null)
             {
                 //session中保存的当前部门
                 string procName = Session["proc_name"].ToString();
                 //写入到客户端
                 lit.Text = procName;
             }
             //获取是否传入了多个盘亏表的id值
             string strIdAll = Request["ids"];
             if (strIdAll != null && strIdAll.Trim().Length > 0)
             {
                 //分解出id号
                 string[] strIds = strIdAll.Split(new char[] { '|' }, 10, StringSplitOptions.RemoveEmptyEntries);
                 //检测id号数量
                 if (strIds.Length > 0)
                 {
                     //盘亏表数据适配器
                     using (var da = new v_mantissa_lot_card_loseTableAdapter())
                     {
                         //当前子表行索引
                         int iRow = 0;
                         //逐行获取数据
                         foreach (var strId in strIds)
                         {
                             //继续分解取得送货单号和行号
                             string[] strBillNumAndRowId =
                                 strId.Split(new char[] { '-' }, 2, StringSplitOptions.RemoveEmptyEntries);
                             //检测取得的分解出来的参数数量
                             if (strBillNumAndRowId.Length < 2)
                             {
                                 continue;
                             }
                             //检测单号和行号是否符合规则
                             Int64 billNum;
                             byte rowId;
                             if (Int64.TryParse(strBillNumAndRowId[0], out billNum) && billNum > 0 &&
                                 byte.TryParse(strBillNumAndRowId[1], out rowId) && rowId >= 1 && rowId <= 10
                             )
                             {
                                 //取得数据
                                 var tab = da.GetDataByBillNumAndRowId(billNum.ToString(), rowId);
                                 //检测有无数据
                                 if (tab.Rows.Count > 0)
                                 {
                                     //首行数据
                                     var row = (DataSetMantissaLose.v_mantissa_lot_card_loseRow)tab.Rows[0];
                                     //写入清单数据到控件
                                     SetBillContent(row, iRow);
                                     //行号加1
                                     iRow++;
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         case FormViewMode.Edit:
         case FormViewMode.ReadOnly:
             //设置单据清单不可见
             tabDataListSon.Visible = false;
             //通过盘盈单号获取数据清单
             //取得传入的盘盈单号
             string billNum2 = Request["bnum"];
             if (billNum2 != null && billNum2.Length > 0)
             {
                 //获取清单
                 using (var daContent = new t_mantissa_lot_card_back_contentTableAdapter())
                 {
                     //获取数据
                     var tabContent = daContent.GetDataByBillNum(billNum2);
                     //检测是否找到数据
                     if (tabContent.Rows.Count > 0)
                     {
                         //设置单据清单可见
                         tabDataListSon.Visible = true;
                         //把内容写入页面
                         foreach (DataSetMantissaBack.t_mantissa_lot_card_back_contentRow row in tabContent.Rows)
                         {
                             //当前行号
                             int i = row.row_id - 1;
                             //写入清单数据到控件
                             SetBillContent(row, i);
                         }
                     }
                 }
             }
             break;
     }
     //当前批量卡号文本框获取焦点
     var tb2 = (TextBox)fvMantissaBackAdd.FindControl("txtLotId0");
     if (tb2 != null)
     {
         //设置焦点
         tb2.Focus();
     }
 }