Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Dear
I tried to used the code what it is in you website. but alwyes get wrong
the wrong is web.mvc.dll is unhandeled
can you please help me to create Bar code en add to explorer in mvc C# Database with more than 7 tables and database first
best regards
F Ibrahim
e-mail: faayez@gmail.com

I want to create Barcode for products that what i did barcode controller:
C#
public ActionResult Index(BProduct model)
{
barcodecs objbar = new barcodecs();
BProduct objprod = new BProduct()
{
ProductName = model.ProductName,
Description = model.Description,
ImageUrl = model.ImageUrl,
BarCodeID = model.BarCodeID,
Barcode = objbar.generateBarcode(),
BarcodeImage = objbar.getBarcodeImage(objbar.generateBarcode(), model.ProductName)
};
BProduct.InsertOnSubmit(objprod);
SubmitChanges();
return RedirectToAction("Mixxim_ICT", "Home");
}
 
private void SubmitChanges()
{
throw new NotImplementedException();
}
static void Main(string[] args)
{
try
{
FutureFeature();
}
catch (NotImplementedException notImp)
{
Console.WriteLine(notImp.Message);
}
}
 
static void FutureFeature()
{
// Not developed yet. 
throw new NotImplementedException();
}
public ActionResult BarCode()

SqlConnection con = new SqlConnection("Data Source=-------\\SQLEXPRESS;Initial Catalog=storage;Integrated Security=sspi");
string query = "select * From Barcode";
DataTable dt = new DataTable();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(query, con);
sda.Fill(dt);
con.Close();
IList model = new List();
for (int i = 0; i < dt.Rows.Count; i++)
{
 
var p = dt.Rows[i]["BarCodeImage"];
model.Add(new BProduct()
{
ProductName = dt.Rows[i]["ProductName"].ToString(),
Description = dt.Rows[i]["Description"].ToString(),
Barcode = dt.Rows[i]["Barcode1"].ToString(),
ImageUrl = dt.Rows[i]["BarCodeImage"] != null ? "data:image/jpg;base64," + Convert.ToBase64String((byte[])dt.Rows[i]["BarCodeImage"]) : ""
 
}
);
 

}
return View(model);
}
}
}
Posted
Updated 5-Jul-14 22:37pm
v2
Comments
Marc Gabrie 5-Jul-14 7:09am    
What kind of barcode type do you need? What have you tried so far?
faayez 5-Jul-14 18:41pm    
I want to create Barcode for products that what i did barcode controller:
public ActionResult Index(BProduct model)
{
barcodecs objbar = new barcodecs();
BProduct objprod = new BProduct()
{
ProductName = model.ProductName,
Description = model.Description,
ImageUrl = model.ImageUrl,
BarCodeID = model.BarCodeID,
Barcode = objbar.generateBarcode(),
BarcodeImage = objbar.getBarcodeImage(objbar.generateBarcode(), model.ProductName)
};
BProduct.InsertOnSubmit(objprod);
SubmitChanges();
return RedirectToAction("Mixxim_ICT", "Home");
}

private void SubmitChanges()
{
throw new NotImplementedException();
}
static void Main(string[] args)
{
try
{
FutureFeature();
}
catch (NotImplementedException notImp)
{
Console.WriteLine(notImp.Message);
}
}

static void FutureFeature()
{
// Not developed yet.
throw new NotImplementedException();
}
public ActionResult BarCode()

SqlConnection con = new SqlConnection("Data Source=-------\\SQLEXPRESS;Initial Catalog=storage;Integrated Security=sspi");
string query = "select * From Barcode";
DataTable dt = new DataTable();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(query, con);
sda.Fill(dt);
con.Close();
IList<bproduct> model = new List<bproduct>();
for (int i = 0; i < dt.Rows.Count; i++)
{

var p = dt.Rows[i]["BarCodeImage"];
model.Add(new BProduct()
{
ProductName = dt.Rows[i]["ProductName"].ToString(),
Description = dt.Rows[i]["Description"].ToString(),
Barcode = dt.Rows[i]["Barcode1"].ToString(),
ImageUrl = dt.Rows[i]["BarCodeImage"] != null ? "data:image/jpg;base64," + Convert.ToBase64String((byte[])dt.Rows[i]["BarCodeImage"]) : ""

}
);


}
return View(model);
}
}
}
faayez 5-Jul-14 18:42pm    
model Is:
namespace ITCompany.Models
{
using System;
using System.Collections.Generic;

public partial class BProduct
{
public BProduct()
{
this.StoreProducts = new HashSet<storeproduct>();
this.SupplierProducts = new HashSet<supplierproduct>();
}

public int BarCodeID { get; set; }
public byte[] BarcodeImage { get; set; }
public string ImageUrl { get; set; }
public string Barcode { get; set; }
public string ProductName { get; set; }
public string Description { get; set; }

public virtual ICollection<storeproduct> StoreProducts { get; set; }
public virtual ICollection<supplierproduct> SupplierProducts { get; set; }

internal static void InsertOnSubmit(BProduct objprod)
{
throw new NotImplementedException();
}
}
}
faayez 5-Jul-14 18:43pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Configuration;

