public FrmBarcodeEdit(string strFileName) { InitializeComponent(); userControlCanvas1.Loader(strFileName); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); //我自己的初始化 myInit(); }
//private string _strTemplet = @"<Shapes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><arrlistShapeEle/><BarcodePageSettings><arrModelShapes><string>方形</string><string>圆角矩形</string><string>椭圆形</string><string>CD</string></arrModelShapes><ModelShapes>圆角矩形</ModelShapes><BarcodePaperLayout><strError/><BarcodePaperSize><Height>1169</Height><PaperName>A4</PaperName><RawKind>9</RawKind><Width>827</Width></BarcodePaperSize><NumberOfLine>2</NumberOfLine><NumberOfColumn>2</NumberOfColumn><Top>2</Top><Left>2</Left><Right>2</Right><Bottom>2</Bottom><ModelWidth>102</ModelWidth><ModelHeight>146.5</ModelHeight><CustomModelSize>false</CustomModelSize><HorizontalInterval>2</HorizontalInterval><VerticalInterval>0</VerticalInterval><CornerRadius>2</CornerRadius><CustomDistance>true</CustomDistance></BarcodePaperLayout></BarcodePageSettings><arrlistKeyValue/><Zoom>0.97</Zoom></Shapes>" public FrmBarcodeEdit() { InitializeComponent(); //新建的话也得有个打开啊。 string strFileName = Application.StartupPath + "\\BarcodeModel\\templet.barcode"; /** //如果不存在这个文件就新建一个,并且写入默认的 if (!File.Exists(strFileName)) { if (!Directory.Exists(Application.StartupPath + "\\BarcodeModel")) { Directory.CreateDirectory(Application.StartupPath + "\\BarcodeModel"); } using (Stream stream = new FileStream(strFileName, FileMode.Create)) { using (StreamWriter sw=new StreamWriter(stream)) { //sw.Write(_strTemplet); } } } * */ if (File.Exists(strFileName)) { userControlCanvas1.Loader(strFileName); } shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); //我自己的初始化自己的初始化中有放大到屏幕,这个容易出问题。,所以如下两个是吧设置工具和画布大小的放在这里来。 //myInit(); //设置工具可以操作画布的。 userControlToolBox1.setCanvas(userControlCanvas1); //设置画布的尺寸同布局大小 canvasResie(); ClsBarcodePrint c = new ClsBarcodePrint();//只是一个启动计时器的 if (ClsBarcodePrint.strPrinterName == "") { ClsBarcodePrint.strPrinterName = c.myPrintDocument.PrinterSettings.PrinterName;//默认打印机 } toolStripLabelPrintingName.Text = ClsBarcodePrint.strPrinterName;//默认打印机 }
private void btnPrint_Click_1(object sender, EventArgs e) { string strFileName; while (((shapesFileData.Key == "templet"))) { strFileName = userControlCanvas1.Saver(); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); if (strFileName == "") { MessageBox.Show("请先保存文件再打印,或许用“测试打印”不用保存"); return; } } strFileName = userControlCanvas1.Saver(shapesFileData.Value); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); //userControlCanvas1.Saver(shapesFileData.Value); int intPages = getCurrentPrintPages(); //只有大于零才打印 if (intPages > 0) { printBarcode(intPages); } }
// /// <summary> /// 加载程序配置,包括打印机名字,是否倒着打印,以及模板的路径 /// </summary> private void loadXmlAPP() { #region 如下的我打算用序列化来实现 /** if (!File.Exists(Application.StartupPath + "\\xmlAPP.xml")) { createXmlApp(); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Application.StartupPath + "\\xmlAPP.xml"); XmlElement xmlEle = xmlDoc.DocumentElement; foreach (XmlElement myxmlNode in xmlEle.ChildNodes) { string strNodeName = myxmlNode.Name; switch (strNodeName) { case "printer": //clsBarcodePrint.fltDPIX = clsBarcodePrint.strAttributeValueToFloat(myxmlNode, "DPIX"); //clsBarcodePrint.fltDPIY = clsBarcodePrint.strAttributeValueToFloat(myxmlNode, "DPIY"); //读取打印机的时候,得判断是否为空,如果为空就设置为默认打印机 string strPrintName_ = myxmlNode.GetAttribute("PrinterName"); if (strPrintName_ == "") { PrintDocument printDoc = new PrintDocument(); ClsBarcodePrint.strPrinterName = printDoc.PrinterSettings.PrinterName; } else { ClsBarcodePrint.strPrinterName = strPrintName_; } lblPrinterName.Text = ClsBarcodePrint.strPrinterName; break; case "xmlBarcodeModel"://条形码模板 string strPath = myxmlNode.Attributes["Path"].InnerText;//路径 //还得判断这个路径是否是相对路径 if (strPath.IndexOf(":") < 0) strPath = Application.StartupPath + "\\" + strPath; //去掉了没有的 if (File.Exists(strPath)) { clsKeyValue lt = new clsKeyValue(Path.GetFileNameWithoutExtension(strPath), strPath); comboBoxBarcodeModel.Items.Add(lt); } break; } } * */ #endregion //如下是用序列化实现的,如果存在文件就反序列化 if (File.Exists(Application.StartupPath + "\\xmlAPP.xml")) { try { using (Stream stream = new FileStream(Application.StartupPath + "\\xmlAPP.xml", FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlSerializer formatter = new XmlSerializer(typeof(ClsXmlApp)); myClsXmlApp = formatter.Deserialize(stream) as ClsXmlApp; } } catch (Exception exception) { ClsErrorFile.WriteLine("加载不成功,原因是" , exception); //MessageBox.Show("加载不成功,原因是" + exception.Message); } finally { } } //如下就是添加了。 if (myClsXmlApp != null) { PrintDocument printdoc = new PrintDocument(); //如果没有设置打印机就设置使用默认的打印机 if (myClsXmlApp.strPrintingName == null) { myClsXmlApp.strPrintingName = printdoc.PrinterSettings.PrinterName; } //显示选择的打印机,通常是用户选择要使用的, lblPrinterName.Text = myClsXmlApp.strPrintingName; //这个类也使用这个打印机配置 //如果没有设置打印机,就设置默认的打印机 ClsBarcodePrint.strPrinterName = myClsXmlApp.strPrintingName; foreach (string strPath in myClsXmlApp.arrlistBarcodeModel) { //去掉了没有的 if (File.Exists(strPath)) { clsKeyValue lt = new clsKeyValue(Path.GetFileNameWithoutExtension(strPath), strPath); comboBoxBarcodeModel.Items.Add(lt); } } //如果有模板,就设置第一个 if (comboBoxBarcodeModel.Items.Count > 0) { comboBoxBarcodeModel.Text = comboBoxBarcodeModel.Items[0].ToString(); //MessageBox.Show(comboBoxBarcodeModel.Items[0].ToString()); } } }
private void bindingNavigatorPositionItem_TextChanged(object sender, EventArgs e) { try { int intCurrentLine = Convert.ToInt32(bindingNavigatorPositionItem.Text);//取得当前行 ArrayList arrlist = new ArrayList(); foreach (DataColumn item in CurrentDataTable.Columns) { clsKeyValue keyvalue = new clsKeyValue(item.Caption,CurrentDataTable.Rows[intCurrentLine-1][item.Caption].ToString()); arrlist.Add(keyvalue); } //给画布更新变量信息。 setKeyValue(arrlist); //更新要打印数量。 txtQtyOfWantToPrinted.Text = CurrentDataTable.Rows[intCurrentLine - 1][comboBoxQtyOfWantToPrinted.Text].ToString(); } catch (Exception ex) { //ClsErrorFile.WriteLine(ex); //throw; } }
public FrmBarcodeEdit(clsKeyValue lt , DataTable dataTable , ArrayList arrlist , string tableName) { InitializeComponent(); //这个需要保存。 shapesFileData = lt; strTableName = tableName;//保存表名 //加载形状 userControlCanvas1.Loader(lt.Value); LoadDataTable(dataTable);//加载表格 //加载变量 setKeyValue(arrlist); //我自己的初始化 myInit(); }
private void printBarcode(int intPages) { ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); //如下的这个有些破坏了封装性,我用这个只是为了打印结束后判断是否自动打印。 //myBarcodePrint.myPrintDocument.EndPrint += new PrintEventHandler(myPrintDocument_EndPrint); //如下如下是将变量深拷贝 //如下这个只是复制一个值变量再传递 ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝 if (userControlCanvas1.myShapes.arrlistKeyValue != null) { foreach (clsKeyValue myKeyValue in userControlCanvas1.myShapes.arrlistKeyValue) { clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value); arrlist.Add(kv); } } //创建打印信息。 queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = strTableName; printDetails.ShapesFileName = (shapesFileData).Value; printDetails.IsFull = chkIsFull.Checked; queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = intPages; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); myBarcodePrint.addPrintDetails (printDetails); }
private void btnTestPrint_Click(object sender, EventArgs e) { try { //timer1.Enabled = false;//这个好像是没有必要 ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝 if (arrlistSellectRow != null) { foreach (clsKeyValue myKeyValue in arrlistSellectRow) { clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value); arrlist.Add(kv); } } //测试的话只打印一页就可以了。 ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = strCurrentTableName;//当前表 //如下是取得模板的路径 string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value; //还得判断是否是相对路径,我的简单判断方法是是否有冒号":" if (strPathName.IndexOf(":") < 0) { //还有得判断首字符是不是"\\",如果不是就加上 if (strPathName.Substring(0) == "\\") { strPathName = Application.StartupPath + strPathName; } else { strPathName = Application.StartupPath + "\\" + strPathName; } } printDetails.ShapesFileName = strPathName; printDetails.IsFull = chkIsFull.Checked; queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = 1; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); //queuePrintItem printDetails = new queuePrintItem("Test", ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, 1); // 添加到保存信息中。 myBarcodePrint.addPrintDetails(printDetails); } catch (Exception ex) { ClsErrorFile.WriteLine("测试打印出现异常",ex); //throw; } }
/// <summary> /// 保存 /// </summary> private void SaveBarcodeModel() { string strFileName; while (((shapesFileData.Key == "templet"))) { strFileName = userControlCanvas1.Saver(); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); if (strFileName == "") { MessageBox.Show("您没有选择文件"); return; } } strFileName = userControlCanvas1.Saver(shapesFileData.Value); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); }
/// <summary> /// 根据用户要求的的实际数量打印 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPrint_Click(object sender, EventArgs e) { int intPages = getCurrentPrintPages();//这个数量是钉死的 if (chkIsMulti.Checked) { //创建打印信息。 queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = strCurrentTableName; //如下是取得模板的路径 string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value; //还得判断是否是相对路径,我的简单判断方法是是否有冒号":" if (strPathName.IndexOf(":") < 0) { //还有得判断首字符是不是"\\",如果不是就加上 if (strPathName.Substring(0) == "\\") { strPathName = Application.StartupPath + strPathName; } else { strPathName = Application.StartupPath + "\\" + strPathName; } } printDetails.ShapesFileName = strPathName;//设置目录 printDetails.IsFull = chkIsFull.Checked; try { //得根据选中的行迭代 if (dataGridView1.SelectedRows.Count>0) { foreach (DataGridViewRow item in dataGridView1.SelectedRows) { ArrayList arrlist = new ArrayList(); //如下是构造数据的 for (int i = 0; i < dataGridView1.ColumnCount; i++) { clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, item.Cells[i].Value.ToString()); arrlist.Add(keyvalue); } //如下就是构造打印了。 queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = intPages; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); //queuePrintItem printDetails = new queuePrintItem(strCurrentTableName, ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, intPages); } } else { queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = null; queuePrintItemRowAndPages1.intPages = intPages; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); } ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); myBarcodePrint.addPrintDetails(printDetails); } catch (System.Exception ex) { ClsErrorFile.WriteLine(ex); } } else { //只有大于零才打印 if (intPages > 0) { printBarcode(intPages); } } /**如下的会产生问题,比如说在读取打印数量后已经抛出来一场,但结果还是打印了。 * timer1.Enabled = false; int intPages = 0; try { if (txtCurrentPrintPage.Text != "") { intPages = Convert.ToInt32(txtCurrentPrintPage.Text); printBarcode(intPages); } else { MessageBox.Show("请输入本次要打印的页数"); return; } } catch (Exception ex) { MessageBox.Show("不能取得打印数量,原因是" + ex.Message); } * */ }
private void btnSaveImage_Click(object sender, EventArgs e) { //这个到处图像跟打印部分绝大部分是相同的,如下的是先拷贝再修改的。 ArrayList arrlistRows = new ArrayList(); if (chkIsMulti.Checked) { //创建打印信息。 try { //得根据选中的行迭代 foreach (DataGridViewRow item in dataGridView1.SelectedRows) { ArrayList arrlist = new ArrayList(); //如下是构造数据的 for (int i = 0; i < dataGridView1.ColumnCount; i++) { clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, item.Cells[i].Value.ToString()); arrlist.Add(keyvalue); } arrlistRows.Add(arrlist); } } catch (System.Exception ex) { ClsErrorFile.WriteLine(ex); return; } } else { ArrayList arrlist = new ArrayList(); if (arrlistSellectRow != null) { foreach (clsKeyValue myKeyValue in arrlistSellectRow) { clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value); arrlist.Add(kv); } } arrlistRows.Add(arrlist); } FrmSaveImage f = new FrmSaveImage(((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value,arrlistRows); f.ShowDialog();//打开窗体 }
/// <summary> /// 按损耗打印 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPrint2_Click(object sender, EventArgs e) { //如果是选择多行,每一项都得判断有多少数据的 if (chkIsMulti.Checked) { try { queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = strCurrentTableName; //如下是取得模板的路径 string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value; //还得判断是否是相对路径,我的简单判断方法是是否有冒号":" if (strPathName.IndexOf(":") < 0) { //还有得判断首字符是不是"\\",如果不是就加上 if (strPathName.Substring(0) == "\\") { strPathName = Application.StartupPath + strPathName; } else { strPathName = Application.StartupPath + "\\" + strPathName; } } printDetails.ShapesFileName = strPathName; printDetails.IsFull = chkIsFull.Checked; //得根据选中的行迭代DataGridViewTextBoxCell foreach (DataGridViewRow item in dataGridView1.SelectedRows) { ArrayList arrlist = new ArrayList(); int intPages = 0;//默认打印0页 //如下是构造数据的 for (int i = 0; i < dataGridView1.ColumnCount; i++) { clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, item.Cells[i].Value.ToString()); arrlist.Add(keyvalue); //判断哪个是数量 if (dataGridView1.Columns[i].Name == comboBoxQtyOfWantToPrinted.Text) { try { intPages = Convert.ToInt32(item.Cells[i].Value.ToString()); } catch (System.Exception ex) { MessageBox.Show("读取不到数量,请在“要打印数量”后选择一项作为数量,这个是自动读取的,错误原因是:"+ex.Message); ClsErrorFile.WriteLine("读取不到数量,请在“要打印数量”后选择一项作为数量,这个是自动读取的,错误原因是:" + ex.Message); return; } } } //如下就是构造打印了。 //创建打印信息。 queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = intPages; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); } ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); myBarcodePrint.addPrintDetails(printDetails); } catch (System.Exception ex) { ClsErrorFile.WriteLine(ex); } } else { int intPages = getQtyOfWantToPrinted();//取得打印数量,加上损耗 if (intPages > 0) { timer1.Enabled = false; printBarcode(intPages); } } /** * 如下的会产生问题,比如说在读取打印数量时已经跑出异常了,但是还是系统还是崩溃了,所以加上如上判断 try { float fltSunHao = Convert.ToSingle(txtSunHao.Text)/100; int intPages = Convert.ToInt32(txtQtyOfWantToPrinted.Text); intPages += ((int)(intPages * fltSunHao)); printBarcode(intPages); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } * */ }
private void addXmlFileData(string strFileName) { //主要添加两个方向,一个是往选择框里添加,一个是往xmlapp文件中添加。 clsKeyValue keyvalue = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); comboBoxBarcodeModel.Items.Add(keyvalue); comboBoxBarcodeModel.SelectedItem = keyvalue; /**如下的也注释掉了。改为序列化。 //保存早xmlapp文件中。 //因为会有文件异常,所以 XmlDocument xmlDocApp = new XmlDocument(); xmlDocApp.Load(Application.StartupPath + "\\xmlAPP.xml"); XmlNode myxmlNode = xmlDocApp.SelectNodes("root").Item(0); XmlElement xmlEleFileName = xmlDocApp.CreateElement("xmlBarcodeModel"); XmlAttribute xmlAttributeFileName = xmlDocApp.CreateAttribute("Path"); xmlAttributeFileName.Value = strFileName; xmlEleFileName.Attributes.Append(xmlAttributeFileName); myxmlNode.AppendChild(xmlEleFileName); xmlDocApp.Save(Application.StartupPath + "\\xmlAPP.xml"); * */ if (myClsXmlApp == null) myClsXmlApp = new ClsXmlApp(); myClsXmlApp.addBarcodeModel(strFileName); saveXmlApp(); //同时更新画布。 dataGridViewChangedCell(); }
private void printBarcode(int intPages) { ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); //如下的这个有些破坏了封装性,我用这个只是为了打印结束后判断是否自动打印。 //myBarcodePrint.myPrintDocument.EndPrint += new PrintEventHandler(myPrintDocument_EndPrint); //如下是添加到打印队列 ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝 if (arrlistSellectRow != null) { foreach (clsKeyValue myKeyValue in arrlistSellectRow) { clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value); arrlist.Add(kv); } } //创建打印信息。 queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = strCurrentTableName; //如下是取得模板的路径 string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value; //还得判断是否是相对路径,我的简单判断方法是是否有冒号":" if (strPathName.IndexOf(":") < 0) { //还有得判断首字符是不是"\\",如果不是就加上 if (strPathName.Substring(0) == "\\") { strPathName = Application.StartupPath + strPathName; } else { strPathName = Application.StartupPath + "\\" + strPathName; } } printDetails.ShapesFileName = strPathName; printDetails.IsFull = chkIsFull.Checked; queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = intPages; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); //queuePrintItem printDetails = new queuePrintItem(strCurrentTableName, ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, intPages); myBarcodePrint.addPrintDetails(printDetails); }
/// <summary> /// 加载模板 /// </summary> private void loadXmlBarcodeModel() { //加载文件,并保存信息到shapesFileData string strFileName = userControlCanvas1.Loader();//返回的是文件名 if (strFileName != "") { shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); this.Text = "条形码编辑设计 www.xuhengxiao.com 打开文件:" + strFileName; } }
/// <summary> /// 测试打印 /// </summary> private void TestPrint() { //如下这个只是复制一个值变量再传递 ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝 if (userControlCanvas1.myShapes.arrlistKeyValue != null) { foreach (clsKeyValue myKeyValue in userControlCanvas1.myShapes.arrlistKeyValue) { clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value); arrlist.Add(kv); } } userControlCanvas1.Saver(Application.StartupPath + "\\barcodeEditTestPrint.barcode"); //测试的话只打印一页就可以了。 ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); queuePrintItem printDetails = new queuePrintItem(); printDetails.strTableName = "Test"; printDetails.ShapesFileName = Application.StartupPath + "\\barcodeEditTestPrint.barcode"; printDetails.IsFull = chkIsFull.Checked; queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages(); queuePrintItemRowAndPages1.arrlistRow = arrlist; queuePrintItemRowAndPages1.intPages = 1; printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1); myBarcodePrint.addPrintDetails(printDetails); }
/// <summary> /// 我自己编写的关闭方法 /// </summary> private void myExit() { if (userControlCanvas1.isNeedSave()) { //提示用户还没有保存 DialogResult dr = MessageBox.Show("您没有保存,请问要保存吗?", "保存", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { string strFileName; while (((shapesFileData.Key == "templet"))) { strFileName = userControlCanvas1.Saver(); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); if (strFileName == "") { MessageBox.Show("您没有选择文件"); return; } } strFileName = userControlCanvas1.Saver(shapesFileData.Value); this.Dispose();//关闭 } else if (dr == DialogResult.No) { //不保存就是直接关闭了 this.Dispose(); } else { //到这里就是选择的是取消了,什么也不用做 return; } } else { this.Dispose(); } }
/// <summary> /// 加载DataTable数据 /// </summary> /// <param name="dataTable"></param> public void LoadDataTable(DataTable dataTable) { try { if (dataTable != null) { CurrentDataTable = dataTable;//这个可以选择变量 //如下两个是绑定那个数据 bindingNavigator1.BindingSource = bindingSource1; bindingSource1.DataSource = CurrentDataTable; bindingNavigatorPositionItem.Text = "1";//将这个重设为第一条记录 //将第一项更新到画布 ArrayList arrlist = new ArrayList(); if ((CurrentDataTable.Rows.Count > 0)) { //根据列名迭代 foreach (DataColumn item in CurrentDataTable.Columns) { clsKeyValue myclsKeyValue = new clsKeyValue(item.Caption, CurrentDataTable.Rows[0][item.Caption].ToString()); arrlist.Add(myclsKeyValue); } } //更新到画布 userControlCanvas1.arrlistKeyValue = arrlist; loadPrintedQtytoComboBox();// 判断哪像是数字 } } catch (System.Exception ex) { //ClsErrorFile.WriteLine("模板编辑中加载DataTable数据出现异常",ex); } }
/// <summary> /// 新建模板 /// </summary> private void NewBarcodeModel() { //这个我想把它做成,打开一个条形码模板,但关闭前判断是不是这个模板,如果是,就提示保存 string strFileName = Application.StartupPath + "\\BarcodeModel\\templet.barcode"; userControlCanvas1.Loader(strFileName); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); }
/// <summary> /// 这个方法只是设置变量信息的 /// </summary> /// <param name="arrlist"></param> public void setKeyValue(ArrayList arrlist) { ArrayList arrlisttemp = new ArrayList(); try { if (arrlist != null) { foreach (clsKeyValue item in arrlist) { clsKeyValue clskeyvalue1 = new clsKeyValue(item.Key, item.Value); arrlisttemp.Add(clskeyvalue1); } userControlCanvas1.setArrKeyValue(arrlisttemp); userControlCanvas1.Refresh(); } } catch (System.Exception ex) { //ClsErrorFile.WriteLine("设置变量信息不成功",ex); } }
/// <summary> /// 另存为 /// </summary> private void SaveAsBarcodeModel() { string strFileName = userControlCanvas1.Saver(); shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName); }
public void dataGridViewChangedCell() { // //因为存在点击列名而导致的异常,所以需要判断一下。 if (dataGridView1.SelectedCells.Count > 0) { arrlistSellectRow.Clear();//当然首先是清空了。 string strData = "";//查询打印记录时用 for (int i = 0; i < dataGridView1.ColumnCount; i++) { clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, dataGridView1.CurrentRow.Cells[i].Value.ToString()); arrlistSellectRow.Add(keyvalue); strData = strData + dataGridView1.CurrentRow.Cells[i].Value.ToString();//就是所有项连接起来 } //导入打印记录,判断是根据表名和数据, ClsDataBase myClsDataBase = new ClsDataBase(); dataGridViewPrintedRecords.DataSource = myClsDataBase.commandSelectPrintedRecord(strCurrentTableName, arrlistSellectRow); //更新图片 XmlDocument xmlDoc = new XmlDocument(); //如下得判断路径是否是绝对路径 //值深度拷贝 ArrayList arrlisttemp = new ArrayList(); if (arrlistSellectRow != null) { foreach (clsKeyValue item in arrlistSellectRow) { clsKeyValue clskeyvalue1 = new clsKeyValue(item.Key, item.Value); arrlisttemp.Add(clskeyvalue1); } } //还得判断是否有选择的条形码模板 userControlCanvas1.setArrKeyValue(arrlisttemp); userControlCanvas1.Refresh(); /** { if (comboBoxBarcodeModel.SelectedItem != null) { string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value; //还得判断是否是相对路径,我的简单判断方法是是否有冒号":" if (strPathName.IndexOf(":") < 0) { //还有得判断首字符是不是"\\",如果不是就加上 if (strPathName.Substring(0) == "\\") { strPathName = Application.StartupPath + strPathName; } else { strPathName = Application.StartupPath + "\\" + strPathName; } } ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint(); //如下是画布设置 userControlCanvas1.Loader(strPathName); //根据纸张的大小选择放大率 calculateCanvas(); userControlCanvas1.setArrKeyValue(arrlisttemp); userControlCanvas1.ZoomPaperToScreen(); userControlCanvas1.Refresh(); //picCanvas.Image = myBarcodePrint.xmlToBarcodeImage(clsBarcodePrint.populateVariable(xmlDoc, frmMain.arrlistSellectRow)); } } * */ //得更新要打印数量 //加载变量名。从arrlistSellectRow得到列名。 comboBoxVaribaleName_SelectedIndexChanged(this, new EventArgs()); } }