示例#1
0
        /// <summary>
        /// 打印委托
        /// </summary>
        /// <param name="g">Graphics</param>
        /// <param name="num">打印第几条</param>
        /// <param name="a">是否继续打印</param>
        private void DrawContent(Graphics g, int num, ref bool a)
        {
            //获得打印数据
            if (num < 0)
            {
                return;
            }
            BarCodeBean barCodeBean = this._printDataList[num];

            //打印基本设置
            int  pageLeft   = Convert.ToInt32(_printSetting.PageLeft) * 4;
            int  pageTop    = Convert.ToInt32(_printSetting.PageTop) * 4;
            uint codeHeight = Convert.ToUInt32(_printSetting.BarCodeHeight) * 4;
            int  wordSize   = Convert.ToInt32(_printSetting.WordSize);
            int  codeSize   = Convert.ToInt32(_printSetting.BarCodeSize);
            Font wordFont   = new Font(_printSetting.WordType, wordSize);
            Font wordFont2  = new Font(_printSetting.WordType, wordSize + 2);
            Font codeFont   = new Font(_printSetting.WordType, codeSize);

            //画出打印内容
            g.DrawString(barCodeBean.Grade, wordFont2, Brushes.Black, pageLeft + 182, pageTop + 8);
            g.DrawString(barCodeBean.Brand, wordFont, Brushes.Black, pageLeft + 190, pageTop + 54);

            BarCode barCode = new BarCode();

            barCode.ValueFont = codeFont;
            barCode.Height    = codeHeight;
            System.Drawing.Bitmap imgBarCode = barCode.GetCodeImage(barCodeBean.BarCode, BarCode.Encode.Code128C);
            g.DrawImage(imgBarCode, pageLeft, pageTop + 255);
            g.DrawString(barCodeBean.ReadCode, codeFont, Brushes.Black, pageLeft, pageTop + 258 + imgBarCode.Height);
        }
示例#2
0
        /// <summary>
        /// json对象转为list对象
        /// </summary>
        /// <param name="jsonData">json对象</param>
        /// <returns>list对象</returns>
        private List <BarCodeBean> ConvertToList(JObject jsonData)
        {
            List <BarCodeBean> dataList = new List <BarCodeBean>();
            BarCodeBean        bean;

            foreach (JToken jt in jsonData.GetValue("result").Children())
            {
                bean           = new BarCodeBean();
                bean.BarcodeId = _barcodeId;
                bean.Grade     = jt["grade"].ToString();
                bean.Brand     = jt["brand"].ToString();
                bean.BarCode   = jt["barcode"].ToString();
                bean.ReadCode  = jt["readcode"].ToString();
                dataList.Add(bean);
            }
            return(dataList);
        }
示例#3
0
        /// <summary>
        /// 选择文件按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            //初始化一个OpenFileDialog类
            OpenFileDialog fileDialog = new OpenFileDialog();

            //判断用户是否正确的选择了文件
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                //获取用户选择文件的后缀名
                string extension = Path.GetExtension(fileDialog.FileName);
                //声明允许的后缀名
                string[] str = new string[] { ".csv" };
                if (!((IList)str).Contains(extension))
                {
                    MessageBox.Show("仅能上传csv格式的文件!");
                }
                else
                {
                    //获取用户选择的文件,并判断文件大小不能超过2000K,fileInfo.Length是以字节为单位的
                    FileInfo fileInfo = new FileInfo(fileDialog.FileName);
                    if (fileInfo.Length > 2097152)
                    {
                        MessageBox.Show("上传的文件不能大于2M");
                    }
                    else
                    {
                        List <String[]> list = CSVFileHelper.ReadCSV(fileInfo);

                        _printDataList = new List <BarCodeBean>();
                        BarCodeBean bean;
                        int         rowNo = 1;
                        foreach (string[] data in list)
                        {
                            if (data.Length > 4)
                            {
                                bean           = new BarCodeBean();
                                bean.RowNo     = rowNo;
                                bean.BarcodeId = data[0].Replace("\"", "");
                                bean.BarCode   = data[1].Replace("\"", "");
                                bool isNum = isBarCode(bean.BarCode);
                                if (!isNum)
                                {
                                    continue;
                                }
                                bean.ReadCode = data[2].Replace("\"", "");
                                bean.Brand    = data[3].Replace("\"", "");
                                bean.Grade    = data[4].Replace("\"", "");
                                _printDataList.Add(bean);
                                rowNo++;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        this.lblMessage.Text  = "文件已选择:\n";
                        this.lblMessage.Text += fileDialog.FileName;
                        this.lblMessage.Text += "\n";
                        this.lblMessage.Text += "共需打印 " + _printDataList.Count().ToString() + " 个标签!";

                        //设置名称
                        string strName = fileDialog.FileName.Split('\\').LastOrDefault().ToString();
                        _fileName = strName.Split('.').FirstOrDefault().ToString();
                    }
                }
            }
        }
示例#4
0
 private void SelectData(BarCodeBean bean)
 {
     bean.IsPrint = true;
 }