using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using UAS_LabelMachine.Entity; using UAS_LabelMachine.PublicMethod; namespace UAS_LabelMachine { public partial class ExportColumns : Form { DataHelper dh = SystemInf.dh; string inoutno = ""; string custcode = ""; public ExportColumns() { InitializeComponent(); Activate(); } public ExportColumns(string IInoutno) { InitializeComponent(); inoutno = IInoutno; } private void ExportColumns_Load(object sender, EventArgs e) { Activate(); LogicHandler.CustInit("0"); LoadData(); } private void SaveColumns_Click(object sender, EventArgs e) { //先删除之前此客户的记录 dh.ExecuteSql("delete from CS_EXPORTSETTING where es_custcode='" + custcode + "'", "delete"); StringBuilder sql = new StringBuilder(); List es_filed = new List(); List es_caption = new List(); List es_enable = new List(); List es_detno = new List(); List es_istitle = new List(); List es_datatype = new List(); for (int i = 0; i < FirstPage.Rows.Count; i++) { es_filed.Add(FirstPage.Rows[i].Cells["es_filed"].Value.ToString()); es_caption.Add(FirstPage.Rows[i].Cells["es_caption"].Value.ToString()); es_enable.Add(FirstPage.Rows[i].Cells["es_enable"].Value.ToString()); es_detno.Add(FirstPage.Rows[i].Cells["es_detno"].Value.ToString()); es_istitle.Add(FirstPage.Rows[i].Cells["es_istitle"].Value.ToString()); es_datatype.Add(FirstPage.Rows[i].Cells["es_datatype"].Value.ToString()); } sql.Clear(); sql.Append("insert into CS_EXPORTSETTING(es_type,es_filed,es_caption,es_enable,es_detno,es_custcode,es_istitle,es_datatype)"); sql.Append("values('First',:es_filed,:es_caption,:es_enable,:es_detno,'" + custcode + "',:es_istitle,:es_datatype)"); dh.BatchInsert(sql.ToString(), new string[] { "es_filed", "es_caption", "es_enable", "es_detno", "es_istitle", "es_datatype" }, es_filed.ToArray(), es_caption.ToArray(), es_enable.ToArray(), es_detno.ToArray(), es_istitle.ToArray(), es_datatype.ToArray()); //清除首页赋的值 es_filed.Clear(); es_caption.Clear(); es_enable.Clear(); ; es_detno.Clear(); es_filed.Clear(); es_istitle.Clear(); for (int i = 0; i < DataPage.Rows.Count; i++) { es_filed.Add(DataPage.Rows[i].Cells["es_filed"].Value.ToString()); es_caption.Add(DataPage.Rows[i].Cells["es_caption"].Value.ToString()); es_enable.Add(DataPage.Rows[i].Cells["es_enable"].Value.ToString()); es_detno.Add(DataPage.Rows[i].Cells["es_detno"].Value.ToString()); es_istitle.Add(DataPage.Rows[i].Cells["es_istitle"].Value.ToString()); es_datatype.Add(DataPage.Rows[i].Cells["es_datatype"].Value.ToString()); } sql.Clear(); sql.Append("insert into CS_EXPORTSETTING(es_type,es_filed,es_caption,es_enable,es_detno,es_custcode,es_istitle,es_datatype)"); sql.Append("values('DataPage',:es_filed,:es_caption,:es_enable,:es_detno,'" + custcode + "',:es_istitle,:es_datatype)"); dh.BatchInsert(sql.ToString(), new string[] { "es_filed", "es_caption", "es_enable", "es_detno", "es_istitle", "es_datatype" }, es_filed.ToArray(), es_caption.ToArray(), es_enable.ToArray(), es_detno.ToArray(), es_istitle.ToArray(), es_datatype.ToArray()); MessageBox.Show("保存成功!"); LoadData(); } private void ResetColumns_Click(object sender, EventArgs e) { string close = MessageBox.Show(this.ParentForm, "是否重置列", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close == "Yes") { dh.ExecuteSql("delete from CS_EXPORTSETTING where es_custcode='" + custcode + "'", "delete"); LoadData(); } } private void DeleteColumns_Click(object sender, EventArgs e) { DataGridViewSelectedCellCollection cl = FirstPage.SelectedCells; List deleteIndex = new List(); for (int i = 0; i < cl.Count; i++) { if (!deleteIndex.Contains(cl[i].ColumnIndex)) { deleteIndex.Add(cl[i].ColumnIndex); } } for (int i = FirstPage.Columns.Count - 1; i >= 0; i--) { for (int j = 0; j < deleteIndex.ToArray().Length; j++) { if (deleteIndex.ToArray()[j] == i) FirstPage.Columns.RemoveAt(i); } } } private void DeleteDataColumns_Click(object sender, EventArgs e) { DataGridViewSelectedCellCollection cl = DataPage.SelectedCells; List deleteIndex = new List(); for (int i = 0; i < cl.Count; i++) { if (!deleteIndex.Contains(cl[i].ColumnIndex)) { deleteIndex.Add(cl[i].ColumnIndex); } } for (int i = DataPage.Columns.Count - 1; i >= 0; i--) { for (int j = 0; j < deleteIndex.ToArray().Length; j++) { if (deleteIndex.ToArray()[j] == i) DataPage.Columns.RemoveAt(i); } } } private void LoadData() { StringBuilder sql = new StringBuilder(); custcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString(); DataTable SQL1_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select"); //没有置顶客户的取空的 if (SQL1_.Rows.Count == 0) { SQL1_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode is null order by es_detno", "select"); } //获取首页需要展示的字段 DataTable SQL_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select"); if (SQL_.Rows.Count == 0) { SQL_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode is null order by es_detno", "select"); } if (FirstPage.DataSource != null) FirstPage.DataSource = null; if (DataPage.DataSource != null) DataPage.DataSource = null; FirstPage.DataSource = SQL_; DataPage.DataSource = SQL1_; FirstPage.ReadOnly = false; DataPage.ReadOnly = false; } } }