全局搜索结果(4)
-
- 技术文摘c# 实现文件下载功能,带下载进度条,可用到软件的自动更新中
- 2021/1/19 18:44:59
- ...rc="https://img-blog.csdnimg.cn/20190516112307397.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3h1a2FpNTE1Nzg2,size_16,color_FFFFFF,t_70" src="https://img-blog.csdnimg.cn/20190516112307397.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3h1a2FpNTE1Nzg2,size_16,color_FFFFFF,t_70" width="478" class="has cke_widget_element" data-cke-widget-data="{"hasCaption":false,"src":"https://img-blog.csdnimg.cn/20190516112307397.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3h1a2FpNTE1Nzg2,size_16,color_FFFFFF,t_70","alt":"","width":"478","height":"238","lock":true,"align":"none","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image">1、实例一个委托: private delegate void setText();2、定义一个线程内方法:public void Threadp()
{
try
{
setText d = new setText(downFile); //实例化一个委托
this.Invoke(d); //在拥用此控件的基础窗体句柄的线程上执行指定的委托
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}3、下载文件的方法: public void downFile()
{
string updateFileUrl = textBox1.Text.Trim();
long fileLength = 0;
try
{
int readCountOnce = 5;//每次下载的字节数,该值越大,下载越快
WebRequest webReq = WebRequest.Create(updateFileUrl);
WebResponse webRes = webReq.GetResponse();
fileLength = webRes.ContentLength;
pbDownFile.Value = 0;
pbDownFile.Maximum = (int)fileLength;
try
{
Stream srm = webRes.GetResponseStream();
StreamReader srmReader = new StreamReader(srm);
byte[] bufferbyte = new byte[fileLength];
int allByte = (int)bufferbyte.Length;
int startByte = 0;
while (fileLength > 0)
{
Application.DoEvents();
int downByte = srm.Read(bufferbyte, startByte, allByte > readCountOnce ? readCountOnce : allByte);
if (downByte == 0) { break; };
startByte += downByte;
allByte -= downByte;
pbDownFile.Value += downByte;
float part = (float)startByte / readCountOnce;
float total = (float)bufferbyte.Length / readCountOnce;
int percent = Convert.ToInt32((part / total) * 100);
this.label_precess.Text = percent.ToString() + "%";
}
string tempPath = Application.StartupPath + "//files//";
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
tempPath += DateTime.Now.ToString("yyyyMMddHHmmss");
FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(bufferbyte, 0, bufferbyte.Length);
srm.Close();
srmReader.Close();
fs.Close();
}
catch (WebException ex)
{
MessageBox.Show("更新文件下载失败!" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (WebException ex1)
{
MessageBox.Show("更新文件下载失败!" + ex1.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}4、万事具备, 只欠东风了,来一个选择文件路径的按钮(文件路径可以是网络路径)private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = ofd.FileName;
}
}5、开始下载按钮事件:try
{
//string UpdateFile = textBox1.Text.Trim();
Thread threadDown = new Thread(new ThreadStart(Threadp));
threadDown.IsBackground = true;
threadDown.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
- 评论:0 / 阅读:1135
-
- 技术文摘c# 如何打印条形码
- 2021/1/20 20:30:37
- ...t;, \"16\", \"123122\");\n m_Code128.Rows.Add(\"17\", \"1\", \"1\", \"17\", \"123221\");\n m_Code128.Rows.Add(\"18\", \"2\", \"2\", \"18\", \"223211\");\n m_Code128.Rows.Add(\"19\", \"3\", \"3\", \"19\", \"221132\");\n m_Code128.Rows.Add(\"20\", \"4\", \"4\", \"20\", \"221231\");\n m_Code128.Rows.Add(\"21\", \"5\", \"5\", \"21\", \"213212\");\n m_Code128.Rows.Add(\"22\", \"6\", \"6\", \"22\", \"223112\");\n m_Code128.Rows.Add(\"23\", \"7\", \"7\", \"23\", \"312131\");\n m_Code128.Rows.Add(\"24\", \"8\", \"8\", \"24\", \"311222\");\n m_Code128.Rows.Add(\"25\", \"9\", \"9\", \"25\", \"321122\");\n m_Code128.Rows.Add(\"26\", \":\", \":\", \"26\", \"321221\");\n m_Code128.Rows.Add(\"27\", \";\", \";\", \"27\", \"312212\");\n m_Code128.Rows.Add(\"28\", \"<\", \"<\", \"28\", \"322112\");\n m_Code128.Rows.Add(\"29\", \"=\", \"=\", \"29\", \"322211\");\n m_Code128.Rows.Add(\"30\", \">\", \">\", \"30\", \"212123\");\n m_Code128.Rows.Add(\"31\", \"?\", \"?\", \"31\", \"212321\");\n m_Code128.Rows.Add(\"32\", \"@\", \"@\", \"32\", \"232121\");\n m_Code128.Rows.Add(\"33\", \"A\", \"A\", \"33\", \"111323\");\n m_Code128.Rows.Add(\"34\", \"B\", \"B\", \"34\", \"131123\");\n m_Code128.Rows.Add(\"35\", \"C\", \"C\", \"35\", \"131321\");\n m_Code128.Rows.Add(\"36\", \"D\", \"D\", \"36\", \"112313\");\n m_Code128.Rows.Add(\"37\", \"E\", \"E\", \"37\", \"132113\");\n m_Code128.Rows.Add(\"38\", \"F\", \"F\", \"38\", \"132311\");\n m_Code128.Rows.Add(\"39\", \"G\", \"G\", \"39\", \"211313\");\n m_Code128.Rows.Add(\"40\", \"H\", \"H\", \"40\", \"231113\");\n m_Code128.Rows.Add(\"41\", \"I\", \"I\", \"41\", \"231311\");\n m_Code128.Rows.Add(\"42\", \"J\", \"J\", \"42\", \"112133\");\n m_Code128.Rows.Add(\"43\", \"K\", \"K\", \"43\", \"112331\");\n m_Code128.Rows.Add(\"44\", \"L\", \"L\", \"44\", \"132131\");\n m_Code128.Rows.Add(\"45\", \"M\", \"M\", \"45\", \"113123\");\n m_Code128.Rows.Add(\"46\", \"N\", \"N\", \"46\", \"113321\");\n m_Code128.Rows.Add(\"47\", \"O\", \"O\", \"47\", \"133121\");\n m_Code128.Rows.Add(\"48\", \"P\", \"P\", \"48\", \"313121\");\n m_Code128.Rows.Add(\"49\", \"Q\", \"Q\", \"49\", \"211331\");\n m_Code128.Rows.Add(\"50\", \"R\", \"R\", \"50\", \"231131\");\n m_Code128.Rows.Add(\"51\", \"S\", \"S\", \"51\", \"213113\");\n m_Code128.Rows.Add(\"52\", \"T\", \"T\", \"52\", \"213311\");\n m_Code128.Rows.Add(\"53\", \"U\", \"U\", \"53\", \"213131\");\n m_Code128.Rows.Add(\"54\", \"V\", \"V\", \"54\", \"311123\");\n m_Code128.Rows.Add(\"55\", \"W\", \"W\", \"55\", \"311321\");\n m_Code128.Rows.Add(\"56\", \"X\", \"X\", \"56\", \"331121\");\n m_Code128.Rows.Add(\"57\", \"Y\", \"Y\", \"57\", \"312113\");\n m_Code128.Rows.Add(\"58\", \"Z\", \"Z\", \"58\", \"312311\");\n m_Code128.Rows.Add(\"59\", \"[\", \"[\", \"59\", \"332111\");\n m_Code128.Rows.Add(\"60\", \"\\\\\", \"\\\\\", \"60\", \"314111\");\n m_Code128.Rows.Add(\"61\", \"]\", \"]\", \"61\", \"221411\");\n m_Code128.Rows.Add(\"62\", \"^\", \"^\", \"62\", \"431111\");\n m_Code128.Rows.Add(\"63\", \"_\", \"_\", \"63\", \"111224\");\n m_Code128.Rows.Add(\"64\", \"NUL\", \"`\", \"64\", \"111422\");\n m_Code128.Rows.Add(\"65\", \"SOH\", \"a\", \"65\", \"121124\");\n m_Code128.Rows.Add(\"66\", \"STX\", \"b\", \"66\", \"121421\");\n m_Code128.Rows.Add(\"67\", \"ETX\", \"c\", \"67\", \"141122\");\n m_Code128.Rows.Add(\"68\", \"EOT\", \"d\", \"68\", \"141221\");\n m_Code128.Rows.Add(\"69\", \"ENQ\", \"e\", \"69\", \"112214\");\n m_Code128.Rows.Add(\"70\", \"ACK\", \"f\", \"70\", \"112412\");\n m_Code128.Rows.Add(\"71\", \"BEL\", \"g\", \"71\", \"122114\");\n m_Code128.Rows.Add(\"72\", \"BS\", \"h\", \"72\", \"122411\");\n m_Code128.Rows.Add(\"73\", \"HT\", \"i\", \"73\", \"142112\");\n m_Code128.Rows.Add(\"74\", \"LF\", \"j\", \"74\", \"142211\");\n m_Code128.Rows.Add(\"75\", \"VT\", \"k\", \"75\", \"241211\");\n m_Code128.Rows.Add(\"76\", \"FF\", \"I\", \"76\", \"221114\");\n m_Code128.Rows.Add(\"77\", \"CR\", \"m\", \"77\", \"413111\");\n m_Code128.Rows.Add(\"78\", \"SO\", \"n\", \"78\", \"241112\");\n m_Code128.Rows.Add(\"79\", \"SI\", \"o\", \"79\", \"134111\");\n m_Code128.Rows.Add(\"80\", \"DLE\", \"p\", \"80\", \"111242\");\n m_Code128.Rows.Add(\"81\", \"DC1\", \"q\", \"81\", \"121142\");\n m_Code128.Rows.Add(\"82\", \"DC2\", \"r\", \"82\", \"121241\");\n m_Code128.Rows.Add(\"83\", \"DC3\", \"s\", \"83\", \"114212\");\n m_Code128.Rows.Add(\"84\", \"DC4\", \"t\", \"84\", \"124112\");\n m_Code128.Rows.Add(\"85\", \"NAK\", \"u\", \"85\", \"124211\");\n m_Code128.Rows.Add(\"86\", \"SYN\", \"v\", \"86\", \"411212\");\n m_Code128.Rows.Add(\"87\", \"ETB\", \"w\", \"87\", \"421112\");\n m_Code128.Rows.Add(\"88\", \"CAN\", \"x\", \"88\", \"421211\");\n m_Code128.Rows.Add(\"89\", \"EM\", \"y\", \"89\", \"212141\");\n m_Code128.Rows.Add(\"90\", \"SUB\", \"z\", \"90\", \"214121\");\n m_Code128.Rows.Add(\"91\", \"ESC\", \"{\", \"91\", \"412121\");\n m_Code128.Rows.Add(\"92\", \"FS\", \"|\", \"92\", \"111143\");\n m_Code128.Rows.Add(\"93\", \"GS\", \"}\", \"93\", \"111341\");\n m_Code128.Rows.Add(\"94\", \"RS\", \"~\", \"94\", \"131141\");\n m_Code128.Rows.Add(\"95\", \"US\", \"DEL\", \"95\", \"114113\");\n m_Code128.Rows.Add(\"96\", \"FNC3\", \"FNC3\", \"96\", \"114311\");\n m_Code128.Rows.Add(\"97\", \"FNC2\", \"FNC2\", \"97\", \"411113\");\n m_Code128.Rows.Add(\"98\", \"SHIFT\", \"SHIFT\", \"98\", \"411311\");\n m_Code128.Rows.Add(\"99\", \"CODEC\", \"CODEC\", \"99\", \"113141\");\n m_Code128.Rows.Add(\"100\", \"CODEB\", \"FNC4\", \"CODEB\", \"114131\");\n m_Code128.Rows.Add(\"101\", \"FNC4\", \"CODEA\", \"CODEA\", \"311141\");\n m_Code128.Rows.Add(\"102\", \"FNC1\", \"FNC1\", \"FNC1\", \"411131\");\n m_Code128.Rows.Add(\"103\", \"StartA\", \"StartA\", \"StartA\", \"211412\");\n m_Code128.Rows.Add(\"104\", \"StartB\", \"StartB\", \"StartB\", \"211214\");\n m_Code128.Rows.Add(\"105\", \"StartC\", \"StartC\", \"StartC\", \"211232\");\n m_Code128.Rows.Add(\"106\", \"Stop\", \"Stop\", \"Stop\", \"2331112\");\n #endregion\n }\n /// <summary>\n /// 获取128图形\n /// </summary>\n /// <param name=\"p_Text\">文字</param>\n /// <param name=\"p_Code\">编码</param> \n /// <returns>图形</returns>\n public Bitmap GetCodeImage(string p_Text, Encode p_Code,Graphics g=null)\n {\n string _ViewText = p_Text;\n string _Text = \"\";\n IList<int> _TextNumb = new List<int>();\n int _Examine = 0; //首位\n switch (p_Code)\n {\n case Encode.Code128C:\n _Examine = 105;\n if (!((p_Text.Length & 1) == 0)) throw new Exception(\"128C长度必须是偶数\");\n while (p_Text.Length != 0)\n {\n int _Temp = 0;\n try\n {\n int _CodeNumb128 = Int32.Parse(p_Text.Substring(0, 2));\n }\n catch\n {\n throw new Exception(\"128C必须是数字!\");\n }\n _Text += GetValue(p_Code, p_Text.Substring(0, 2), ref _Temp);\n _TextNumb.Add(_Temp);\n p_Text = p_Text.Remove(0, 2);\n }\n break;\n case Encode.EAN128:\n _Examine = 105;\n if (!((p_Text.Length & 1) == 0)) throw new Exception(\"EAN128长度必须是偶数\");\n _TextNumb.Add(102);\n _Text += \"411131\";\n while (p_Text.Length != 0)\n {\n int _Temp = 0;\n try\n {\n int _CodeNumb128 = Int32.Parse(p_Text.Substring(0, 2));\n }\n catch\n {\n throw new Exception(\"128C必须是数字!\");\n }\n _Text += GetValue(Encode.Code128C, p_Text.Substring(0, 2), ref _Temp);\n _TextNumb.Add(_Temp);\n p_Text = p_Text.Remove(0, 2);\n }\n break;\n default:\n if (p_Code == Encode.Code128A)\n {\n _Examine = 103;\n }\n else\n {\n _Examine = 104;\n }\n\n while (p_Text.Length != 0)\n {\n int _Temp = 0;\n string _ValueCode = GetValue(p_Code, p_Text.Substring(0, 1), ref _Temp);\n if (_ValueCode.Length == 0) throw new Exception(\"无效的字符集!\" + p_Text.Substring(0, 1).ToString());\n _Text += _ValueCode;\n _TextNumb.Add(_Temp);\n p_Text = p_Text.Remove(0, 1);\n }\n break;\n }\n if (_TextNumb.Count == 0) throw new Exception(\"错误的编码,无数据\");\n _Text = _Text.Insert(0, GetValue(_Examine)); //获取开始位\n\n for (int i = 0; i != _TextNumb.Count; i++)\n {\n _Examine += _TextNumb[i] * (i + 1);\n }\n _Examine = _Examine % 103; //获得严效位\n _Text += GetValue(_Examine); //获取严效位\n _Text += \"2331112\"; //结束位\n Bitmap _CodeImage = GetImage(_Text, _ViewText,g);\n //GetViewText(_CodeImage, _ViewText);\n return _CodeImage;\n }\n /// <summary>\n /// 获取目标对应的数据\n /// </summary>\n /// <param name=\"p_Code\">编码</param>\n /// <param name=\"p_Value\">数值 A b 30</param>\n /// <param name=\"p_SetID\">返回编号</param>\n /// <returns>编码</returns>\n private string GetValue(Encode p_Code, string p_Value, ref int p_SetID)\n {\n if (m_Code128 == null) return \"\";\n DataRow[] _Row = m_Code128.Select(p_Code.ToString() + \"='\" + p_Value + \"'\");\n if (_Row.Length != 1) throw new Exception(\"错误的编码\" + p_Value.ToString());\n p_SetID = Int32.Parse(_Row[0][\"ID\"].ToString());\n return _Row[0][\"BandCode\"].ToString();\n }\n /// <summary>\n /// 根据编号获得条纹\n /// </summary>\n /// <param name=\"p_CodeId\"></param>\n /// <returns></returns>\n private string GetValue(int p_CodeId)\n {\n DataRow[] _Row = m_Code128.Select(\"ID='\" + p_CodeId.ToString() + \"'\");\n if (_Row.Length != 1) throw new Exception(\"验效位的编码错误\" + p_CodeId.ToString());\n return _Row[0][\"BandCode\"].ToString();\n }\n /// <summary>\n /// 获得条码图形\n /// </summary>\n /// <param name=\"p_Text\">文字</param>\n /// <returns>图形</returns>\n private Bitmap GetImage(string p_Text, string sourceText,Graphics g=null)\n {\n char[] _Value = p_Text.ToCharArray();\n int _Width = 0;\n for (int i = 0; i != _Value.Length; i++)\n {\n _Width += Int32.Parse(_Value[i].ToString()) * (m_Magnify + 1);\n }\n Bitmap _CodeImage = new Bitmap(_Width+4 , (int)m_Height + 12);\n Graphics _Garphics = g;\n //Pen _Pen;\n int _LenEx = 6;\n int _TopEx = 4;\n if (g == null)\n {\n Graphics.FromImage(_CodeImage);\n _LenEx = 2;\n _TopEx = 0;\n }\n\n for (int i = 0; i != _Value.Length; i++)\n {\n int _ValueNumb = Int32.Parse(_Value[i].ToString()) * (m_Magnify + 1); //获取宽和放大系数\n if (!((i & 1) == 0))\n {\n //_Pen = new Pen(Brushes.White, _ValueNumb);\n _Garphics.FillRectangle(Brushes.White, new Rectangle(_LenEx, _TopEx, _ValueNumb, (int)m_Height));\n }\n else\n {\n //_Pen = new Pen(Brushes.Black, _ValueNumb);\n _Garphics.FillRectangle(Brushes.Black, new Rectangle(_LenEx, _TopEx, _ValueNumb, (int)m_Height));\n }\n //_Garphics.(_Pen, new Point(_LenEx, 0), new Point(_LenEx, m_Height));\n _LenEx += _ValueNumb;\n }\n _Garphics.DrawString(sourceText, new Font(\"宋体\", 10f), new SolidBrush(Color.Black), new PointF(2, m_Height+_TopEx));\n if (_Garphics != g)\n {\n _Garphics.Dispose();\n }\n return _CodeImage;\n }\n /// <summary>\n /// 显示可见条码文字 如果小于40 不显示文字\n /// </summary>\n /// <param name=\"p_Bitmap\">图形</param> \n private void GetViewText(Bitmap p_Bitmap, string p_ViewText)\n {\n if (m_ValueFont == null) return;\n\n Graphics _Graphics = Graphics.FromImage(p_Bitmap);\n SizeF _DrawSize = _Graphics.MeasureString(p_ViewText, m_ValueFont);\n if (_DrawSize.Height > p_Bitmap.Height - 10 || _DrawSize.Width > p_Bitmap.Width)\n {\n _Graphics.Dispose();\n return;\n }\n\n int _StarY = p_Bitmap.Height - (int)_DrawSize.Height;\n _Graphics.FillRectangle(Brushes.White, new Rectangle(0, _StarY, p_Bitmap.Width, (int)_DrawSize.Height));\n _Graphics.DrawString(p_ViewText, m_ValueFont, Brushes.Black, 0, _StarY);\n }\n\n //12345678\n //(105 + (1 * 12 + 2 * 34 + 3 * 56 + 4 *78)) % 103 = 47\n //结果为starc +12 +34 +56 +78 +47 +end\n\n\n}\n\n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet">using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
public class Code128
{
private DataTable m_Code128 = new DataTable();
private uint m_Height = 40;
/// <summary>
/// 高度
/// </summary>
public uint Height { get { return m_Height; } set { m_Height = value; } }
private Font m_ValueFont = null;
/// <summary>
/// 是否显示可见号码 如果为NULL不显示号码
/// </summary>
public Font ValueFont { get { return m_ValueFont; } set { m_ValueFont = value; } }
private byte m_Magnify = 0;
/// <summary>
/// 放大倍数
/// </summary>
public byte Magnify { get { return m_Magnify; } set { m_Magnify = value; } }
/// <summary>
/// 条码类别
/// </summary>
public enum Encode
{
Code128A,
Code128B,
Code128C,
EAN128
}
public Code128()
{
m_Code128.Columns.Add("ID");
m_Code128.Columns.Add("Code128A");
m_Code128.Columns.Add("Code128B");
m_Code128.Columns.Add("Code128C");
m_Code128.Columns.Add("BandCode");
m_Code128.CaseSensitive = true;
#region 数据表
m_Code128.Rows.Add("0", " ", " ", "00", "212222");
m_Code128.Rows.Add("1", "!", "!", "01", "222122");
m_Code128.Rows.Add("2", "\"", "\"", "02", "222221");
m_Code128.Rows.Add("3", "#", "#", "03", "121223");
m_Code128.Rows.Add("4", "$", "$", "04", "121322");
m_Code128.Rows.Add("5", "%", "%", "05", "131222");
m_Code128.Rows.Add("6", "&", "&", "06", "122213");
m_Code128.Rows.Add("7", "'", "'", "07", "122312");
m_Code128.Rows.Add("8", "(", "(", "08", "132212");
m_Code128.Rows.Add("9", ")", ")", "09", "221213");
m_Code128.Rows.Add("10", "*", "*", "10", "221312");
m_Code128.Rows.Add("11", "+", "+", "11", "231212");
m_Code128.Rows.Add("12", ",", ",", "12", "112232");
m_Code128.Rows.Add("13", "-", "-", "13", "122132");
m_Code128.Rows.Add("14", ".", ".", "14", "122231");
m_Code128.Rows.Add("15", "/", "/", "15", "113222");
m_Code128.Rows.Add("16", "0", "0", "16", "123122");
m_Code128.Rows.Add("17", "1", "1", "17", "123221");
m_Code128.Rows.Add("18", "2", "2", "18", "223211");
m_Code128.Rows.Add("19", "3", "3", "19", "221132");
m_Code128.Rows.Add("20", "4", "4", "20", "221231");
m_Code128.Rows.Add("21", "5", "5", "21", "213212");
m_Code128.Rows.Add("22", "6", "6", "22", "223112");
m_Code128.Rows.Add("23", "7", "7", "23", "312131");
m_Code128.Rows.Add("24", "8", "8", "24", "311222");
m_Code128.Rows.Add("25", "9", "9", "25", "321122");
m_Code128.Rows.Add("26", ":", ":", "26", "321221");
m_Code128.Rows.Add("27", ";", ";", "27", "312212");
m_Code128.Rows.Add("28", "<", "<", "28", "322112");
m_Code128.Rows.Add("29", "=", "=", "29", "322211");
m_Code128.Rows.Add("30", ">", ">", "30", "212123");
m_Code128.Rows.Add("31", "?", "?", "31", "212321");
m_Code128.Rows.Add("32", "@", "@", "32", "232121");
m_Code128.Rows.Add("33", "A", "A", "33", "111323");
m_Code128.Rows.Add("34", "B", "B", "34", "131123");
m_Code128.Rows.Add("35", "C", "C", "35", "131321");
m_Code128.Rows.Add("36", "D", "D", "36", "112313");
m_Code128.Rows.Add("37", "E", "E", "37", "132113");
m_Code128.Rows.Add("38", "F", "F", "38", "132311");
m_Code128.Rows.Add("39", "G", "G", "39", "211313");
m_Code128.Rows.Add("40", "H", "H", "40", "231113");
m_Code128.Rows.Add("41", "I", "I", "41", "231311");
m_Code128.Rows.Add("42", "J", "J", "42", "112133");
m_Code128.Rows.Add("43", "K", "K", "43", "112331");
m_Code128.Rows.Add("44", "L", "L", "44", "132131");
m_Code128.Rows.Add("45", "M", "M", "45", "113123");
m_Code128.Rows.Add("46", "N", "N", "46", "113321");
m_Code128.Rows.Add("47", "O", "O", "47", "133121");
m_Code128.Rows.Add("48", "P", "P", "48", "313121");
m_Code128.Rows.Add("49", "Q", "Q", "49", "211331");
m_Code128.Rows.Add("50", "R", "R", "50", "231131");
m_Code128.Rows.Add("51", "S", "S", "51", "213113");
m_Code128.Rows.Add("52", "T", "T", "52", "213311");
m_Code128.Rows.Add("53", "U", "U", "53", "213131");
m_Code128.Rows.Add("54", "V", "V", "54", "311123");
m_Code128.Rows.Add("55", "W", "W", "55", "311321");
m_Code128.Rows.Add("56", "X", "X", "56", "331121");
m_Code128.Rows.Add("57", "Y", "Y", "57", "312113");
m_Code128.Rows.Add("58", "Z", "Z", "58", "312311");
m_Code128.Rows.Add("59", "[", "[", "59", "332111");
m_Code128.Rows.Add("60", "\\", "\\", "60", "314111");
m_Code128.Rows.Add("61", "]", "]", "61", "221411");
m_Code128.Rows.Add("62", "^", "^", "62", "431111");
m_Code128.Rows.Add("63", "_", "_", "63", "111224");
m_Code128.Rows.Add("64", "NUL", "`", "64", "111422");
m_Code128.Rows.Add("65", "SOH", "a", "65", "121124");
m_Code128.Rows.Add("66", "STX", "b", "66", "121421");
m_Code128.Rows.Add("67", "ETX", "c", "67", "141122");
m_Code128.Rows.Add("68", "EOT", "d", "68", "141221");
m_Code128.Rows.Add("69", "ENQ", "e", "69", "112214");
m_Code128.Rows.Add("70", "ACK", "f", "70", "112412");
m_Code128.Rows.Add("71", "BEL", "g", "71", "122114");
m_Code128.Rows.Add("72", "BS", "h", "72", "122411");
m_Code128.Rows.Add("73", "HT", "i", "73", "142112");
m_Code128.Rows.Add("74", "LF", "j", "74", "142211");
m_Code128.Rows.Add("75", "VT", "k", "75", "241211");
m_Code128.Rows.Add("76", "FF", "I", "76", "221114");
m_Code128.Rows.Add("77", "CR", "m", "77", "413111");
m_Code128.Rows.Add("78", "SO", "n", "78", "241112");
m_Code128.Rows.Add("79", "SI", "o", "79", "134111");
m_Code128.Rows.Add("80", "DLE", "p", "80", "111242");
m_Code128.Rows.Add("81", "DC1", "q", "81", "121142");
m_Code128.Rows.Add("82", "DC2", "r", "82", "121241");
m_Code128.Rows.Add("83", "DC3", "s", "83", "114212");
m_Code128.Rows.Add("84", "DC4", "t", "84", "124112");
m_Code128.Rows.Add("85", "NAK", "u", "85", "124211");
m_Code128.Rows.Add("86", "SYN", "v", "86", "411212");
m_Code128.Rows.Add("87", "ETB", "w", "87", "421112");
m_Code128.Rows.Add("88", "CAN", "x", "88", "421211");
m_Code128.Rows.Add("89", "EM", "y", "89", "212141");
m_Code128.Rows.Add("90", "SUB", "z", "90", "214121");
m_Code128.Rows.Add("91", "ESC", "{", "91", "412121");
m_Code128.Rows.Add("92", "FS", "|", "92", "111143");
m_Code128.Rows.Add("93", "GS", "}", "93", "111341");
m_Code128.Rows.Add("94", "RS", "~", "94", "131141");
m_Code128.Rows.Add("95", "US", "DEL", "95", "114113");
m_Code128.Rows.Add("96", "FNC3", "FNC3", "96", "114311");
m_Code128.Rows.Add("97", "FNC2", "FNC2", "97", "411113");
m_Code128.Rows.Add("98", "SHIFT", "SHIFT", "98", "411311");
m_Code128.Rows.Add("99", "CODEC", "CODEC", "99", "113141");
m_Code128.Rows.Add("100", "CODEB", "FNC4", "CODEB", "114131");
m_Code128.Rows.Add("101", "FNC4", "CODEA", "CODEA", "311141");
m_Code128.Rows.Add("102", "FNC1", "FNC1", "FNC1", "411131");
m_Code128.Rows.Add("103", "StartA", "StartA", "StartA", "211412");
m_Code128.Rows.Add("104", "StartB", "StartB", "StartB", "211214");
m_Code128.Rows.Add("105", "StartC", "StartC", "StartC", "211232");
m_Code128.Rows.Add("106", "Stop", "Stop", "Stop", "2331112");
#endregion
}
/// <summary>
/// 获取128图形
/// </summary>
/// <param name="p_Text">文字</param>
/// <param name="p_Code">编码</param>
/// <returns>图形</returns>
public Bitmap GetCodeImage(string p_Text, Encode p_Code,Graphics g=null)
{
string _ViewText = p_Text;
string _Text = "";
IList<int> _TextNumb = new List<int>();
int _Examine = 0; //首位
switch (p_Code)
{
case Encode.Code128C:
_Examine = 105;
if (!((p_Text.Length & 1) == 0)) throw new Exception("128C长度必须是偶数");
while (p_Text.Length != 0)
{
int _Temp = 0;
try
{
int _CodeNumb128 = Int32.Parse(p_Text.Substring(0, 2));
}
catch
{
throw new Exception("128C必须是数字!");
}
_Text += GetValue(p_Code, p_Text.Substring(0, 2), ref _Temp);
_TextNumb.Add(_Temp);
p_Text = p_Text.Remove(0, 2);
}
break;
case Encode.EAN128:
_Examine = 105;
if (!((p_Text.Length & 1) == 0)) throw new Exception("EAN128长度必须是偶数");
_TextNumb.Add(102);
_Text += "411131";
while (p_Text.Length != 0)
{
int _Temp = 0;
try
{
int _CodeNumb128 = Int32.Parse(p_Text.Substring(0, 2));
}
catch
{
throw new Exception("128C必须是数字!");
}
_Text += GetValue(Encode.Code128C, p_Text.Substring(0, 2), ref _Temp);
_TextNumb.Add(_Temp);
p_Text = p_Text.Remove(0, 2);
}
break;
default:
if (p_Code == Encode.Code128A)
{
_Examine = 103;
}
else
{
_Examine = 104;
}
while (p_Text.Length != 0)
{
int _Temp = 0;
string _ValueCode = GetValue(p_Code, p_Text.Substring(0, 1), ref _Temp);
if (_ValueCode.Length == 0) throw new Exception("无效的字符集!" + p_Text.Substring(0, 1).ToString());
_Text += _ValueCode;
_TextNumb.Add(_Temp);
p_Text = p_Text.Remove(0, 1);
}
break;
}
if (_TextNumb.Count == 0) throw new Exception("错误的编码,无数据");
_Text = _Text.Insert(0, GetValue(_Examine)); //获取开始位
for (int i = 0; i != _TextNumb.Count; i++)
{
_Examine += _TextNumb[i] * (i + 1);
}
_Examine = _Examine % 103; //获得严效位
_Text += GetValue(_Examine); //获取严效位
_Text += "2331112"; //结束位
Bitmap _CodeImage = GetImage(_Text, _ViewText,g);
//GetViewText(_CodeImage, _ViewText);
return _CodeImage;
}
/// <summary>
/// 获取目标对应的数据
/// </summary>
/// <param name="p_Code">编码</param>
/// <param name="p_Value">数值 A b 30</param>
/// <param name="p_SetID">返回编号</param>
/// <returns>编码</returns>
private string GetValue(Encode p_Code, string p_Value, ref int p_SetID)
{
if (m_Code128 == null) return "";
DataRow[] _Row = m_Code128.Select(p_Code.ToString() + "='" + p_Value + "'");
if (_Row.Length != 1) throw new Exception("错误的编码" + p_Value.ToString());
p_SetID = Int32.Parse(_Row[0]["ID"].ToString());
return _Row[0]["BandCode"].ToString();
}
/// <summary>
/// 根据编号获得条纹
/// </summary>
/// <param name="p_CodeId"></param>
/// <returns></returns>
private string GetValue(int p_CodeId)
{
DataRow[] _Row = m_Code128.Select("ID='" + p_CodeId.ToString() + "'");
if (_Row.Length != 1) throw new Exception("验效位的编码错误" + p_CodeId.ToString());
return _Row[0]["BandCode"].ToString();
}
/// <summary>
/// 获得条码图形
/// </summary>
/// <param name="p_Text">文字</param>
/// <returns>图形</returns>
private Bitmap GetImage(string p_Text, string sourceText,Graphics g=null)
{
char[] _Value = p_Text.ToCharArray();
int _Width = 0;
for (int i = 0; i != _Value.Length; i++)
{
_Width += Int32.Parse(_Value[i].ToString()) * (m_Magnify + 1);
}
Bitmap _CodeImage = new Bitmap(_Width+4 , (int)m_Height + 12);
Graphics _Garphics = g;
//Pen _Pen;
int _LenEx = 6;
int _TopEx = 4;
if (g == null)
{
Graphics.FromImage(_CodeImage);
_LenEx = 2;
_TopEx = 0;
}
for (int i = 0; i != _Value.Length; i++)
{
int _ValueNumb = Int32.Parse(_Value[i].ToString()) * (m_Magnify + 1); //获取宽和放大系数
if (!((i & 1) == 0))
{
//_Pen = new Pen(Brushes.White, _ValueNumb);
_Garphics.FillRectangle(Brushes.White, new Rectangle(_LenEx, _TopEx, _ValueNumb, (int)m_Height));
}
else
{
//_Pen = new Pen(Brushes.Black, _ValueNumb);
_Garphics.FillRectangle(Brushes.Black, new Rectangle(_LenEx, _TopEx, _ValueNumb, (int)m_Height));
}
//_Garphics.(_Pen, new Point(_LenEx, 0), new Point(_LenEx, m_Height));
_LenEx += _ValueNumb;
}
_Garphics.DrawString(sourceText, new Font("宋体", 10f), new SolidBrush(Color.Black), new PointF(2, m_Height+_TopEx));
if (_Garphics != g)
{
_Garphics.Dispose();
}
return _CodeImage;
}
/// <summary>
/// 显示可见条码文字 如果小于40 不显示文字
/// </summary>
/// <param name="p_Bitmap">图形</param>
private void GetViewText(Bitmap p_Bitmap, string p_ViewText)
{
if (m_ValueFont == null) return;
Graphics _Graphics = Graphics.FromImage(p_Bitmap);
SizeF _DrawSize = _Graphics.MeasureString(p_ViewText, m_ValueFont);
if (_DrawSize.Height > p_Bitmap.Height - 10 || _DrawSize.Width > p_Bitmap.Width)
{
_Graphics.Dispose();
return;
}
int _StarY = p_Bitmap.Height - (int)_DrawSize.Height;
_Graphics.FillRectangle(Brushes.White, new Rectangle(0, _StarY, p_Bitmap.Width, (int)_DrawSize.Height));
_Graphics.DrawString(p_ViewText, m_ValueFont, Brushes.Black, 0, _StarY);
}
//12345678
//(105 + (1 * 12 + 2 * 34 + 3 * 56 + 4 *78)) % 103 = 47
//结果为starc +12 +34 +56 +78 +47 +end
}
- 评论:0 / 阅读:702
-
- 技术文摘不用写一句sql的ORM框架,支持多种数据库
- 2021/4/12 11:59:22
- ...27.0.0.1;database=ormcms;uid=root;pwd=abc123123;oldsyntax=true;charset=utf8;Allow Zero Datetime=True;port=3306;" /> 2、定义一个类文件(这个文件可以自己用代码生成器生成,后面会开放下载)//------------------------------------------------------------------------------
//
// 此代码由工具生成:
// 生成时间:2021/3/17
// 创建人:XuKai
//
using System;
using Xk.ORM;
namespace CMS.Models
{
///
/// *实体类:ktcfriendlink
///
[Table("ktcfriendlink")]
[Serializable]
public partial class Ktcfriendlink : Entity
{
#region Model
private int _Id;
///
/// 主键id
///
[Field("id")]
public int Id
{
get { return _Id; }
set
{
this.OnPropertyValueChange("id");
this._Id = value;
}
}
private string _Title;
///
/// 友链标题
///
[Field("title")]
public string Title
{
get { return _Title; }
set
{
this.OnPropertyValueChange("title");
this._Title = value;
}
}
private string _Desc;
///
/// 描述
///
[Field("desc")]
public string Desc
{
get { return _Desc; }
set
{
this.OnPropertyValueChange("desc");
this._Desc = value;
}
}
private string _Url;
///
/// 友链地址
///
[Field("url")]
public string Url
{
get { return _Url; }
set
{
this.OnPropertyValueChange("url");
this._Url = value;
}
}
private int _Status;
///
/// 1 通过,2 不通过,0 未审核
///
[Field("status")]
public int Status
{
get { return _Status; }
set
{
this.OnPropertyValueChange("status");
this._Status = value;
}
}
private DateTime _Createtime;
///
/// 创建时间
///
[Field("createtime")]
public DateTime Createtime
{
get { return _Createtime; }
set
{
this.OnPropertyValueChange("createtime");
this._Createtime = value;
}
}
private DateTime _Authtime;
///
/// 审核时间
///
[Field("authtime")]
public DateTime Authtime
{
get { return _Authtime; }
set
{
this.OnPropertyValueChange("authtime");
this._Authtime = value;
}
}
private string _Askdesc;
///
/// 申请描述
///
[Field("askdesc")]
public string Askdesc
{
get { return _Askdesc; }
set
{
this.OnPropertyValueChange("askdesc");
this._Askdesc = value;
}
}
private string _Imgurl;
///
/// 友链图片封面
///
[Field("imgurl")]
public string Imgurl
{
get { return _Imgurl; }
set
{
this.OnPropertyValueChange("imgurl");
this._Imgurl = value;
}
}
private int _Index;
///
/// 排序
///
[Field("index")]
public int Index
{
get { return _Index; }
set
{
this.OnPropertyValueChange("index");
this._Index = value;
}
}
private int _Isimg;
///
/// 是否为图片链接,1 是,0 否(文本)
///
[Field("isimg")]
public int Isimg
{
get { return _Isimg; }
set
{
this.OnPropertyValueChange("isimg");
this._Isimg = value;
}
}
private string _Email;
///
/// 对方的站点url
///
[Field("email")]
public string Email
{
get { return _Email; }
set
{
this.OnPropertyValueChange("email");
this._Email = value;
}
}
#endregion
#region Method
///
/// 获取实体中的主键列
///
public override Field[] GetPrimaryKeyFields()
{
return new Field[] {
_.Id,
};
}
///
/// 获取列信息
///
public override Field[] GetFields()
{
return new Field[] {
_.Id,
_.Title,
_.Desc,
_.Url,
_.Status,
_.Createtime,
_.Authtime,
_.Askdesc,
_.Imgurl,
_.Index,
_.Isimg,
_.Email
};
}
///
/// 获取值信息
///
public override object[] GetValues()
{
return new object[] {
this._Id,
this._Title,
this._Desc,
this._Url,
this._Status,
this._Createtime,
this._Authtime,
this._Askdesc,
this._Imgurl,
this._Index,
this._Isimg,
this._Email
};
}
#endregion
#region _Field
///
/// 字段信息
///
public class _
{
///
/// *
///
public readonly static Field All = new Field("*", "ktcfriendlink");
///
/// 主键id
///
public readonly static Field Id = new Field("id", "ktcfriendlink");
///
/// 友链标题
///
public readonly static Field Title = new Field("title", "ktcfriendlink");
///
/// 描述
///
public readonly static Field Desc = new Field("desc", "ktcfriendlink");
///
/// 友链地址
///
public readonly static Field Url = new Field("url", "ktcfriendlink");
///
/// 1 通过,2 不通过,0 未审核
///
public readonly static Field Status = new Field("status", "ktcfriendlink");
///
/// 创建时间
///
public readonly static Field Createtime = new Field("createtime", "ktcfriendlink");
///
/// 审核时间
///
public readonly static Field Authtime = new Field("authtime", "ktcfriendlink");
///
/// 申请描述
///
public readonly static Field Askdesc = new Field("askdesc", "ktcfriendlink");
///
/// 友链图片封面
///
public readonly static Field Imgurl = new Field("imgurl", "ktcfriendlink");
///
/// 排序
///
public readonly static Field Index = new Field("index", "ktcfriendlink");
///
/// 是否为图片链接,1 是,0 否(文本)
///
public readonly static Field Isimg = new Field("isimg", "ktcfriendlink");
///
/// 对方的联系邮箱
///
public readonly static Field Email = new Field("email", "ktcfriendlink");
}
#endregion
}
}
3、cuid操作int i = 0;
DbHelper.From<Ktcfriendlink>();//查询表所有数据 DbHelper.From<Ktcfriendlink>().Where(t => t.Id == 1);//条件id为1的数据,参数遵循linq语法。 DbHelper.From<Ktcfriendlink>().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。 Ktcfriendlink model = new Ktcfriendlink();
model.Title = "baidu";
model.Url = "www.baidu.com";
i = DbHelper.Insert(model);//插入一条数据
i = DbHelper.Delete(a => a.Id == 1);//删除id为1的数据
model.Title = "taobao";
i = DbHelper.Update(model);
DbHelper.FromProc("procname");//可以执行存储过程
DbTrans trans = DbHelper.BeginTransaction();//执行事务
try
{
trans.Update(Ktcfriendlink._.Title, "google", a => a.Id == 1);
trans.Update(Ktcfriendlink._.Title, "yahoo", a => a.Id == 2);
trans.Commit();//提交事务
}
catch
{
trans.Rollback();//回滚事务
}
finally
{
trans.Close();
} Ktcfriendlink model = new Ktcfriendlink();
model.Title = "baidu";
model.Url = "www.baidu.com";
i = DbHelper.Insert(model);//插入一条数据
i = DbHelper.Delete(a => a.Id == 1);//删除id为1的数据
model.Title = "taobao";
i = DbHelper.Update(model);
DbHelper.FromProc("procname");//可以执行存储过程
DbTrans trans = DbHelper.BeginTransaction();//执行事务
try
{
trans.Update(Ktcfriendlink._.Title, "google", a => a.Id == 1);
trans.Update(Ktcfriendlink._.Title, "yahoo", a => a.Id == 2);
trans.Commit();//提交事务
}
catch
{
trans.Rollback();//回滚事务
}
finally
{
trans.Close();
} DbHelper.From().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。
Ktcfriendlink model = new Ktcfriendlink();
model.Title = "baidu";
model.Url = "www.baidu.com";
i = DbHelper.Insert(model);//插入一条数据
i = DbHelper.Delete(a => a.Id == 1);//删除id为1的数据
model.Title = "taobao";
i = DbHelper.Update(model);
DbHelper.FromProc("procname");//可以执行存储过程
DbTrans trans = DbHelper.BeginTransaction();//执行事务
try
{
trans.Update(Ktcfriendlink._.Title, "google", a => a.Id == 1);
trans.Update(Ktcfriendlink._.Title, "yahoo", a => a.Id == 2);
trans.Commit();//提交事务
}
catch
{
trans.Rollback();//回滚事务
}
finally
{
trans.Close();
} DbHelper.From().Where(t => t.Id == 1);//条件id为1的数据,参数遵循linq语法。
DbHelper.From().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。
Ktcfriendlink model = new Ktcfriendlink();
model.Title = "baidu";
model.Url = "www.baidu.com";
i = DbHelper.Insert(model);//插入一条数据
i = DbHelper.Delete(a => a.Id == 1);//删除id为1的数据
model.Title = "taobao";
i = DbHelper.Update(model);
DbHelper.FromProc("procname");//可以执行存储过程
DbTrans trans = DbHelper.BeginTransaction();//执行事务
try
{
trans.Update(Ktcfriendlink._.Title, "google", a => a.Id == 1);
trans.Update(Ktcfriendlink._.Title, "yahoo", a => a.Id == 2);
trans.Commit();//提交事务
}
catch
{
trans.Rollback();//回滚事务
}
finally
{
trans.Close();
}框架后期整理好后开放下载,欢迎广大.net ORM爱好者使用
- 评论:1 / 阅读:1353
-
- 技术文摘123
- 2021/5/24 16:10:46
- 评论:0 / 阅读:469