自动生成单据号

来源:互联网 发布:怎么在淘宝买便宜东西 编辑:程序博客网 时间:2024/04/28 17:48
private void Create_Inbound_no()    
        {
            DataSet InNods = new DataSet();
            string inbound_no = "";
            string tempInBound_no = "";
            OracleConnection conn = new OracleConnection(ConnectionString);
            try
            {
                //创建数据提供者 
                OracleDataAdapter daInbound_no = new OracleDataAdapter(String.Format("SELECT INBOUND_NO FROM T_BJ_InBound order by INBOUND_NO"), ConnectionString);
                daInbound_no.Fill(InNods, "T_BJ_InBound");    //填充数据集dataset,并为本次填充的数据起名"T_BJ_info"
                daInbound_no.Dispose();
                int countInbound_no = 0;          
                int countEveryday = 1;       //记录每天的入库单数量,从01-99
                countInbound_no = InNods.Tables[0].Rows.Count;    //入库单号的数量
                if (countInbound_no == 0)
                {
                    inbound_no = "R" + DateTime.Now.ToString("yyMMdd") + countEveryday.ToString("00");
                }
                else
                {
                    tempInBound_no = InNods.Tables["T_BJ_InBound"].Rows[countInbound_no - 1]["INBOUND_NO"].ToString();
                    string memberInBound_1 = tempInBound_no.Substring(0, 7);     
                    string memberInBound_2 = tempInBound_no.Substring(7, 2);    
                    string now_memberInBound_1 = "R" + DateTime.Now.ToString("yyMMdd");
                    if (now_memberInBound_1 != memberInBound_1)
                    {
                        countEveryday = 1;
                        inbound_no = "R" + DateTime.Now.ToString("yyMMdd") + countEveryday.ToString("00");
                    }
                    else
                    {
                        countEveryday = Convert.ToInt16(memberInBound_2);
                        countEveryday++;
                        if (countEveryday > 99)
                        {
                            MessageBox.Show("今日入库单已达最大值!");
                        }
                        else
                        {
                            inbound_no = "R" + DateTime.Now.ToString("yyMMdd") + countEveryday.ToString("00");
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
                conn.Dispose();
                InNods.Dispose();
            }
            txtInBound_no.Text = inbound_no;
        }
原创粉丝点击