【问题标题】:Barcode stock management条码库存管理
【发布时间】:2012-11-19 09:11:51
【问题描述】:

我正在为一家珠宝店创建一个库存管理应用程序。我已经完成了没有条形码的库存的添加和销售。现在他们希望我将其与条形码集成。

当我添加库存时,应该像这样打印条形码:

我正在做的条目是这样的:

只要我点击保存按钮,股票就会被添加到数据库中。如何为条形码编写代码以使其打印?

我现在使用的代码在这里:

    public partial class FrmAddNewItem : Form
{
    public static bool isEditMode = false;
    private void btnReset_Click(object sender, EventArgs e)
    {
        addComboItems();
        Utility.resetForm(groupBox1);
        isEditMode = false;
        btnStartInvoice.Enabled = true;
        btnSave.Text = "Save";
        generateBarCode();
    }

    private void generateBarCode()
    {
        Random random = new Random();
        String barCode = random.Next(1000000000, int.MaxValue).ToString();
        String strCmd = "select itemCode from tblItemDetail where itemCode='" + barCode + "'";
        while (DBUtil.isRecordExist(strCmd))
        {
            barCode = random.Next(1000000000, int.MaxValue).ToString();
            strCmd = "select itemCode from tblItemDetail where itemCode='" + barCode + "'";
        }
        txtBarCode.Text = barCode;
        lblBarCode.Text = barCode;
        lblBarCode.Font = new Font("Barcode Font", 48);
    }

