using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Swash.Objects;
using Swash.BusinessLayer;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing.Drawing2D;
using System.IO;
using System.Globalization;
using System.Drawing.Text;
namespace Barcodes
{
public partial class frmPrintBarcode : Form
{
List<System.Drawing.Image> imgList = new List<System.Drawing.Image>();
List<barList> Bars = new List<barList>();
//Image img;
class barList
{
public System.Drawing.Image BarcodeImage { get; set; }
public string Barcode { get; set; }
public string GrossWt { get; set; }
public string NetWt { get; set; }
public string Price { get; set; }
public string Grade { get; set; }
public string ItemName { get; set; }
public string StoreName { get; set; }
public string Colour { get; set; }
public string Size { get; set; }
public string StyleNo { get; set; }
public string BrandName { get; set; }
public string GoldCategory { get; set; }
public string SilverPurity { get; set; }
public string SilverCategory { get; set; }
public string Metal { get; set; }
public string ProductCategory { get; set; }
public string ProductType { get; set; }
public int Quantity { get; set; }
public string StoreMRP { get; set; }
public string Color { get; set; }
public string Stone_Name { get; set; }
public string Gold_Purity { get; set; }
public string Product_Type { get; set; }
public string Item_Type_Name { get; set; }
}
private Ean13 ean13 = null;
DataTable dt;
TAGGING_Item obj = new TAGGING_Item();
ERPManagement objdml = new ERPManagement();
static int Total = 0;
static int TotalCopies = 0;
public frmPrintBarcode()
{
InitializeComponent();
}
protected override void WndProc(ref Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
switch (message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
}
base.WndProc(ref message);
}
#region Events
private void frmPrintBarcode_Load(object sender, EventArgs e)
{
try
{
RbtnBarcode.Checked = true;
CmbBrand.Enabled = false;
CmbItemName.Enabled = false;
CmbItemType.Enabled = false;
Fillbrand();
CreateDataTable();
DefaultDropdowns();
}
catch (Exception ex)
{
}
}
private void RbtnBarcode_CheckedChanged(object sender, EventArgs e)
{
try
{
// Reset();
if (RbtnBarcode.Checked == true)
{
TxtBarcode.Enabled = true;
TxtBarcode.Focus();
CmbBrand.SelectedIndex = -1;
CmbBrand.Enabled = false;
CmbItemType.SelectedIndex = -1;
CmbItemName.SelectedIndex = -1;
CmbItemName.Enabled = false;
CmbItemType.Enabled = false;
DgviewBarcode.DataSource = null;
DgviewBarcode.Columns.Clear();
}
}
catch (Exception ex)
{
}
}
private void RbtnBrand_CheckedChanged(object sender, EventArgs e)
{
try
{
// Reset();
if (RbtnBrand.Checked == true)
{
Fillbrand();
DefaultDropdowns();
TxtBarcode.Text = "";
TxtBarcode.Enabled = false;
CmbBrand.Enabled = true;
CmbItemName.Enabled = false;
CmbItemType.Enabled = false;
CmbBrand.Focus();
DgviewBarcode.DataSource = null;
DgviewBarcode.Columns.Clear();
}
}
catch (Exception ex)
{
}
}
private void CmbBrand_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (CmbBrand.SelectedIndex > 0)
{
fillItemType(int.Parse(CmbBrand.SelectedValue.ToString()));
List<TAGGING_PrintBarcode> Listobj = new List<TAGGING_PrintBarcode>();
TAGGING_PrintBarcode Select = new TAGGING_PrintBarcode();
Select.Item_ID = 0;
Select.Item_Name = "Select";
Listobj.Add(Select);
CmbItemName.DataSource = Listobj;
CmbItemName.ValueMember = "Item_ID";
CmbItemName.DisplayMember = "Item_Name";
}
else
{
CmbItemName.Enabled = false;
CmbItemType.Enabled = false;
DefaultDropdowns();
}
DgviewBarcode.Columns[0].Visible = false;
DgviewBarcode.Columns[1].Visible = false;
if (DgviewBarcode.Columns.Contains("Copies"))
{
DgviewBarcode.Columns.Remove("Copies");
}
DgviewBarcode.DataSource = null;
DgviewBarcode.ColumnHeadersVisible = false;// Added
TxtQuantity.Text = "0";
}
catch (Exception ex)
{
}
}
private void CmbItemType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (CmbItemType.SelectedIndex > 0)
{
fillItemName(int.Parse(CmbItemType.SelectedValue.ToString()));
}
else
{
CmbItemName.Enabled = false;
List<TAGGING_PrintBarcode> Listobj = new List<TAGGING_PrintBarcode>();
TAGGING_PrintBarcode Select = new TAGGING_PrintBarcode();
Select.Item_ID = 0;
Select.Item_Name = "Select";
Listobj.Add(Select);
CmbItemName.DataSource = Listobj;
CmbItemName.ValueMember = "Item_ID";
CmbItemName.DisplayMember = "Item_Name";
}
DgviewBarcode.Columns[0].Visible = false;
DgviewBarcode.Columns[1].Visible = false;
if (DgviewBarcode.Columns.Contains("Copies"))
{
DgviewBarcode.Columns.Remove("Copies");
}
DgviewBarcode.DataSource = null;
DgviewBarcode.ColumnHeadersVisible = false; // added
TxtQuantity.Text = "0";
}
catch (Exception ex)
{
}
}
private void BtnSearch_Click(object sender, EventArgs e)
{
try
{
Search();
}
catch (Exception ex)
{
}
}
private void TxtBarcode_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyValue == 13)
{
Search();
}
}
catch (Exception ex)
{
}
}
private void DgviewBarcode_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (checkquantity() == true)
{
int x = 0, j = 0;
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
if (DgviewBarcode.Rows[i].Cells[9].Value != "" && DgviewBarcode.Rows[i].Cells[9].Value != null)
{
j = int.Parse(DgviewBarcode.Rows[i].Cells[9].Value.ToString());
x = x + j;
}
}
TxtQuantity.Text = x.ToString();
}
}
catch (Exception ex)
{
if (ex.Message.Contains("Object reference not set to an instance of an object."))
{
return;
}
}
}
bool checkquantity()
{
bool ReturnValue = false;
try
{
if (DgviewBarcode.Rows.Count > 0)
{
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
int result = 0;
int count = DgviewBarcode.Columns.Count;
// string abc = DgviewBarcode.Rows[i].Cells[6].Value.ToString();
if (DgviewBarcode.Rows[i].Cells[9].Value != null && DgviewBarcode.Rows[i].Cells[9].Value != "")
{
if (int.TryParse(DgviewBarcode.Rows[i].Cells[9].Value.ToString(), out result))
{
if (int.Parse(DgviewBarcode.Rows[i].Cells[9].Value.ToString()) < 0)
{
MessageBox.Show("Copies can't be negative.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
DataGridViewTextBoxCell txt = (DataGridViewTextBoxCell)(DgviewBarcode.Rows[i].Cells[9]);
DgviewBarcode.Rows[i].Cells[9].Value = "";
txt.Selected = true;
ReturnValue = false;
}
else if (int.Parse(DgviewBarcode.Rows[i].Cells[9].Value.ToString()) == 0)
{
MessageBox.Show("Copies can't be zero.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
DataGridViewTextBoxCell txt = (DataGridViewTextBoxCell)(DgviewBarcode.Rows[i].Cells[9]);
DgviewBarcode.Rows[i].Cells[9].Value = "";
txt.Selected = true;
ReturnValue = false;
}
else
{
ReturnValue = true;
}
}
else
{
MessageBox.Show("Enter only integers.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
DgviewBarcode.Rows[i].Cells[9].Value = "";
ReturnValue = false;
}
}
else
{
ReturnValue = true;
}
}
}
}
catch (Exception ex)
{
}
return ReturnValue;
}
private void BtnCancel_Click(object sender, EventArgs e)
{
try
{
Reset();
}
catch (Exception ex)
{
}
}
private void BtnPrintBarcode_Click(object sender, EventArgs e)
{
try
{
if (DgviewBarcode.Rows.Count > 0)
{
SaveBarcode();
}
else
{
MessageBox.Show("No items has been selected.", "Ken Cloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
TxtBarcode.Focus();
return;
}
}
catch (Exception ex)
{
}
}
#endregion
#region Method
void fillItemType(int value)
{
List<TAGGING_PrintBarcode> Listobj = new List<TAGGING_PrintBarcode>();
TAGGING_PrintBarcode Type = new TAGGING_PrintBarcode();
Type.Item_Type_Name = "Select";
Type.Item_Type_ID = 0;
Listobj.Add(Type);
var x = (from m in ERPManagement.GetInstance.GetAllItemBrandDetails()
where m.Brand_ID == value
select m );
var y = (from s in x
select s.Item_Type_ID).Distinct().ToList();
List<int> it=new List<int>();
for(int i=0; i<x.ToList().Count; i++)
{
it.Add(x.ToList()[i].Item_Type_ID);
}
for (int i = 0; i < y.Count(); i++)
{
if (it.Contains(y[i]))
{
var srch= (from t in x
where t.Item_Type_ID == y[i]
select t.Item_Type_Name).Distinct();
TAGGING_PrintBarcode ch=new TAGGING_PrintBarcode();
ch.Item_Type_ID=y[i];
ch.Item_Type_Name = srch.ToList()[0];
//ch.Item_Type_Name=
Listobj.Add(ch);
}
}
//for (int i = 0; i < x.Count(); i++)
//{
// Listobj.Add(x.ToList()[i]);
//}
CmbItemType.DataSource = Listobj;
CmbItemType.DisplayMember = "Item_Type_Name";
CmbItemType.ValueMember = "Item_Type_ID";
CmbItemType.Enabled = true;
}
void fillItemName(int ItemtypeID)
{
List<TAGGING_PrintBarcode> Listobj = new List<TAGGING_PrintBarcode>();
TAGGING_PrintBarcode Select = new TAGGING_PrintBarcode();
Select.Item_ID = 0;
Select.Item_Name = "Select";
Listobj.Add(Select);
var x = from m in ERPManagement.GetInstance.GetAllItemBrandDetails()
where m.Item_Type_ID == ItemtypeID
select m;
for (int i = 0; i < x.Count(); i++)
{
Listobj.Add(x.ToList()[i]);
}
CmbItemName.DataSource = Listobj;
CmbItemName.DisplayMember = "Item_Name";
CmbItemName.ValueMember = "Item_ID";
CmbItemName.Enabled = true;
}
void Reset()
{
TxtBarcode.Text = "";
TxtQuantity.Text = "0";
CmbBrand.SelectedIndex = -1;
CmbBrand.DataSource = null;
CmbItemType.SelectedIndex = -1;
CmbItemType.DataSource = null;
CmbItemName.SelectedIndex = -1;
CmbItemName.DataSource = null;
DgviewBarcode.Columns.Clear();
DgviewBarcode.DataSource = null;
RbtnBrand.Checked = false;
CmbBrand.Enabled = false;
CmbItemType.Enabled = false;
CmbItemName.Enabled = false;
RbtnBarcode.Checked = true;
TxtBarcode.Enabled = true;
}
void Fillbrand()
{
obj.T_Name = "Inventory.MST_Brand";
obj.Vf_Name = "Brand_ID";
obj.Tf_Name = "Brand_Name";
CmbBrand.DataSource = objdml.GetItemData1(obj);
CmbBrand.DisplayMember = "Text";
CmbBrand.ValueMember = "Value";
}
void Search()
{
try
{
List<TAGGING_PrintBarcode> ListobjBarcode = new List<TAGGING_PrintBarcode>();
//ListobjBarcode = ERPManagement.GetInstance.GetAllBarcodeDetails();
ListobjBarcode = ERPManagement.GetInstance.GetAllBarcodeDetailsForPrint();
if (TxtBarcode.Enabled == false)
{
if (CmbBrand.SelectedIndex > 0)
{
// Code to retrive all the records when all combo box are checked
if (CmbItemType.SelectedIndex > 0 && CmbItemName.SelectedIndex > 0)
{
var lnqBarcode = from Barcode in ListobjBarcode
where Barcode.Item_ID == int.Parse(CmbItemName.SelectedValue.ToString())
select Barcode;
if (lnqBarcode.ToList().Count > 0)
{
GenerateGridView(DgviewBarcode, lnqBarcode.ToList());
DgviewBarcode.ColumnHeadersVisible = true;
DgviewBarcode.ScrollBars = ScrollBars.Both;
//if (DgviewBarcode.Rows.Count > 0)
//{
// DgviewBarcode.Rows[0].Cells[6].Selected = true;
//}
}
else
{
DgviewBarcode.DataSource = null;
DgviewBarcode.ColumnHeadersVisible = false;
DgviewBarcode.ScrollBars = ScrollBars.None;
}
}
// end of code to retrive all the records when all combo box are checked
// For Brand and Item type
else if (CmbItemType.SelectedIndex > 0)
{
var lnqBarcode = from Barcode in ListobjBarcode
where Barcode.Item_Type_ID == int.Parse(CmbItemType.SelectedValue.ToString())
&& Barcode.Brand_ID == int.Parse(CmbBrand.SelectedValue.ToString())
select Barcode;
if (lnqBarcode.ToList().Count > 0)
{
GenerateGridView(DgviewBarcode, lnqBarcode.ToList());
DgviewBarcode.ColumnHeadersVisible = true;
DgviewBarcode.ScrollBars = ScrollBars.Both;
}
else
{
DgviewBarcode.ColumnHeadersVisible = false;
DgviewBarcode.DataSource = null;
DgviewBarcode.ScrollBars = ScrollBars.None;
}
}
// end of Brand and Item type
// For only Brand Combo box
else
{
var lnqBarcode = from Barcode in ListobjBarcode
where Barcode.Brand_ID == int.Parse(CmbBrand.SelectedValue.ToString())
select Barcode;
if (lnqBarcode.ToList().Count > 0)
{
GenerateGridView(DgviewBarcode, lnqBarcode.ToList());
DgviewBarcode.ColumnHeadersVisible = true;
DgviewBarcode.ScrollBars = ScrollBars.Both;
}
else
{
DgviewBarcode.ColumnHeadersVisible = false;
DgviewBarcode.DataSource = null;
DgviewBarcode.ScrollBars = ScrollBars.None;
}
}
// end of only Brand
// Old Code get Commented
//if (CmbItemType.SelectedIndex > 0)
//{
// if (CmbItemName.SelectedIndex > 0)
// {
// var lnqBarcode = from Barcode in ListobjBarcode
// where Barcode.Item_ID == int.Parse(CmbItemName.SelectedValue.ToString())
// select Barcode;
// if (lnqBarcode.ToList().Count > 0)
// {
// GenerateGridView(DgviewBarcode, lnqBarcode.ToList());
// //if (DgviewBarcode.Rows.Count > 0)
// //{
// // DgviewBarcode.Rows[0].Cells[6].Selected = true;
// //}
// }
// else
// {
// DgviewBarcode.DataSource = null;
// }
// }
// else
// {
// MessageBox.Show("Select an item name.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// CmbItemName.Focus();
// return;
// }
//}
//else
//{
// MessageBox.Show("Select an item type.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// CmbItemType.Focus();
// return;
//}
// end of Old Code
}
else
{
MessageBox.Show("Select a brand.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CmbBrand.Focus();
return;
}
}
else
{
if (TxtBarcode.Text.Trim() != "")
{
SearchonBarcode();
}
else
{
MessageBox.Show("Enter barcode no.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
TxtBarcode.Focus();
return;
}
}
}
catch (Exception ex)
{
}
}
void GenerateGridView(DataGridView dg, List<TAGGING_PrintBarcode> barcodes)
{
DgviewBarcode.Columns.Clear();
dg.AutoGenerateColumns = false;
DataGridViewCheckBoxColumn check = new DataGridViewCheckBoxColumn();
check.Width = 30;
dg.Columns.Add(check);
DataGridViewTextBoxColumn Barcode = new DataGridViewTextBoxColumn();
Barcode.DataPropertyName = "Barcode";
Barcode.HeaderText = "Barcode";
Barcode.Width = 160;
Barcode.ReadOnly = true;
dg.Columns.Add(Barcode);
DataGridViewTextBoxColumn Brand = new DataGridViewTextBoxColumn();
Brand.DataPropertyName = "Brand_Name";
Brand.HeaderText = "Brand";
Brand.Width = 160;
Brand.ReadOnly = true;
dg.Columns.Add(Brand);
DataGridViewTextBoxColumn ItemTypeName = new DataGridViewTextBoxColumn();
ItemTypeName.DataPropertyName = "Item_Type_Name";
ItemTypeName.HeaderText = "Item Type";
ItemTypeName.Width = 160;
ItemTypeName.ReadOnly = true;
dg.Columns.Add(ItemTypeName);
DataGridViewTextBoxColumn ProductType = new DataGridViewTextBoxColumn();
ProductType.DataPropertyName = "Product_Type";
ProductType.HeaderText = "Product Type";
ProductType.Width = 160;
ProductType.ReadOnly = true;
dg.Columns.Add(ProductType);
DataGridViewTextBoxColumn GrossWt = new DataGridViewTextBoxColumn();
GrossWt.DataPropertyName = "Total_Gross_Weight";
GrossWt.HeaderText = "Gross Wt.";
GrossWt.Width = 100;
GrossWt.ReadOnly = true;
dg.Columns.Add(GrossWt);
DataGridViewTextBoxColumn StoneWt = new DataGridViewTextBoxColumn();
StoneWt.DataPropertyName = "Total_Stone_Weight";
StoneWt.HeaderText = "Stone Wt.";
StoneWt.Width = 100;
StoneWt.ReadOnly = true;
dg.Columns.Add(StoneWt);
DataGridViewTextBoxColumn NetWt = new DataGridViewTextBoxColumn();
NetWt.DataPropertyName = "Total_Net_Weight";
NetWt.HeaderText = "Net Wt.";
NetWt.Width = 100;
NetWt.ReadOnly = true;
dg.Columns.Add(NetWt);
DataGridViewTextBoxColumn StoneColor = new DataGridViewTextBoxColumn();
StoneColor.DataPropertyName = "Stone_Color";
StoneColor.HeaderText = "Stone Color";
StoneColor.Width = 140;
StoneColor.ReadOnly = true;
dg.Columns.Add(StoneColor);
DataGridViewTextBoxColumn Quantity = new DataGridViewTextBoxColumn();
Quantity.HeaderText = "Copies";
Quantity.Width = 140;
Quantity.ReadOnly = false;
//Quantity.DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
dg.Columns.Add(Quantity);
DataGridViewTextBoxColumn MRP = new DataGridViewTextBoxColumn();
MRP.HeaderText = "Price";
MRP.DataPropertyName = "MRP";
MRP.Width = 140;
MRP.ReadOnly = true;
MRP.Visible = false;
dg.Columns.Add(MRP);
DataGridViewTextBoxColumn ItemName = new DataGridViewTextBoxColumn();
ItemName.HeaderText = "Item Name";
ItemName.DataPropertyName = "Item_Name";
ItemName.Width = 140;
ItemName.ReadOnly = true;
ItemName.Visible = false;
dg.Columns.Add(ItemName);
//DataGridViewTextBoxColumn Store = new DataGridViewTextBoxColumn();
//Store.HeaderText = "Store Name";
//Store.DataPropertyName = "StoreName";
//Store.Width = 140;
//Store.ReadOnly = true;
//Store.Visible = false;
//dg.Columns.Add(Store);
DataGridViewTextBoxColumn Purity = new DataGridViewTextBoxColumn();
Purity.HeaderText = "Purity";
Purity.DataPropertyName = "PurityName";
Purity.Width = 140;
Purity.ReadOnly = true;
Purity.Visible = false;
dg.Columns.Add(Purity);
DataGridViewTextBoxColumn StyleNo = new DataGridViewTextBoxColumn();
StyleNo.HeaderText = "Style No";
StyleNo.DataPropertyName = "Style_No";
StyleNo.Width = 140;
StyleNo.ReadOnly = true;
StyleNo.Visible = true;
dg.Columns.Add(StyleNo);
DataGridViewTextBoxColumn Size = new DataGridViewTextBoxColumn();
Size.HeaderText = "Size";
Size.DataPropertyName = "Size";
Size.Width = 140;
Size.ReadOnly = true;
Size.Visible = true;
dg.Columns.Add(Size);
DataGridViewTextBoxColumn SilverPurity = new DataGridViewTextBoxColumn();
SilverPurity.HeaderText = "Silver Purity";
SilverPurity.DataPropertyName = "Silver_Purity_Name";
SilverPurity.Width = 140;
SilverPurity.ReadOnly = true;
SilverPurity.Visible = true;
dg.Columns.Add(SilverPurity);
dg.DataSource = barcodes;
DataGridViewTextBoxColumn StoneName = new DataGridViewTextBoxColumn();
StoneName.HeaderText = "Stone Name";
StoneName.DataPropertyName = "Stone_Name";
StoneName.Width = 140;
StoneName.ReadOnly = true;
StoneName.Visible = true;
dg.Columns.Add(StoneName);
dg.DataSource = barcodes;
DataGridViewTextBoxColumn StoreMRP = new DataGridViewTextBoxColumn();
StoreMRP.HeaderText = "Store MRP";
StoreMRP.DataPropertyName = "Store_MRP";
StoreMRP.Width = 140;
StoreMRP.ReadOnly = true;
StoreMRP.Visible = true;
dg.Columns.Add(StoreMRP);
dg.DataSource = barcodes;
}
void SearchonBarcode()
{
List<TAGGING_PrintBarcode> ListobjBarcode = new List<TAGGING_PrintBarcode>();
ListobjBarcode = ERPManagement.GetInstance.GetAllBarcodeDetailsForPrint();
var lnqBarcode = from Barcode in ListobjBarcode
where Barcode.Barcode == TxtBarcode.Text.Trim()
select Barcode;
if (lnqBarcode.ToList().Count > 0)
{
GenerateGridView(DgviewBarcode, lnqBarcode.ToList());
}
else
{
MessageBox.Show("Wrong Barcode.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Error);
DgviewBarcode.DataSource = null;
DgviewBarcode.Columns[0].Visible = false;
DgviewBarcode.Columns[1].Visible = false;
TxtBarcode.Text = "";
}
}
void SetGrid()
{
}
void CreateDataTable()
{
dt = new DataTable();
dt.Columns.Add("Barcode_Item", typeof(string));
dt.Columns.Add("No_Of_Copies", typeof(int));
}
bool CheckDataTable()
{
bool insert = false;
if (DgviewBarcode.Rows.Count > 0)
{
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
if (DgviewBarcode.Rows[i].Cells[0].Value != null)
{
if ((bool)this.DgviewBarcode.Rows[i].Cells[0].Value == true)
{
if (DgviewBarcode.Rows[i].Cells[9].Value == null)
{
MessageBox.Show(" Enter copies to print.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
insert = false;
}
else
{
insert = true;
}
}
}
}
}
return insert;
}
void InsertDataTable()
{
if (DgviewBarcode.Rows.Count > 0)
{
dt.Clear();
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
if (DgviewBarcode.Rows[i].Cells[0].Value != null)
{
if ((bool)this.DgviewBarcode.Rows[i].Cells[0].Value == true)
{
dt.Rows.Add(DgviewBarcode.Rows[i].Cells[1].Value,
DgviewBarcode.Rows[i].Cells[9].Value);
dt.AcceptChanges();
}
}
}
}
}
int Copyquantity()
{
int m = 0, n = 0;
if (DgviewBarcode.Rows.Count > 0)
{
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
if (DgviewBarcode.Rows[i].Cells[0].Value != null)
{
if ((bool)this.DgviewBarcode.Rows[i].Cells[0].Value == true)
{
if (DgviewBarcode.Rows[i].Cells[9].Value == null)
{
}
else
{
n = int.Parse(DgviewBarcode.Rows[i].Cells[9].Value.ToString());
m = m + n;
}
}
}
}
}
return m;
}
void SaveBarcode()
{
if (TxtQuantity.Text != "0" && TxtQuantity.Text != "")
{
if (CheckDataTable() == true)
{
TotalCopies = Copyquantity();
if (MessageBox.Show("Are you sure to print " + TotalCopies + " no of barcode(s) ?", "kenCloud", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
imgList.Clear();
Bars.Clear();
string Size="";
string GrossWt = "";
string Price = "";
for (int i = 0; i < DgviewBarcode.Rows.Count; i++)
{
if (DgviewBarcode.Rows[i].Cells[9].Value != null)
{
string Barcode = DgviewBarcode.Rows[i].Cells[1].Value.ToString();
string BrandName = DgviewBarcode.Rows[i].Cells[2].Value.ToString();
Total = int.Parse(DgviewBarcode.Rows[i].Cells[9].Value.ToString());
if (DgviewBarcode.Rows[i].Cells[5].Value != null)
{
GrossWt = DgviewBarcode.Rows[i].Cells[5].Value.ToString();
}
string NetWt = DgviewBarcode.Rows[i].Cells[7].Value.ToString();
if (DgviewBarcode.Rows[i].Cells[2].Value.ToString() == "Milaan")
{
Price = DgviewBarcode.Rows[i].Cells[17].Value.ToString();
}
else if (DgviewBarcode.Rows[i].Cells[2].Value.ToString() == "Glizmore")
{
Price = DgviewBarcode.Rows[i].Cells[10].Value.ToString();
}
string ItemName = DgviewBarcode.Rows[i].Cells[11].Value.ToString();
// string StoreName = DgviewBarcode.Rows[i].Cells[9].Value.ToString();
string Colour = DgviewBarcode.Rows[i].Cells[8].Value.ToString();
if (DgviewBarcode.Rows[i].Cells[14].Value != null)
Size = DgviewBarcode.Rows[i].Cells[14].Value.ToString();
string StyleNo = DgviewBarcode.Rows[i].Cells[13].Value.ToString();
string Grade = DgviewBarcode.Rows[i].Cells[12].Value.ToString();
string SilverPurity = DgviewBarcode.Rows[i].Cells[15].Value.ToString();
//string Grade = "22KT";
string GoldCategory = "3%";
string SilverCategory = "97%";
string ProductType = DgviewBarcode.Rows[i].Cells[4].Value.ToString();
string ProductCategory = DgviewBarcode.Rows[i].Cells[3].Value.ToString();
string StoneName = DgviewBarcode.Rows[i].Cells[16].Value.ToString();
//GenerateNewBarcode(Barcode, GrossWt, NetWt, Price, Grade, ItemName,BrandName, Colour, Size, StyleNo, GoldCategory, SilverPurity, SilverCategory);
GenerateListOfItemsToPrint(1, BrandName, NetWt, SilverPurity, ProductType, ProductCategory, StyleNo, Total, GrossWt, "", "", Price, Barcode, "", SilverPurity, Size, Colour, StoneName);
}
}
PrintDialog dig = new PrintDialog();
PrintDocument doc = new TextDocument();
dig.Document = doc;
if (dig.ShowDialog() == DialogResult.OK)
{
if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count <= 0)
{
MessageBox.Show("Printer not found.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
PrintNewBarcode(dig, doc);
//PrintItems(dig, doc);
TAGGING_PrintBarcode printObj = new TAGGING_PrintBarcode();
printObj.Total_Copies = TotalCopies;
InsertDataTable();
printObj.Barcodeprint = dt;
printObj.Created_By = 1;
ERPManagement.GetInstance.InsertBarcodePrintDetails(printObj);
MessageBox.Show("Barcode(s) printed successfully.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Information);
Reset();
}
}
}
}
else
{
MessageBox.Show("Please check the item.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (TxtBarcode.Text == "" && CmbItemName.SelectedValue == null)
{
if (TxtBarcode.Enabled == true)
{
MessageBox.Show("Please enter barcode.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Please select item name.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("Please enter copies to print.", "Kencloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (DgviewBarcode.Rows.Count > 0)
{
// DgviewBarcode.Rows[0].Cells[6].Selected = true;
DgviewBarcode.CurrentCell = DgviewBarcode.Rows[0].Cells[9];
DgviewBarcode.BeginEdit(true);
}
}
}
void DefaultDropdowns()
{
List<TAGGING_PrintBarcode> Listobj = new List<TAGGING_PrintBarcode>();
TAGGING_PrintBarcode Select = new TAGGING_PrintBarcode();
Select.Item_Type_Name = "Select";
Select.Item_Type_ID = 0;
Select.Item_ID = 0;
Select.Item_Name = "Select";
Listobj.Add(Select);
CmbItemType.DataSource = Listobj;
CmbItemType.DisplayMember = "Item_Type_Name";
CmbItemType.ValueMember = "Item_Type_ID";
CmbItemName.DataSource = Listobj;
CmbItemName.ValueMember = "Item_ID";
CmbItemName.DisplayMember = "Item_Name";
}
#endregion
#region Print
//public System.Drawing.Image GenerateBarcode(string Text)
//{
// Barcode128 code128 = new Barcode128();
// code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
// code128.ChecksumText = true;
// code128.GenerateChecksum = true;
// code128.StartStopText = false;
// code128.Code = Text;
// System.Drawing.Bitmap bmpimg = new Bitmap(130, 18);
// Graphics bmpgraphics = Graphics.FromImage(bmpimg);
// bmpgraphics.Clear(Color.White);
// bmpgraphics.DrawImage(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(0, 0));
// //Label_Generic(bmpimg, Text);
// return bmpimg;
//}
class TextDocument : PrintDocument
{
public int PageNumber;
public int Offset;
public TextDocument()
{
}
}
#endregion
#region Dated 17/12/2012
public void GenerateNewBarcode(string Barcode, string GrossWt, string NetWt, string Price, string Grade, string ItemName,string BrandName, string Colour, string Size, string StyleNo, string GoldCategory, string SilverPurity, string SilverCategory)
{
try
{
for (int i = 0; i < Total; i++)
{
System.Drawing.Image GeneratedImg = GenerateBarcode(Barcode);
barList bar = new barList();
bar.Barcode = Barcode;
bar.BarcodeImage = GeneratedImg;
bar.Grade = Grade;
bar.GrossWt = GrossWt;
bar.ItemName = ItemName;
bar.NetWt = NetWt;
bar.Price = Price;
bar.BrandName = BrandName;
bar.Colour = Colour;
bar.Size = Size;
bar.StyleNo = StyleNo;
bar.GoldCategory = GoldCategory;
bar.SilverPurity = SilverPurity;
bar.SilverCategory = SilverCategory;
Bars.Add(bar);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
public void PrintNewBarcode(PrintDialog dig, PrintDocument doc)
{
doc.PrinterSettings.PrinterName = dig.PrinterSettings.PrinterName;
PaperSize paperSize = new PaperSize();
paperSize.RawKind = (int)PaperKind.Custom;
paperSize.Height = 50;
doc.DefaultPageSettings.PaperSize = paperSize;
doc.DefaultPageSettings.Landscape = false;
doc.DefaultPageSettings.Margins = new Margins(4, 1, 0, 1);
doc.PrintPage += this.PrintingBarcode;
doc.Print();
}
private void Doc_NewPrintPage(object sender, PrintPageEventArgs e)
{
//TextDocument doc = (TextDocument)sender;
//System.Drawing.Font font = new System.Drawing.Font("Calibri", 6);
//float lineHeight = 25;
//float x = e.MarginBounds.Left;
//float y = e.MarginBounds.Top;
//float PositionY = 0f;
//doc.PageNumber += 1;
//while ((y + lineHeight) < e.MarginBounds.Bottom && doc.Offset < Bars.Count)
//{
// System.Drawing.Font Newfont = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
// e.Graphics.DrawString(Bars[doc.Offset].ItemName, Newfont, Brushes.Black, x, y);
// e.Graphics.DrawString(Bars[doc.Offset].Ct + "K", Newfont, Brushes.Black, x + 90, y);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Gross Wt.", Newfont, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", Newfont, Brushes.Black, x + 40, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].GrossWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 50, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Net Wt.", Newfont, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", Newfont, Brushes.Black, x + 40, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].NetWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 50, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Price", Newfont, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", Newfont, Brushes.Black, x + 40, PositionY);
// string destfile = Application.StartupPath;
// for (int i = 0; i < 2; i++)
// {
// destfile = destfile.Substring(0, destfile.LastIndexOf("\\"));
// }
// string path = destfile;
// PrivateFontCollection Rupees = new PrivateFontCollection();
// Rupees.AddFontFile(path + "\\Rupee_Foradian.ttf");
// e.Graphics.DrawString("` ", new System.Drawing.Font(Rupees.Families[0], 6, FontStyle.Bold), Brushes.Black, x + 50, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].Price).ToString("N", CultureInfo.CreateSpecificCulture("hi-IN")), Newfont, Brushes.Black, x + 56, PositionY);
// e.Graphics.DrawImage(Bars[doc.Offset].BarcodeImage, x + 134, y);
// e.Graphics.DrawString("Item Code : " + Bars[doc.Offset].Barcode, font, Brushes.Black, x + 134, y + Bars[doc.Offset].BarcodeImage.Height + 1);
// //if (File.Exists(destfile + "\\Resources\\Twitter-icon.png"))
// //{
// // System.Drawing.Image bmp = Bitmap.FromFile(destfile + "\\Resources\\Twitter-icon.png");
// // e.Graphics.DrawImage(bmp, x + 134, y + Bars[doc.Offset].BarcodeImage.Height + 9);
// // e.Graphics.DrawString(Bars[doc.Offset].StoreName, Newfont, Brushes.Black, x + 134 + bmp.Width, y + Bars[doc.Offset].BarcodeImage.Height + 9);
// //}
// e.Graphics.DrawString(Bars[doc.Offset].StoreName, Newfont, Brushes.Black, x + 134, y + Bars[doc.Offset].BarcodeImage.Height + 9);
// doc.Offset += 1;
// y += lineHeight;
//}
//if (doc.Offset < Bars.Count)
//{
// e.HasMorePages = true;
//}
//else
//{
// doc.Offset = 0;
//}
}
private System.Drawing.Image Label_Generic(System.Drawing.Image img, string Data)
{
try
{
System.Drawing.Font font = new System.Drawing.Font("Calibri", 6, FontStyle.Regular);
using (Graphics g = Graphics.FromImage(img))
{
g.DrawImage(img, (float)0, (float)0);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
StringFormat f = new StringFormat();
f.Alignment = StringAlignment.Near;
f.LineAlignment = StringAlignment.Near;
int LabelX = 0;
int LabelY = 0;
LabelX = img.Width / 2;
LabelY = img.Height - (font.Height);
f.Alignment = StringAlignment.Center;
g.FillRectangle(Brushes.White, new RectangleF((float)0, (float)LabelY, (float)img.Width, (float)font.Height));
g.DrawString(Data, font, new SolidBrush(this.ForeColor), new RectangleF((float)0, (float)LabelY + 2, (float)img.Width, (float)font.Height), f);
g.Save();
}
return img;
}
catch (Exception ex)
{
throw new Exception("ELABEL_GENERIC-1: " + ex.Message);
}
}
#endregion
#region Dt 19/01/2012
//private void PrintingBarcode(object sender, PrintPageEventArgs e)
//{
// TextDocument doc = (TextDocument)sender;
// System.Drawing.Font font = new System.Drawing.Font("Calibri", 5);
// System.Drawing.Font fontBold = new System.Drawing.Font("Calibri", 5, FontStyle.Bold);
// float lineHeight = 25;
// float x = e.MarginBounds.Left;
// float y = e.MarginBounds.Top;
// doc.PageNumber += 1;
// string destfile = Application.StartupPath;
// while ((y + lineHeight) < e.MarginBounds.Bottom && doc.Offset < Bars.Count)
// {
// if (Bars[doc.Offset].BrandName == "Milaan")
// {
// float PositionY = 0f;
// System.Drawing.Font Newfont = new System.Drawing.Font("Calibri", 5, FontStyle.Regular);
// System.Drawing.Font NewfontBold = new System.Drawing.Font("Calibri", 5, FontStyle.Bold);
// e.Graphics.DrawString("MRP", NewfontBold, Brushes.Black, x + 15, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// for (int i = 0; i < 2; i++)
// {
// destfile = destfile.Substring(0, destfile.LastIndexOf("\\"));
// }
// string path = destfile;
// PrivateFontCollection Rupees = new PrivateFontCollection();
// Rupees.AddFontFile(path + "\\Rupee_Foradian.ttf");
// e.Graphics.DrawString("` ", new System.Drawing.Font(Rupees.Families[0], 6, FontStyle.Bold), Brushes.Black, x + 45, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].Price).ToString("N", CultureInfo.CreateSpecificCulture("hi-IN")), Newfont, Brushes.Black, x + 51, PositionY);
// if (File.Exists(destfile + "\\Resources\\Milaan.png"))
// {
// System.Drawing.Image bmp = Bitmap.FromFile(destfile + "\\Resources\\Milaan.png");
// e.Graphics.DrawImage(bmp, x, PositionY);
// }
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Wt.", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].GrossWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Size", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(Bars[doc.Offset].Size, font, Brushes.Black, x + 45, PositionY);
// e.Graphics.DrawString("Color : ", NewfontBold, Brushes.Black, x + 80, PositionY);
// e.Graphics.DrawString(Bars[doc.Offset].Colour, Newfont, Brushes.Black, x + 100, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Gold", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString("(" + Bars[doc.Offset].Grade + ")" + Bars[doc.Offset].GoldCategory, Newfont, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Silver", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString("(" + Bars[doc.Offset].SilverPurity + ")" + Bars[doc.Offset].SilverCategory, Newfont, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// if (File.Exists(destfile + "\\Resources\\Glizmore.png"))
// {
// System.Drawing.Image bmp = Bitmap.FromFile(destfile + "\\Resources\\Glizmore.png");
// e.Graphics.DrawImage(bmp, x + 134, y);
// }
// e.Graphics.DrawString(Bars[doc.Offset].ItemName, NewfontBold, Brushes.Black, x + 154, y);
// y += Newfont.Height;
// e.Graphics.DrawString(Bars[doc.Offset].BrandName, NewfontBold, Brushes.Black, x + 132, y);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 170, y);
// e.Graphics.DrawString(Bars[doc.Offset].StyleNo, Newfont, Brushes.Black, x + 176, y);
// y += Newfont.Height;
// e.Graphics.DrawImage(Bars[doc.Offset].BarcodeImage, x + 132, y);
// //e.Graphics.DrawString(Bars[doc.Offset].StoreName, Newfont, Brushes.Black, x + 134, y + Bars[doc.Offset].BarcodeImage.Height + 9);
// doc.Offset += 1;
// y += lineHeight;
// }
// else if (Bars[doc.Offset].BrandName == "Glizmore")
// {
// float PositionY = 0f;
// System.Drawing.Font Newfont = new System.Drawing.Font("Calibri", 5, FontStyle.Regular);
// System.Drawing.Font NewfontBold = new System.Drawing.Font("Calibri", 5, FontStyle.Bold);
// e.Graphics.DrawString("MRP", NewfontBold, Brushes.Black, x + 15, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// for (int i = 0; i < 2; i++)
// {
// destfile = destfile.Substring(0, destfile.LastIndexOf("\\"));
// }
// string path = destfile;
// PrivateFontCollection Rupees = new PrivateFontCollection();
// Rupees.AddFontFile(path + "\\Rupee_Foradian.ttf");
// e.Graphics.DrawString("` ", new System.Drawing.Font(Rupees.Families[0], 6, FontStyle.Bold), Brushes.Black, x + 45, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].Price).ToString("N", CultureInfo.CreateSpecificCulture("hi-IN")), Newfont, Brushes.Black, x + 51, PositionY);
// if (File.Exists(destfile + "\\Resources\\Milaan.png"))
// {
// System.Drawing.Image bmp = Bitmap.FromFile(destfile + "\\Resources\\Milaan.png");
// e.Graphics.DrawImage(bmp, x, PositionY);
// }
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Wt.", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].GrossWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Size", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(Bars[doc.Offset].Size, font, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Color", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(Bars[doc.Offset].Colour, Newfont, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// e.Graphics.DrawString("Silver", NewfontBold, Brushes.Black, x, PositionY);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 35, PositionY);
// e.Graphics.DrawString(Bars[doc.Offset].SilverPurity, Newfont, Brushes.Black, x + 45, PositionY);
// PositionY += Newfont.Height;
// if (File.Exists(destfile + "\\Resources\\Glizmore.png"))
// {
// System.Drawing.Image bmp = Bitmap.FromFile(destfile + "\\Resources\\Glizmore.png");
// e.Graphics.DrawImage(bmp, x + 134, y);
// }
// e.Graphics.DrawString(Bars[doc.Offset].ItemName, NewfontBold, Brushes.Black, x + 154, y);
// y += Newfont.Height;
// e.Graphics.DrawString(Bars[doc.Offset].BrandName, NewfontBold, Brushes.Black, x + 132, y);
// e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 170, y);
// e.Graphics.DrawString(Bars[doc.Offset].StyleNo, Newfont, Brushes.Black, x + 176, y);
// y += Newfont.Height;
// e.Graphics.DrawImage(Bars[doc.Offset].BarcodeImage, x + 132, y);
// //e.Graphics.DrawString(Bars[doc.Offset].StoreName, Newfont, Brushes.Black, x + 134, y + Bars[doc.Offset].BarcodeImage.Height + 9);
// doc.Offset += 1;
// y += lineHeight;
// }
// if (doc.Offset < Bars.Count)
// {
// e.HasMorePages = true;
// }
// else
// {
// doc.Offset = 0;
// }
// }
//}
#endregion
private void BtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
// Added code for new format of Brand here onwards.....
public System.Drawing.Image GenerateBarcode(string Text)
{
Barcode128 code128 = new Barcode128();
code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = false;
code128.Code = Text;
System.Drawing.Bitmap bmpimg = new Bitmap(130, 12);
Graphics bmpgraphics = Graphics.FromImage(bmpimg);
bmpgraphics.Clear(Color.White);
bmpgraphics.DrawImage(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(0, 0));
return bmpimg;
}
//class TextDocument : PrintDocument
//{
// public int PageNumber;
// public int Offset;
// public TextDocument()
// {
// }
//}
public void GenerateListOfItemsToPrint(int Item_ID, string Brand, string Metal, string SilverPurity, string ProductType, string ProductCategory, string StyleNo, int Quantity, string GrossWt, string DJILMRP, string FranchiseMRP, string StoreMRP, string Barcode, string Gold_Grade, string Gold_Purity, string Size, string Color, string Stone_Name)
{
for (int i = 0; i < Quantity; i++)
{
barList bar = new barList();
// bar.Item_ID = Item_ID;
bar.BrandName = Brand;
// bar.DJILMRP = DJILMRP;
// bar.FranchiseMRP = FranchiseMRP;
bar.GrossWt = GrossWt;
bar.Metal = Metal;
bar.ProductCategory = ProductCategory;
bar.ProductType = ProductType;
bar.Quantity = Quantity;
bar.SilverPurity = SilverPurity;
bar.StoreMRP = StoreMRP;
bar.StyleNo = StyleNo;
bar.Barcode = Barcode;
// bar.Gold_Grade = Gold_Grade;
bar.Gold_Purity = Gold_Purity;
bar.Size = Size;
bar.Color = Color;
bar.Stone_Name = Stone_Name;
Bars.Add(bar);
}
}
public void PrintItems(PrintDialog dig, PrintDocument doc)
{
doc.PrinterSettings.PrinterName = dig.PrinterSettings.PrinterName;
PaperSize paperSize = new PaperSize();
paperSize.RawKind = (int)PaperKind.Custom;
paperSize.Height = 50;
doc.DefaultPageSettings.PaperSize = paperSize;
doc.DefaultPageSettings.Landscape = false;
doc.DefaultPageSettings.Margins = new Margins(4, 1, 0, 1);
doc.PrintPage += this.PrintingBarcode;
doc.Print();
}
private void PrintingBarcode(object sender, PrintPageEventArgs e)
{
TextDocument doc = (TextDocument)sender;
System.Drawing.Font font = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
System.Drawing.Font fontBold = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
float lineHeight = 25;
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
doc.PageNumber += 1;
string destfile = Application.StartupPath;
while ((y + lineHeight) < e.MarginBounds.Bottom && doc.Offset < Bars.Count)
{
#region IF BRAND IS MILAAN
if (Bars[doc.Offset].BrandName == "Milaan")
{
float PositionY = 0f;
System.Drawing.Font Newfont = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
System.Drawing.Font NewfontBold = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
e.Graphics.DrawString("MRP", NewfontBold, Brushes.Black, x + 32, PositionY);
e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
for (int i = 0; i < 2; i++)
{
destfile = destfile.Substring(0, destfile.LastIndexOf("\\"));
}
string path = destfile;
PrivateFontCollection Rupees = new PrivateFontCollection();
string NewPath = Environment.CurrentDirectory;
if (File.Exists(NewPath + "\\Milaan.png"))
{
System.Drawing.Image bmp = Bitmap.FromFile(NewPath + "\\Milaan.png");
System.Drawing.Image newImage = ScaleImage(bmp, 30, 30);
e.Graphics.DrawImage(newImage, x, PositionY+2);
}
Rupees.AddFontFile(NewPath + "\\Rupee_Foradian.ttf");
e.Graphics.DrawString("` ", new System.Drawing.Font(Rupees.Families[0], 6, FontStyle.Bold), Brushes.Black, x + 67, PositionY);
e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].StoreMRP).ToString("N", CultureInfo.CreateSpecificCulture("hi-IN")), Newfont, Brushes.Black, x + 73, PositionY);
PositionY += Newfont.Height;
e.Graphics.DrawString("Wt.", NewfontBold, Brushes.Black, x + 32, PositionY);
e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].GrossWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 67, PositionY);
PositionY += Newfont.Height;
e.Graphics.DrawString("Purity", NewfontBold, Brushes.Black, x + 32, PositionY);
e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
int Purity = Bars[doc.Offset].SilverPurity.Length;
if (Purity > 15)
{
string PurityF = Bars[doc.Offset].SilverPurity.Substring(0, 15);
e.Graphics.DrawString(PurityF, NewfontBold, Brushes.Black, x + 67, PositionY);
PositionY += NewfontBold.Height;
string PurityL = Bars[doc.Offset].SilverPurity.Substring(15, Purity - 15);
e.Graphics.DrawString(PurityL, NewfontBold, Brushes.Black, x + 67, PositionY);
PositionY += NewfontBold.Height;
}
else
{
e.Graphics.DrawString(Bars[doc.Offset].SilverPurity, NewfontBold, Brushes.Black, x + 67, PositionY);
PositionY += NewfontBold.Height;
}
//e.Graphics.DrawString(Bars[doc.Offset].SilverPurity, font, Brushes.Black, x + 67, PositionY);
int RightY = 0;
if (File.Exists(NewPath + "\\Glizmore.png"))
{
System.Drawing.Image bmp = Bitmap.FromFile(NewPath + "\\Glizmore.png");
System.Drawing.Image newImage = ScaleImage(bmp, 16, 16);
e.Graphics.DrawImage(newImage, x + 132, RightY);
}
e.Graphics.DrawString("L/S : " + Bars[doc.Offset].Size, NewfontBold, Brushes.Black, x + 149, RightY);
e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 197, RightY);
e.Graphics.DrawString(Bars[doc.Offset].Stone_Name, NewfontBold, Brushes.Black, x + 205, RightY);
RightY += Newfont.Height;
e.Graphics.DrawString("Glizmore", NewfontBold, Brushes.Black, x + 149, RightY);
e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 180, RightY);
e.Graphics.DrawString(Bars[doc.Offset].Color, NewfontBold, Brushes.Black, x + 187, RightY);
e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 196, RightY);
e.Graphics.DrawString(Bars[doc.Offset].StyleNo, NewfontBold, Brushes.Black, x + 202, RightY);
//e.Graphics.DrawString(Bars[doc.Offset].ProductCategory, NewfontBold, Brushes.Black, x + 152, PositionY);
//e.Graphics.DrawString(Bars[doc.Offset].ProductType, NewfontBold, Brushes.Black, x + 184, PositionY);
//PositionY += Newfont.Height;
//e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 191, PositionY);
//e.Graphics.DrawString(Bars[doc.Offset].StyleNo, Newfont, Brushes.Black, x + 198, PositionY);
// PositionY += Newfont.Height;
string BarcodeText = "";
if (Bars[doc.Offset].Barcode != "" && Bars[doc.Offset].Barcode != null)
{
BarcodeText = Bars[doc.Offset].Barcode;
}
//else
//{
// BarcodeText = GetTopValue();
// string Gen_No = BarcodeText.Substring(2, 12);
// int Item_ID = Bars[doc.Offset].Item_ID;
// UpdatePrintedBarcode(Item_ID, Gen_No, BarcodeText);
// BindGrid();
// //****** if quantity based ********//
// for (int i = 0; i < Bars.Count; i++)
// {
// if (Bars[i].Item_ID == Item_ID)
// {
// Bars[i].Barcode = BarcodeText;
// }
// }
// //**************************************//
//}
System.Drawing.Image img = GenerateBarcode(BarcodeText);
e.Graphics.DrawImage(img, x + 132, y + (Newfont.Height) * 2);
string PrintBarcode = "* " + BarcodeText + " *";
StringFormat f = new StringFormat();
f.Alignment = StringAlignment.Near;
f.LineAlignment = StringAlignment.Near;
int LabelX = 0;
int LabelY = 0;
LabelX = (int)x + 134 + (img.Width / 2) - PrintBarcode.Length;
LabelY = (int)(y + (Newfont.Height) * 2 + img.Height);
f.Alignment = StringAlignment.Center;
e.Graphics.DrawString("* " + BarcodeText + " *", font, Brushes.Black, new RectangleF((float)(x + 126), (float)LabelY, (float)img.Width, (float)font.Height), f);
doc.Offset += 1;
y += lineHeight;
}
#endregion
#region IF BRAND IS GLIZMORE
else if (Bars[doc.Offset].BrandName == "Glizmore")
{
float PositionY = 0f;
System.Drawing.Font Newfont = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
System.Drawing.Font NewfontBold = new System.Drawing.Font("Calibri", 6, FontStyle.Bold);
e.Graphics.DrawString("MRP", NewfontBold, Brushes.Black, x + 32, PositionY);
e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
for (int i = 0; i < 2; i++)
{
destfile = destfile.Substring(0, destfile.LastIndexOf("\\"));
}
string path = destfile;
PrivateFontCollection Rupees = new PrivateFontCollection();
string NewPath = Environment.CurrentDirectory;
if (File.Exists(NewPath + "\\Derewala.png"))
{
System.Drawing.Image bmp = Bitmap.FromFile(NewPath + "\\Derewala.png");
System.Drawing.Image newImage = ScaleImage(bmp, 30, 30);
e.Graphics.DrawImage(newImage, x, PositionY+2);
}
Rupees.AddFontFile(NewPath + "\\Rupee_Foradian.ttf");
e.Graphics.DrawString("` ", new System.Drawing.Font(Rupees.Families[0], 6, FontStyle.Bold), Brushes.Black, x + 67, PositionY);
e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].StoreMRP).ToString("N", CultureInfo.CreateSpecificCulture("hi-IN")), Newfont, Brushes.Black, x + 73, PositionY);
PositionY += Newfont.Height;
//e.Graphics.DrawString("Wt.", NewfontBold, Brushes.Black, x + 32, PositionY);
//e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
//e.Graphics.DrawString(decimal.Parse(Bars[doc.Offset].GrossWt).ToString("0.000") + " gm.", font, Brushes.Black, x + 67, PositionY);
//PositionY += Newfont.Height;
e.Graphics.DrawString("Purity", NewfontBold, Brushes.Black, x + 32, PositionY);
e.Graphics.DrawString(" : ", NewfontBold, Brushes.Black, x + 57, PositionY);
e.Graphics.DrawString(Bars[doc.Offset].SilverPurity, NewfontBold, Brushes.Black, x + 67, PositionY);
//e.Graphics.DrawString(Bars[doc.Offset].SilverPurity, font, Brushes.Black, x + 67, PositionY);
int RightY = 0;
if (File.Exists(NewPath + "\\Glizmore.png"))
{
System.Drawing.Image bmp = Bitmap.FromFile(NewPath + "\\Glizmore.png");
System.Drawing.Image newImage = ScaleImage(bmp, 16, 16);
e.Graphics.DrawImage(newImage, x + 132, RightY);
}
//e.Graphics.DrawString("L/S : " + Bars[doc.Offset].Size, NewfontBold, Brushes.Black, x + 149, RightY);
//e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 197, RightY);
//e.Graphics.DrawString(Bars[doc.Offset].Stone_Name, NewfontBold, Brushes.Black, x + 205, RightY);
e.Graphics.DrawString(Bars[doc.Offset].ProductCategory, NewfontBold, Brushes.Black, x + 149, RightY);
e.Graphics.DrawString(" ", NewfontBold, Brushes.Black, x + 180, RightY);
e.Graphics.DrawString(Bars[doc.Offset].ProductType, NewfontBold, Brushes.Black, x + 190, RightY);
RightY += Newfont.Height;
e.Graphics.DrawString(Bars[doc.Offset].BrandName, NewfontBold, Brushes.Black, x + 149, RightY);
e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 180, RightY);
//e.Graphics.DrawString(Bars[doc.Offset].Color, NewfontBold, Brushes.Black, x + 187, RightY);
//e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 196, RightY);
e.Graphics.DrawString(Bars[doc.Offset].StyleNo, NewfontBold, Brushes.Black, x + 187, RightY);
//e.Graphics.DrawString(Bars[doc.Offset].ProductCategory, NewfontBold, Brushes.Black, x + 152, PositionY);
//e.Graphics.DrawString(Bars[doc.Offset].ProductType, NewfontBold, Brushes.Black, x + 184, PositionY);
//PositionY += Newfont.Height;
//e.Graphics.DrawString(" | ", NewfontBold, Brushes.Black, x + 191, PositionY);
//e.Graphics.DrawString(Bars[doc.Offset].StyleNo, Newfont, Brushes.Black, x + 198, PositionY);
// PositionY += Newfont.Height;
string BarcodeText = "";
if (Bars[doc.Offset].Barcode != "" && Bars[doc.Offset].Barcode != null)
{
BarcodeText = Bars[doc.Offset].Barcode;
}
//else
//{
// BarcodeText = GetTopValue();
// string Gen_No = BarcodeText.Substring(2, 12);
// int Item_ID = Bars[doc.Offset].Item_ID;
// UpdatePrintedBarcode(Item_ID, Gen_No, BarcodeText);
// BindGrid();
// //****** if quantity based ********//
// for (int i = 0; i < Bars.Count; i++)
// {
// if (Bars[i].Item_ID == Item_ID)
// {
// Bars[i].Barcode = BarcodeText;
// }
// }
// //**************************************//
//}
System.Drawing.Image img = GenerateBarcode(BarcodeText);
e.Graphics.DrawImage(img, x + 132, y + (Newfont.Height) * 2);
string PrintBarcode = "* " + BarcodeText + " *";
StringFormat f = new StringFormat();
f.Alignment = StringAlignment.Near;
f.LineAlignment = StringAlignment.Near;
int LabelX = 0;
int LabelY = 0;
LabelX = (int)x + 134 + (img.Width / 2) - PrintBarcode.Length;
LabelY = (int)(y + (Newfont.Height) * 2 + img.Height);
f.Alignment = StringAlignment.Center;
e.Graphics.DrawString("* " + BarcodeText + " *", font, Brushes.Black, new RectangleF((float)(x + 126), (float)LabelY, (float)img.Width, (float)font.Height), f);
doc.Offset += 1;
y += lineHeight;
}
#endregion
if (doc.Offset < Bars.Count)
{
e.HasMorePages = true;
}
else
{
doc.Offset = 0;
}
}
}
public static System.Drawing.Image ScaleImage(System.Drawing.Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
return newImage;
}
}
}