如何创建唯一代码发票的最佳方式

问题描述 投票:0回答:1

我学会了使用组合框中的值来填充文本框来创建代码发票。

这是我的代码

    string GenerateCode()
    {
        int plus = 1;
        string no = "0000";
        string front = no + plus;
        string mid = sCode;
        string last = DateTime.Now.ToString("/MM/yyyy");
        string fullcode = front.Substring(front.Length-4,4)+ "/" + mid + last;

        if(tDAL.CheckCode (fullcode))
        {
            plus = plus + 1;
            front = no + plus;
            fullcode = front.Substring(front.Length - 4, 4)+"/"+ mid + last;

        }
        return fullcode;
    }

这是我的代码,用于显示创建的代码

tb_invoice.text = fullcode;

这是我的form_load

private void PurchaseandSalesFm_Load(object sender, EventArgs e)
        {
            LoadCode();
            tb_invoice.Text = GenerateCode();
        }

这是迄今为止的结果

输出:0001 / XXL-35/02/2019

对我有什么建议吗?还是更好的代码?因为我仍然对我的代码有疑问而且还在寻找将月份数字改为罗马字母的方法

对不起,如果我要求很多,但我真的很感谢你的帮助。

c#
1个回答
0
投票

Trt在DataSource之后设置了ValueMember

    cb_codetrans.DisplayMember = "title";
    cb_codetrans.ValueMember = "title"; 
    cb_codetrans.DataSource = codetransDT;

这是因为设置DataSource将触发SelectedIndexChanged事件。

© www.soinside.com 2019 - 2024. All rights reserved.