    private void addComboItems()
    {
        cmboMakingType.Items.Clear();
        cmboStoneRateType.Items.Clear();
        cmboVendorName.Items.Clear();
        cmboVendorId.Items.Clear();

        cmboMakingType.Items.Add(Constants.COMBO_DEFAULT);
        cmboStoneRateType.Items.Add(Constants.COMBO_DEFAULT);
        cmboVendorName.Items.Add(Constants.COMBO_DEFAULT);
        cmboVendorId.Items.Add(Constants.COMBO_DEFAULT);

        cmboMakingType.Items.Add("Pc");
        cmboMakingType.Items.Add("Gm");
        cmboMakingType.Items.Add("Tot");

        cmboStoneRateType.Items.Add("Ct");
        cmboStoneRateType.Items.Add("Pc");
        cmboStoneRateType.Items.Add("Tot");

        String strCmd = "select fullName from tblMemberDetail where isActive='TRUE' and ucase(memberType)='VENDOR'";
        String[] strVendorsName = DBUtil.getAllRecords(strCmd);
        strCmd = "select memberId from tblMemberDetail where isActive='TRUE' and ucase(memberType)='VENDOR'";
        String[] strVendorsId = DBUtil.getAllRecords(strCmd);
        if (strVendorsName != null)
        {
            foreach (String strName in strVendorsName)
                cmboVendorName.Items.Add(strName);
            foreach (String strId in strVendorsId)
                cmboVendorId.Items.Add(strId);
        }
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        String strMsg = "";
        if (txtItemCode.Text.Trim() == "")
        {
            strMsg = "Please enter the Item Code of the item to be added. And please try again.";
            MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }
        String strCmd = "select itemName from tblItemCodeDetail where itemCode='" + txtItemCode.Text + "'";
        strMsg = "";
        if (!DBUtil.isRecordExist(strCmd))
        {
            strMsg = "Item code does not exist. Please enter a valid item code and try again.";
            MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            txtItemCode.SelectAll();
            txtItemCode.Focus();
            return;
        }
        foreach (Control ctrl in groupBox1.Controls)
        {
            if (ctrl is TextBox && ctrl.Text == "")
                ctrl.Text = "0";
        }
        if (cmboMakingType.SelectedIndex == 0 || cmboStoneRateType.SelectedIndex == 0)
        {
            strMsg = "Please select the making type and the stone rate type from the dropdown menu.";
            MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }
        if (cmboVendorName.SelectedIndex == 0)
        {
            strMsg = "Please select the vendor from whom you are purchasing this item.";
            MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            cmboVendorName.Focus();
            return;
        }
        strMsg = "Are you sure all the details provided are correct and you want to add/update this item to the stock?";
        if (MessageBox.Show(strMsg, "Add / Update New Item", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            return;
        if (isEditMode)
            doUpdate();
        else
            doAdding();
        btnReset_Click(null, null);
    }

    private void doUpdate()
    {
        String[] commands = { "update tblItemDetail set originalTunch='" + txtOriginalTunch.Text + "', purchaseTunch='" + txtPurchaseTunch.Text + "', itemCode='" + txtItemCode.Text + "', grossWeight='" + txtGrossWeight.Text + "', making='" + txtMaking.Text + "', makingType='" + cmboMakingType.Text + "', quantity='" + txtPieces.Text + "', stoneWeight='" + txtStoneWeight.Text + "', stoneRate='" + txtStoneRate.Text + "', stoneRateType='" + cmboStoneRateType.Text + "', stoneQuantity='" + txtStonePieces.Text + "', vendorId='" + cmboVendorId.Text + "', purchaseRate='" + txtPurchaseRate.Text + "', 'TRUE', 'NONE')" };
        String strMsg = "";
        if (!DBUtil.executeCommands(commands))
        {
            strMsg = "There occured some error while updating existing item to the stock. Please re-check all the details and try again later.\nIf the problem persists please contact service provider.";
            MessageBox.Show(strMsg, "Update existing Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }
        strMsg = "Item updated successfully to the stock.";
        MessageBox.Show(strMsg, "Update existing Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void doAdding()
    {
        String[] commands = { "Insert into tblItemDetail values('" + txtBarCode.Text + "', '" + txtOriginalTunch.Text + "', '" + txtPurchaseTunch.Text + "', '" + txtItemCode.Text + "', '" + txtGrossWeight.Text + "', '" + txtMaking.Text + "', '" + cmboMakingType.Text + "', '" + txtPieces.Text + "', '" + txtStoneWeight.Text + "', '" + txtStoneRate.Text + "', '" + cmboStoneRateType.Text + "', '" + txtStonePieces.Text + "', '" + cmboVendorId.Text + "', '" + txtPurchaseRate.Text + "', 'TRUE', 'NONE', '" + invoiceNumber + "', '" + invoiceDate + "')" };
        String strMsg = "";
        if (!DBUtil.executeCommands(commands))
        {
            strMsg = "There occured some error while adding new item to the stock. Please re-check all the details and try again later.\nIf the problem persists please contact service provider.";
            MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }
        strMsg = "New Item added successfully to the stock.";
        MessageBox.Show(strMsg, "Add New Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void FrmAddNewItem_Load(object sender, EventArgs e)
    {
        btnReset_Click(sender, e);
    }
}

我只需要帮助打印该条形码,以便他们可以将该条形码粘贴在他们的物品上。他们将有条码打印机。

【问题讨论】:

    标签: c# barcode barcode-printing


    【解决方案1】:

    拉维,

    您可以在表格上显示条形码,并使用 Print Form 技术打印出条形码!

    见以下链接:
    Printing Windows Form in C#
    Print Forms C# without API
    MSDN: How to Print Windows Form

    更新:
    这些链接也可能有帮助:
    What's the best way to get the default printer in .NET
    How do I set the windows default printer in C#?

    【讨论】:

    • 你确定它会以我上面显示的格式在条码打印机上打印出来吗..>?
    • @RaviSharma 条码一旦生成只是一个图像,您可能需要设置图像大小以适合条码打印机的需要......但是当您打印表格时,您将拥有完全的灵活性,您可以轻松玩!
    • 所以你的意思是说我将制作一个没有边框或标题栏的表单.. 然后它会询问用户打印机,然后他们会选择正确的条形码打印机打印带走。因为当然会有不止一台打印机,比如一台用于计费,一台用于报告,一台用于条码..
    • 是的,你想自动化这个过程而不让用户选择打印机吗?
    • M 的意思是,如果添加的每个项目都会自动检测正确的打印机,那就太好了,因为每次都要求打印机对用户来说会有点不舒服。我认为
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多