2012-12-01 36 views
1

我正在爲珠寶店創建庫存管理應用程序。我已完成沒有條形碼的庫存添加和銷售。現在他們希望我將它與條形碼結合起來。條碼庫存管理

當我加入高湯,條形碼應印像這樣: enter image description here

和我提出的條目是像這樣:

enter image description here

而且只要我打的保存按鈕股票將被添加到數據庫。我如何編寫條形碼的代碼才能打印?

我使用到現在該代碼是在這裏:

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); 
    } 
} 

我只是需要幫助來獲取條碼的打印輸出,使他們能夠對自己的物品貼條碼。他們會有條碼打印機。

回答

0

拉維,

您可以顯示一個表單上的條形碼,並使用打印窗體技術,打印出條形碼!

見下面的鏈接:
Printing Windows Form in C#
Print Forms C# without API
MSDN: How to Print Windows Form

UPDATE:
這些鏈接可以幫助過:
What's the best way to get the default printer in .NET
How do I set the windows default printer in C#?

+0

你確信這將b公關在條形碼打印機中以我上面顯示的格式輸入..>? –

+0

@RaviSharma一旦生成的條形碼只是一個圖像,您可能需要設置圖像大小以適應條形碼打印機的需要......但是當您打印表單時,您將擁有完全的靈活性,並且您可以輕鬆玩耍! –

+0

所以你的意思是說,我會製作一個沒有邊框或標題欄的表單,然後它會詢問用戶有關打印機,然後他們會選擇正確的條形碼打印機,從中打印出來。因爲那裏有多臺打印機,比如一臺打印機,一臺用於報告,另一臺用於條形碼。 –