void UPC_AddChecksum(object sender, AddChecksumEventArgs e) { if (e.Codes.Count == 12) { return; } int total = 0; for (int i = 0; i < e.Codes.Count; i++) { if (i % 2 == 1) { total += (e.Codes[i] % 10); } else { total += 3 * (e.Codes[i] % 10); } } total = total % 10; e.Codes.Add(total == 0 ? 20 : 30 - total); e.Text += (total == 0 ? 0 : 10 - total).ToString(); }
public static void AddChecksumEventHandler(object sender, AddChecksumEventArgs e) { string value = e.Text.Replace(" ", ""); if (!System.Text.RegularExpressions.Regex.IsMatch(value, "^\\d+$")) { throw new ArgumentException("Only numeric values can have a check digit"); } int total = 0; for (int i = 0; i < value.Length; i++) { if (i % 2 == 0) { total += int.Parse(value.Substring(i, 1)); } else { int tmp = int.Parse(value.Substring(i, 1)) * 2; total += (tmp % 9); } } total = total % 10; e.Text += total.ToString(); e.Codes.Insert(e.Codes.Count - 1, total.ToString()[0]); }
protected void DoChecksumCalculation(AddChecksumEventArgs e, int factor) { int tmp = 0; int weight = 0; for (int i = 0; i < e.Text.Length; i++) { weight = ((e.Text.Length - i) % factor); if (weight == 0) { weight = factor; } tmp += ((e.Text[i] == '-' ? 10 : int.Parse(e.Text.Substring(i, 1))) * weight); } tmp = tmp % 11; e.Text += tmp > 9 ? "-" : tmp.ToString(); if (e.Codes != null) { if (e.Codes[e.Codes.Count - 1] == LIMIT) { e.Codes.Insert(e.Codes.Count - 1, tmp > 9 ? '-' : tmp + '0'); } else { e.Codes.Add(tmp > 9 ? '-' : tmp + '0'); } } }
public string AddSingleCheckDigit(string value) { AddChecksumEventArgs e = new AddChecksumEventArgs(value, null); DoChecksumCalculation(e, 10); return e.Text; }
void RM4SCC_AddChecksum(object sender, AddChecksumEventArgs e) { int[] values = new int[PatternSet.Count]; PatternSet.Keys.CopyTo(values, 0); int rowTotal = 0, colTotal = 0, tmp; for (int i = 1; i < e.Codes.Count - 1; i++) { int index = Array.IndexOf(values, e.Codes[i]); tmp = (index / 6) + 1; rowTotal += (tmp == 6 ? 0 : tmp); tmp = (index % 6) + 1; colTotal += (tmp == 6 ? 0 : tmp); } rowTotal = rowTotal % 6; rowTotal = rowTotal == 0 ? 6 : rowTotal - 1; colTotal = colTotal % 6; colTotal = colTotal == 0 ? 5 : colTotal - 1; e.Codes.Insert(e.Codes.Count - 1, values[(rowTotal * 6) + colTotal]); }
public string AddSingleCheckDigit(string value) { AddChecksumEventArgs e = new AddChecksumEventArgs(value, null); DoChecksumCalculation(e, 10); return(e.Text); }
/// <summary> /// Fires the add checksum event /// </summary> /// <param name="e">Arguments for the add checksum event</param> protected virtual void OnAddChecksum(AddChecksumEventArgs e) { if (AddChecksum == null) { return; } AddChecksum(this, e); }
/// <summary> /// If the barcode supports a check digit, add it to the string /// </summary> /// <param name="value">barcode value to use for calculation</param> /// <returns>check digit to return</returns> public virtual string AddCheckDigit(string value) { CodedValueCollection codes = new CodedValueCollection(); value = ParseText(value, codes); AddChecksumEventArgs e = new AddChecksumEventArgs(value, codes); OnAddChecksum(e); return(e.Text); }
void Postnet_AddChecksum(object sender, AddChecksumEventArgs e) { int total = 0; for (int i = 1; i < e.Codes.Count - 1; i++) { total += e.Codes[i]; } total = total % 10; e.Codes.Insert(e.Codes.Count - 1, total == 0 ? 0 : 10 - total); }
void Code11_AddChecksum(object sender, AddChecksumEventArgs e) { e.Codes.RemoveAt(e.Codes.Count - 1); DoChecksumCalculation(e, 10); if (e.Text.Length >= 10) { DoChecksumCalculation(e, 9); } e.Codes.Add(LIMIT); }
public static void AddChecksumEventHandler(object sender, AddChecksumEventArgs e) { int total = 0; bool isEven = true; for (int i = e.Codes.Count - 2; i < 0; i--) { total += isEven ? 3 * e.Codes[i] : e.Codes[i]; } total = total % 10; total = total == 0 ? 0 : 10 - total; e.Codes.Insert(e.Codes.Count - 1, total); e.Text += total.ToString(); }
public static void AddChecksumEventHandler(object sender, AddChecksumEventArgs e) { int total = 0; bool isEven = true; for (int i = e.Codes.Count-2; i < 0; i--) { total += isEven ? 3 * e.Codes[i] : e.Codes[i]; } total = total % 10; total = total == 0 ? 0 : 10 - total; e.Codes.Insert(e.Codes.Count - 1, total); e.Text += total.ToString(); }
/// <summary> /// Handles the add checksum event /// </summary> /// <param name="sender">the barcode instance raising the event</param> /// <param name="e">argument for the event</param> void Code128_AddChecksum(object sender, AddChecksumEventArgs e) { int total = 0; for (int i = 0; i < e.Codes.Count - 1; i++) { if (i == 0) { total = e.Codes[i]; } else { total += e.Codes[i] * i; } } e.Codes.Insert(e.Codes.Count - 1, total % 103); }
void UPC_AddChecksum(object sender, AddChecksumEventArgs e) { if (e.Codes.Count == 12) return; int total = 0; for (int i = 0; i < e.Codes.Count; i++) { if (i % 2 == 1) total += (e.Codes[i] % 10); else total += 3 * (e.Codes[i] % 10); } total = total % 10; e.Codes.Add(total == 0 ? 20 : 30 - total); e.Text += (total == 0 ? 0 : 10 - total).ToString(); }
private void AddCheckDigit(AddChecksumEventArgs e, int weight) { int total = 0; int w = 1; for (int i = e.Codes.Count - 2; i > 0; i--) { total += (w * e.Codes[i]); w++; if (w > weight) { w = 1; } } total = total % 47; e.Codes.Insert(e.Codes.Count - 2, total); }
protected void DoChecksumCalculation(AddChecksumEventArgs e, int factor) { int tmp = 0; int weight = 0; for (int i = 0; i < e.Text.Length; i++) { weight = ((e.Text.Length - i) % factor); if (weight == 0) weight = factor; tmp += ((e.Text[i] == '-' ? 10 : int.Parse(e.Text.Substring(i, 1))) * weight); } tmp = tmp % 11; e.Text += tmp > 9 ? "-" : tmp.ToString(); if (e.Codes != null) { if (e.Codes[e.Codes.Count - 1] == LIMIT) e.Codes.Insert(e.Codes.Count - 1, tmp > 9 ? '-' : tmp + '0'); else e.Codes.Add(tmp > 9 ? '-' : tmp + '0'); } }
/// <summary> /// Main function to draw the barcode /// </summary> /// <param name="settings">setting in use with this barcode</param> /// <param name="text">text to encode</param> /// <returns>bitmap image of the barcode</returns> protected Bitmap Paint(BarcodeSettings settings, string text) { State state = new State(settings, settings.LeftMargin, settings.TopMargin); state.Codes = new CodedValueCollection(); state.Text = ParseText(text, state.Codes); if (settings.IsChecksumCalculated) { AddChecksumEventArgs args = new AddChecksumEventArgs(state); OnAddChecksum(args); state.Text = args.Text; } Size size = GetDimensions(settings, state.Codes); Bitmap b = new Bitmap(size.Width, size.Height); //, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale); state.Canvas = Graphics.FromImage(b); Paint(state); return(b); }
public static void AddChecksumEventHandler(object sender, AddChecksumEventArgs e) { string value = e.Text.Replace(" ", ""); if (!System.Text.RegularExpressions.Regex.IsMatch(value, "^\\d+$")) throw new ArgumentException("Only numeric values can have a check digit"); int total = 0; for (int i = 0; i < value.Length; i++) { if (i % 2 == 0) total += int.Parse(value.Substring(i, 1)); else { int tmp = int.Parse(value.Substring(i, 1)) * 2; total += (tmp % 9); } } total = total % 10; e.Text += total.ToString(); e.Codes.Insert(e.Codes.Count - 1, total.ToString()[0]); }
/// <summary> /// Fires the add checksum event /// </summary> /// <param name="e">Arguments for the add checksum event</param> protected virtual void OnAddChecksum(AddChecksumEventArgs e) { if (AddChecksum == null) return; AddChecksum(this, e); }
void Code11_AddChecksum(object sender, AddChecksumEventArgs e) { e.Codes.RemoveAt(e.Codes.Count - 1); DoChecksumCalculation(e, 10); if (e.Text.Length >= 10) DoChecksumCalculation(e, 9); e.Codes.Add(LIMIT); }
/// <summary> /// Handles the add checksum event /// </summary> /// <param name="sender">the barcode instance raising the event</param> /// <param name="e">argument for the event</param> void Code128_AddChecksum(object sender, AddChecksumEventArgs e) { int total = 0; for (int i = 0; i < e.Codes.Count - 1; i++) { if (i == 0) total = e.Codes[i]; else total += e.Codes[i] * i; } e.Codes.Insert(e.Codes.Count - 1, total % 103); }
/// <summary> /// If the barcode supports a check digit, add it to the string /// </summary> /// <param name="value">barcode value to use for calculation</param> /// <returns>check digit to return</returns> public virtual string AddCheckDigit(string value) { CodedValueCollection codes = new CodedValueCollection(); value = ParseText(value, codes); AddChecksumEventArgs e = new AddChecksumEventArgs(value, codes); OnAddChecksum(e); return e.Text; }
void RM4SCC_AddChecksum(object sender, AddChecksumEventArgs e) { int[] values = new int[PatternSet.Count]; PatternSet.Keys.CopyTo(values, 0); int rowTotal = 0, colTotal = 0, tmp; for(int i = 1;i < e.Codes.Count -1; i++) { int index = Array.IndexOf(values, e.Codes[i]); tmp = (index / 6) + 1; rowTotal += (tmp == 6 ? 0 : tmp); tmp = (index % 6) + 1; colTotal += (tmp == 6 ? 0 : tmp); } rowTotal = rowTotal % 6; rowTotal = rowTotal == 0 ? 6 : rowTotal - 1; colTotal = colTotal % 6; colTotal = colTotal == 0 ? 5 : colTotal - 1; e.Codes.Insert(e.Codes.Count - 1, values[(rowTotal * 6) + colTotal]); }
private void Code93_AddChecksum(object sender, AddChecksumEventArgs e) { AddCheckDigit(e, 20); AddCheckDigit(e, 15); }
private void AddCheckDigit(AddChecksumEventArgs e, int weight) { int total = 0; int w = 1; for (int i = e.Codes.Count - 2; i > 0; i--) { total += (w * e.Codes[i]); w++; if (w > weight) w = 1; } total = total % 47; e.Codes.Insert(e.Codes.Count - 2, total); }
/// <summary> /// Main function to draw the barcode /// </summary> /// <param name="settings">setting in use with this barcode</param> /// <param name="text">text to encode</param> /// <returns>bitmap image of the barcode</returns> protected Bitmap Paint(BarcodeSettings settings, string text) { State state = new State(settings, settings.LeftMargin, settings.TopMargin); state.Codes = new CodedValueCollection(); state.Text = ParseText(text, state.Codes); if (settings.IsChecksumCalculated) { AddChecksumEventArgs args = new AddChecksumEventArgs(state); OnAddChecksum(args); state.Text = args.Text; } Size size = GetDimensions(settings, state.Codes); Bitmap b = new Bitmap(size.Width, size.Height);//, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale); state.Canvas = Graphics.FromImage(b); Paint(state); return b; }