• mes 入库单号 锁表方案


     

    1. 提取单别

    create table z_doctype as

    select distinct substr(INSTRUCTION_NUM, 0, 3) doctype from Z_INSTRUCTION_DOC where INSTRUCTION_NUM not like 'PP%'

     

    单别表结构

     

    程序优化方案如下:

    me 入库单 优化-防止多人入库取到同一个单号方案

    1. 原本取下一个单号的逻辑不变
    2. 在取原本取下一个单号前加一个 锁表逻辑  执行语句

                      select * from Z_DOCTYPE where DOCTYPE='单据前缀' for update nowait

    1. 上面的行锁 会随着  事物的  提交而自动解锁,无需其他代码

     

    取最大单号表sql

    select nvl2(max(INSTRUCTION_NUM),

    'AGK' || to_char(sysdate, 'yyyymmdd') || substr( '0000'|| to_char(to_number(substr(max(INSTRUCTION_NUM), -4)) + 1),-4),

    'AGK' || to_char(sysdate, 'yyyymmdd') || '0001'

    )

    from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like 'AGK' || to_char(sysdate, 'yyyymmdd') || '%';

     

    select max(INSTRUCTION_NUM) from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like 'AGK' || to_char(sysdate, 'yyyymmdd') || '%'

     

     

    c# 技术验证代码

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

     

    namespace 取单号锁表测试

    {

    public partial class Form1 : Form

    {

    string constring = @"Data Source=10.8.1.132:1521/MP1;User Id=wipdba;Password=Init1234";

    FluentData.IDbContext db = null;

     

    public Form1()

    {

    InitializeComponent();

    }

     

    private void Form1_Load(object sender, EventArgs e)

    {

    db = new FluentData.DbContext().ConnectionString(constring, new FluentData.OracleProvider(), "Oracle.ManagedDataAccess.Client");

     

    string sqlString = "select DOCTYPE from Z_DOCTYPE t";

    List<string> doctype = db.Sql(sqlString).QueryMany<string>();

    comboBox1.DataSource = doctype;

     

     

    }

     

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

     

    string sqlString = "select max(INSTRUCTION_NUM) from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '%'";

    string x = db.Sql(sqlString).QuerySingle<string>();

     

    textBox2.Text = x;

    }

     

    private void button1_Click(object sender, EventArgs e)

    {

    try

    {

    textBox1.Text = "";

    db.UseTransaction(true);

    string sqlString = "select * from Z_DOCTYPE where DOCTYPE='" + comboBox1.Text + "' for update nowait ";

    db.Sql(sqlString).Execute();

     

     

     

    sqlString = "select nvl2(max(INSTRUCTION_NUM), " +

    " '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || substr( '0000'|| to_char(to_number(substr(max(INSTRUCTION_NUM), -4)) + 1),-4), " +

    " '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '0001' " +

    " ) " +

    "from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '%'";

     

    textBox1.Text = db.Sql(sqlString).QuerySingle<string>();

     

     

    }

    catch (Exception ex)

    {

    db.Rollback();

    MessageBox.Show(ex.Message);

    }

     

    }

     

    private void button2_Click(object sender, EventArgs e)

    {

    try

    {

    db.Commit();

    MessageBox.Show("ok");

    }

    catch (Exception ex)

    {

     

    MessageBox.Show(ex.Message);

    }

    }

    }

    }

     

     

  • 相关阅读:
    beta阶段贡献分配实施
    Beta发布
    Beta发布——视频博客
    Scrum立会报告+燃尽图(Beta阶段第二周第七次)
    Beta发布——美工+文案
    Scrum立会报告+燃尽图(Beta阶段第二周第六次)
    Scrum立会报告+燃尽图(Beta阶段第二周第五次)
    Scrum立会报告+燃尽图(Beta阶段第二周第四次)
    Scrum立会报告+燃尽图(Beta阶段第二周第三次)
    20181011-1每周例行报告
  • 原文地址:https://www.cnblogs.com/hlm750908/p/14415647.html
Copyright © 2020-2023  润新知