namespace ITCompany.Models
{
public class BarCode39
{
private const int _itemSepHeight = 3;
SizeF _titleSize = SizeF.Empty;
SizeF _barCodeSize = SizeF.Empty;
SizeF _codeStringSize = SizeF.Empty;
public BarCode39()
{
_titleFont = new Font("Arial", 10);
_codeStringFont = new Font("Arial", 10);
}
#region Barcode Title
private string _titleString = null;
private Font _titleFont = null;
public string Title
{
get { return _titleString; }
set { _titleString = value; }
}
public Font TitleFont
{
get { return _titleFont; }
set { _titleFont = value; }
}
#endregion
#region Barcode code string
private bool _showCodeString = false;
private Font _codeStringFont = null;
public bool ShowCodeString
{
get { return _showCodeString; }
set { _showCodeString = value; }
}
public Font CodeStringFont
{
get { return _codeStringFont; }
set { _codeStringFont = value; }
}
#endregion
#region Barcode Font
private Font _c39Font = null;
private float _c39FontSize = 12;
private string _c39FontFileName = null;
private string _c39FontFamilyName = null;
public string FontFileName
{
get { return _c39FontFileName; }
set { _c39FontFileName = value; }
}
public string FontFamilyName
{
get { return _c39FontFamilyName; }
set { _c39FontFamilyName = value; }
}
public float FontSize
{
get { return _c39FontSize; }
set { _c39FontSize = value; }
}
private Font Code39Font
{
get
{
if (_c39Font == null)
{
// Load the barcode font
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile(_c39FontFileName);
FontFamily family = new FontFamily(_c39FontFamilyName, pfc);
_c39Font = new Font(family, _c39FontSize);
}
return _c39Font;
}
}
#endregion
#region Barcode Generation
public byte[] Code39(string code, int barSize, bool showCodeString, string title, string fontFile)
{
// Create stream....
MemoryStream ms = new MemoryStream();
FontFamilyName = "Free 3 of 9";//ConfigurationSettings.AppSettings["BarCodeFontFamily"];
FontFileName = fontFile;//@"C:\Documents and Settings\Desktop\Barcode\WSBarCode\Code39Font\FREE3OF9.TTF";// ConfigurationSettings.AppSettings["BarCodeFontFile"];
FontSize = barSize;
ShowCodeString = showCodeString;
if (title + "" != "")
Title = title;
Bitmap objBitmap = GenerateBarcode(code);
objBitmap.Save(ms, ImageFormat.Png);

//return bytes....
return ms.GetBuffer();
}
public Bitmap GenerateBarcode(string barCode)
{
int bcodeWidth = 0;
int bcodeHeight = 0;
// Get the image container...
Bitmap bcodeBitmap = CreateImageContainer(barCode, ref bcodeWidth, ref bcodeHeight);
Graphics objGraphics = Graphics.FromImage(bcodeBitmap);

// Fill the background
objGraphics.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, bcodeWidth, bcodeHeight));
faayez 5-Jul-14 18:44pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;


namespace ITCompany.Models
{
public class barcodecs
{
public string generateBarcode()
{
try
{
string[] charPool = "1-2-3-4-5-6-7-8-9-0".Split('-');
StringBuilder rs = new StringBuilder();
int length = 6;
Random rnd = new Random();
while (length-- > 0)
{
int index = (int)(rnd.NextDouble() * charPool.Length);
if (charPool[index] != "-")
{
rs.Append(charPool[index]);
charPool[index] = "-";
}
else
length++;
}
return rs.ToString();
}
catch (Exception )
{
//ErrorLog.WriteErrorLog("Barcode", ex.ToString(), ex.Message);
}
return "";
}

//31 December 2012 Prapti

public Byte[] getBarcodeImage(string barcode, string file)
{
try
{
BarCode39 _barcode = new BarCode39();
int barSize = 16;
string fontFile = HttpContext.Current.Server.MapPath("~/fonts/FREE3OF9.TTF");
return (_barcode.Code39(barcode, barSize, true, file, fontFile));
}
catch (Exception )
{
//ErrorLog.WriteErrorLog("Barcode", ex.ToString(), ex.Message);
}
return null;
}
}
}

1 solution

"when i run the project and click create
i get this:An exception of type 'System.NotImplementedException' occurred in ITCompany.dll but was not handled in user code"


Look at your code:
C#
static void Main(string[] args)
    {
    try
        {
        FutureFeature();
        }
    catch (NotImplementedException notImp)
        {
        Console.WriteLine(notImp.Message);
        }
    }

static void FutureFeature()
    {
    // Not developed yet.
    throw new NotImplementedException();
    }


All it will ever do is throw a NotImplementedException - because that is all you have told it to do!
 
Share this answer
 
Comments
faayez 6-Jul-14 18:49pm    
my quastion how i have to do it
I tried many times but i did not succsed can you help me please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900