123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using UAS_LabelMachine.CustomControl;
- using UAS_LabelMachine.CustomControl.GroupBoxWithBorder;
- using static System.Windows.Forms.Control;
- using System.Text.RegularExpressions;
- using Seagull.BarTender.Print;
- using Microsoft.CSharp;
- using System.CodeDom.Compiler;
- using System.Reflection;
- using UAS_LabelMachine.Entity;
- namespace UAS_LabelMachine
- {
- class BaseUtil
- {
- static string SysDisc;
- public static string SysDisc1
- {
- get
- {
- return SysDisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
- }
- set
- {
- SysDisc = value;
- }
- }
- static int serialnum = 0;
- static bool FirstCode = false;
-
- public static string BarcodeMethod1(string pd_id, string pr_id, string pib_barcode)
- {
- if (pib_barcode != "")
- {
- if (FirstCode)
- {
- serialnum = serialnum + 1;
- }
-
- else
- {
- serialnum = int.Parse(pib_barcode.Substring(pib_barcode.Length - 4)) + 1;
- FirstCode = true;
- }
- }
- else
- {
- serialnum = serialnum + 1;
- }
- string serialcode = serialnum.ToString();
- for (int i = serialnum.ToString().Length; i < 4; i++)
- {
- serialcode = "0" + serialcode;
- }
- return pd_id + "-" + pr_id + "-" + serialcode;
- }
-
-
-
-
-
-
- public static DataTable filterDataTable(DataTable dt, String condition)
- {
- if (dt == null)
- return new DataTable();
-
- DataRow[] dataRows = dt.Select(condition);
- DataTable ndt = dt.Clone();
- for (int i = 0; i < dataRows.Length; i++)
- {
- ndt.Rows.Add(dataRows[i].ItemArray);
- }
- return ndt;
- }
- public static string DToAny(double DB, int Type)
- {
- string H = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- long D;
- double B;
- string tempD = "", tempB = "";
- D = (long)DB;
- B = DB - D;
- if (D == 0)
- {
- tempD = "0";
- }
- while (D != 0)
- {
- tempD = H[(((int)D % Type))] + tempD;
- D = D / Type;
- }
- for (int i = 0; i < 7; i++)
- {
- if (B == 0)
- {
- break;
- }
- tempB += H[((int)(B * Type))];
- B = B * Type - (int)(B * Type);
- }
- if (tempB == "")
- {
- return tempD;
- }
- else
- {
- return tempD + "." + tempB;
- }
- }
- public static DataTable GetExportDataTable(DataGridView dgv)
- {
- DataTable dt = ((DataTable)dgv.DataSource).Copy();
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- for (int j = 0; j < dgv.Columns.Count; j++)
- {
- if (dt.Columns[i].ColumnName.ToLower() == dgv.Columns[j].DataPropertyName.ToLower())
- {
- dt.Columns[i].ColumnName = dgv.Columns[j].HeaderText;
- }
- }
- }
- return dt;
- }
-
-
-
-
-
- public static string GetGridViewSelectContent(DataGridView d)
- {
- StringBuilder selectConetnt = new StringBuilder();
- DataTable dt = (DataTable)d.DataSource;
- if (dt == null)
- {
- foreach (DataGridViewColumn dc in d.Columns)
- {
- if (dc.DataPropertyName != "" && dc.DataPropertyName != null)
- {
- selectConetnt.Append(dc.DataPropertyName + " as " + dc.DataPropertyName + ",");
- }
- }
- }
- else
- {
- foreach (DataColumn dc in dt.Columns)
- {
- selectConetnt.Append(dc.Caption + " as " + dc.ColumnName + ",");
- }
- }
- return selectConetnt.Remove(selectConetnt.Length - 1, 1).ToString();
- }
-
-
-
-
-
-
- public static string GetSelectContentByStringArray(string[] field, string[] cnfield)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < field.Length; i++)
- {
- sb.Append(field[i] + " as " + cnfield[i] + ",");
- }
-
- sb.Remove(sb.Length - 1, 1);
- return sb.ToString();
- }
-
-
-
-
-
- public static void SetFormValue(ControlCollection collection, DataTable dt)
- {
-
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- string controlName = collection[i].Name;
-
- if (collection[i] is TextBox || collection[i] is Label || collection[i] is SearchTextBox || collection[i] is CheckBox)
- {
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- if (controlName.ToUpper() == dt.Columns[j].Caption.ToUpper())
- {
-
- if (controlName.ToUpper().Contains("STATUS"))
- {
-
- switch (dt.Rows[0][j].ToString().ToUpper())
- {
- case "ENTERING":
- collection[i].Text = "在录入";
- break;
- case "UNAPPROVED":
- collection[i].Text = "未批准";
- break;
- case "COMMITED":
- collection[i].Text = "已提交";
- break;
- case "APPROVE":
- collection[i].Text = "已批准";
- break;
- case "AUDITED":
- collection[i].Text = "已审核";
- break;
- case "STARTED":
- collection[i].Text = "已下发";
- break;
- case "UNCHECK":
- collection[i].Text = "待检验";
- break;
- case "CHECKING":
- collection[i].Text = "检验中";
- break;
- default:
- collection[i].Text = dt.Rows[0][j].ToString();
- break;
- }
- }
- else
- {
- if (collection[i] is CheckBox)
- {
- (collection[i] as CheckBox).Checked = dt.Rows[0][j].ToString() == "-1" ? true : false;
- }
- else
- {
- collection[i].Text = dt.Rows[0][j].ToString();
- }
- }
- }
- }
- }
-
- if (collection[i] is GroupBox || collection[i] is Panel || collection[i] is GroupBoxWithBorder)
- {
- for (int j = 0; j < collection[i].Controls.Count; j++)
- {
- controlName = collection[i].Controls[j].Name;
- if (collection[i].Controls[j] is TextBox || collection[i].Controls[j] is Label || collection[i].Controls[j] is SearchTextBox)
- {
- for (int k = 0; k < dt.Columns.Count; k++)
- {
- if (controlName.ToUpper() == dt.Columns[k].Caption.ToUpper())
- {
- collection[i].Controls[j].Text = dt.Rows[0][k].ToString();
- }
- }
- }
- }
- }
- }
- }
-
- else
- {
- for (int i = 0; i < collection.Count; i++)
- {
- if (collection[i] is TextBox || collection[i] is Label || collection[i] is SearchTextBox)
- {
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- if (collection[i].Name.ToUpper() == dt.Columns[j].Caption.ToUpper())
- {
- collection[i].Text = "";
- }
- }
- }
- }
- }
- }
-
-
-
-
-
-
- public static string GetLabelUrl(string URL, string LabelName, DateTime time)
- {
-
- if (URL.Contains("ftp:"))
- {
- ftpOperater ftp = new ftpOperater(SystemInf.FTPModel);
- return ftp.Download(LabelName, time);
- }
- else
- {
- return URL;
- }
- }
-
-
-
- public static ArrayList[] GetColumnDataFromDGV(DataGridView dgv, string[] ColumnName)
- {
- ArrayList[] array = new ArrayList[ColumnName.Length];
-
- for (int i = 0; i < ColumnName.Length; i++)
- {
- array[i] = new ArrayList();
- }
- DataTable dt = (DataTable)dgv.DataSource;
-
- if (dgv.Columns[0] is DataGridViewCheckBoxColumn)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dgv.Rows[i].Cells[0].FormattedValue.ToString() == "True")
- {
- for (int j = 0; j < ColumnName.Length; j++)
- {
- array[j].Add(dt.Rows[i][ColumnName[j]]);
- }
- }
- }
- }
-
- else
- {
- for (int i = 0; i < dgv.RowCount; i++)
- {
- for (int j = 0; j < ColumnName.Length; j++)
- {
- array[j].Add(dt.Rows[i][ColumnName[j]]);
- }
- }
- }
- return array;
- }
-
-
-
-
-
- public static void HideField(DataGridView dgv, string[] field)
- {
- DataTable dt = (DataTable)dgv.DataSource;
- foreach (DataColumn dc in dt.Columns)
- {
- foreach (string s in field)
- {
- if (dc.Caption == s)
- {
- dgv.Columns[dc.ColumnName].Visible = false;
- }
- }
- }
- }
-
-
-
-
-
- public static string[] GetCaptionFromField(string field)
- {
- string[] caption = field.Split(',');
- for (int i = 0; i < caption.Length; i++)
- {
- caption[i] = caption[i].Substring(0, caption[i].LastIndexOf("as")).Trim();
- }
- return caption;
- }
-
-
-
-
-
- public static string[] GetField(string field)
- {
- string[] fields = field.Split(',');
- for (int i = 0; i < fields.Length; i++)
- {
- fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
- }
- return fields;
- }
-
-
-
-
-
- public static List<Dictionary<string, string>> DataTableToListDictionary(DataTable dt)
- {
- List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
- foreach (DataRow dr in dt.Rows)
- {
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- foreach (DataColumn dc in dt.Columns)
- {
- dictionary.Add(dc.Caption, dr[dt.Columns.IndexOf(dc)].ToString());
- }
- list.Add(dictionary);
- }
- return list;
- }
-
-
-
-
-
-
- public static string GetColumnNameByCaption(DataTable dt, string caption)
- {
- foreach (DataColumn dc in dt.Columns)
- {
- if (dc.Caption.ToLower() == caption)
- {
- return dc.ColumnName;
- }
- }
- return null;
- }
-
- public static void ShowError(string errorMessage)
- {
- throw new Exception(errorMessage);
- }
-
-
-
-
- public static void CleanDataTable(DataTable dt)
- {
- for (int i = dt.Columns.Count - 1; i >= 0; i--)
- {
- dt.Columns.Remove(dt.Columns[i]);
- }
- }
-
-
-
-
- public static void CleanDataTableData(DataTable dt)
- {
- for (int i = dt.Rows.Count - 1; i >= 0; i--)
- {
- dt.Rows.Remove(dt.Rows[i]);
- }
- }
-
-
-
-
-
- public static string GetFieldFromDataTable(DataTable dt)
- {
- StringBuilder sb = new StringBuilder();
- foreach (DataColumn dc in dt.Columns)
- {
- sb.Append(dc.Caption + ",");
- }
- return sb.ToString().Substring(sb.ToString().Length - 1, 1);
- }
-
-
-
-
-
-
-
- public static void FillDgvWithDataTable(DataGridView dgv, DataTable dt, params DataGridViewImageColumn[] operate)
- {
- dgv.AutoGenerateColumns = false;
- dgv.DataSource = dt;
- if (operate.Length > 0)
- {
- if (dgv.Columns[operate[0].Name] != null)
- {
- dgv.Columns.Remove(dgv.Columns[operate[0].Name]);
- }
- dgv.Columns.Add(operate[0]);
- }
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
- public static void CleanDGVData(DataGridView dgv)
- {
- for (int i = dgv.Rows.Count - 1; i >= 0; i--)
- {
- dgv.Rows.RemoveAt(i);
- }
- }
-
-
-
-
- public static void CleanForm(Form Form)
- {
- for (int i = 0; i < Form.Controls.Count; i++)
- {
- if (Form.Controls[i] is EnterTextBox || Form.Controls[i] is TextBox || Form.Controls[i] is RichTextBox || Form.Controls[i] is SearchTextBox)
- Form.Controls[i].Text = "";
- if (Form.Controls[i] is DataGridView)
- CleanDGVData((DataGridView)Form.Controls[i]);
- }
- }
-
-
-
-
-
-
-
-
- public static void SetDgvColumnComboxData(DataGridViewComboBoxColumn dgvc, string DataPropertyName, string displayField, string valueField, string[] Value)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add(displayField);
- dt.Columns.Add(valueField);
- for (int i = 0; i < Value.Length; i++)
- {
- DataGridViewRow row = new DataGridViewRow();
- dt.Rows.Add(row);
- dt.Rows[i][displayField] = Value[i].Split('#')[0];
- dt.Rows[i][valueField] = Value[i].Split('#')[1];
- }
- dgvc.DataPropertyName = DataPropertyName;
- dgvc.DataSource = dt;
- dgvc.DisplayMember = displayField;
- dgvc.ValueMember = valueField;
- }
-
-
-
-
-
-
-
- public static void SetDGVCellComboxData(DataGridViewComboBoxCell dgvcc, string displayField, string valueField, string[] Value)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add(displayField);
- dt.Columns.Add(valueField);
- for (int i = 0; i < Value.Length; i++)
- {
- DataRow dr = dt.NewRow();
- dr[displayField] = Value[i].Split('#')[0];
- dr[valueField] = Value[i].Split('#')[1];
- dt.Rows.Add(dr);
- }
- dgvcc.DisplayMember = displayField;
- dgvcc.ValueMember = valueField;
- dgvcc.DataSource = dt;
- }
-
-
-
-
-
-
-
- public static void SetComboxData(ComboBox dgvcc, string displayField, string valueField, string[] Value)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add(displayField);
- dt.Columns.Add(valueField);
- for (int i = 0; i < Value.Length; i++)
- {
- DataRow dr = dt.NewRow();
- dr[displayField] = Value[i].Split('#')[0];
- dr[valueField] = Value[i].Split('#')[1];
- dt.Rows.Add(dr);
- }
- dgvcc.DisplayMember = displayField;
- dgvcc.ValueMember = valueField;
- dgvcc.DataSource = dt;
- }
-
-
-
-
-
-
- public static string GetScreenSqlCondition(params Control[] Condition)
- {
- string condition = " where ";
- for (int i = 0; i < Condition.Length; i++)
- {
- if (i != Condition.Length - 1)
- {
- if (Condition[i] is ComboBox)
- {
- condition += "(" + Condition[i].Tag + " like " + "'%" + (Condition[i] as ComboBox).SelectedValue + "%' or " + Condition[i].Tag + " is null) and ";
- }
- else
- {
- condition += "(" + Condition[i].Tag + " like " + "'%" + Condition[i].Text + "%' or " + Condition[i].Tag + " is null) and ";
- }
- }
- else
- {
- if (Condition[i] is ComboBox)
- {
- condition += "(" + Condition[i].Tag + " like " + "'%" + (Condition[i] as ComboBox).SelectedValue + "%' or " + Condition[i].Tag + " is null)";
- }
- else
- {
- condition += "(" + Condition[i].Tag + " like " + "'%" + Condition[i].Text + "%' or " + Condition[i].Tag + " is null)";
- }
- }
- }
- return condition;
- }
- public static void CleanDataGridView(DataGridView dgv)
- {
- for (int i = dgv.Columns.Count - 1; i >= 0; i--)
- {
- dgv.Columns.RemoveAt(i);
- }
- }
-
-
-
-
-
- public static string[] GetParamFromSQL(string SQL)
- {
- string[] par = SQL.Split(':');
-
- StringBuilder[] addpar = new StringBuilder[par.Length - 1];
- string[] param = new string[par.Length - 1];
- for (int i = 0; i < par.Length - 1; i++)
- {
-
- char[] c = par[i + 1].ToCharArray();
- addpar[i] = new StringBuilder();
- for (int j = 0; j < c.Length; j++)
- {
- if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
- {
- addpar[i].Append(c[j]);
- }
- else
- {
- break;
- }
- }
- }
- for (int i = 0; i < par.Length - 1; i++)
- {
- param[i] = addpar[i].ToString();
- }
- return param;
- }
- public static void SetFormCenter(Form form)
- {
- form.StartPosition = FormStartPosition.CenterParent;
- }
-
-
-
-
-
- public static void SetDataGridViewReadOnly(DataGridView DGV, string[] EditAbleField)
- {
- foreach (DataGridViewColumn dc in DGV.Columns)
- {
- dc.ReadOnly = true;
- foreach (string s in EditAbleField)
- {
- if (dc.Name.ToLower() == s.ToLower())
- {
- DGV.Columns[dc.Name].ReadOnly = false;
- }
- }
- }
- }
-
- public static DataTable DGVIfChecked(DataGridView dgv)
- {
- int CheckCount = 0;
- DataTable dt = new DataTable();
-
- for (int i = 1; i < dgv.Columns.Count; i++)
- {
- dt.Columns.Add(dgv.Columns[i].Name);
- }
- for (int i = 0; i < dgv.RowCount; i++)
- {
- if (dgv.Rows[i].Cells[0].Value != null)
- {
- if (dgv.Rows[i].Cells[0].Value.ToString() == "True")
- {
- if (dgv.Rows[i].Tag.ToString() == "SonRow")
- {
- DataRow dr = dt.NewRow();
- for (int j = 1; j < dgv.ColumnCount; j++)
- {
- dr[dgv.Columns[j].Name] = dgv.Rows[i].Cells[j].FormattedValue;
- }
- dt.Rows.Add(dr);
- CheckCount++;
- }
- }
- }
- }
-
- if (CheckCount == 0)
- {
- return null;
- }
- return dt;
- }
-
-
-
-
-
- public static void NumOnly(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b')
- {
- if ((e.KeyChar < '0') || (e.KeyChar > '9'))
- {
- e.Handled = true;
- }
- }
- }
- public static Dictionary<string, object> ToDictionary(string JsonData)
- {
- object Data = null;
- Dictionary<string, object> Dic = new Dictionary<string, object>();
- if (JsonData.StartsWith("["))
- {
-
-
- List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
- MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");
- foreach (Match ListItem in ListMatch)
- {
- List.Add(ToDictionary(ListItem.ToString()));
- }
- Data = List;
- Dic.Add("List", Data);
- }
- else
- {
- MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");
- foreach (Match item in Match)
- {
- try
- {
- if (item.Groups[2].ToString().StartsWith("["))
- {
-
-
- List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
- MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");
- foreach (Match ListItem in ListMatch)
- {
- List.Add(ToDictionary(ListItem.ToString()));
- }
- Data = List;
- }
- else if (item.Groups[2].ToString().ToLower() == "null") Data = null;
- else Data = item.Groups[2].ToString();
- Dic.Add(item.Groups[1].ToString(), Data);
- }
- catch { }
- }
- }
- return Dic;
- }
- public static string AddField(string[] Fields)
- {
- string sql = " ";
- foreach (string field in Fields)
- {
- sql += field + ",";
- }
- return sql.Substring(0, sql.Length - 1);
- }
- public static string GetArrStr(ArrayList<string> arr, string Split)
- {
- string Str = "";
- for (int i = 0; i < arr.ToArray().Length; i++)
- {
- Str += arr.ToArray()[i] + Split;
- }
- return Str;
- }
-
- public static void SetControlsVisible(params object[] sender)
- {
- foreach (object item in sender)
- {
- (item as DataGridViewColumn).Visible = false;
- }
- }
- public static string GetOutBoxSQL(LabelFormatDocument OutFormat, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2, bool iCustProdCode, bool iCustPo, bool iDC, bool iLotNo, bool iOrderCode)
- {
- StringBuilder sql = new StringBuilder();
- sql.Clear();
- for (int j = 0; j < OutFormat.SubStrings.Count; j++)
- {
- DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
- if (dr1.Length > 0 && (dr1[0]["lp_valuetype"].ToString() == "字符串" || dr1[0]["lp_valuetype"].ToString() == "text") && dr1[0]["lp_sql"].ToString() != "")
- {
- sql.Append(dr1[0]["lp_sql"].ToString() + ",");
- }
- }
-
- string GroupByCondition = "";
- if (iCustProdCode)
- {
- GroupByCondition += "pd_custprodcode,";
- }
- if (iCustPo)
- {
- GroupByCondition += "pd_pocode,";
- }
- if (iDC)
- {
- GroupByCondition += "pib_datecode,";
- }
- if (iLotNo)
- {
- GroupByCondition += "pib_lotno,";
- }
- if (iOrderCode)
- {
- GroupByCondition += "pd_ordercode,";
- }
- if (iCustProdCode || iCustPo || iDC || iLotNo || iOrderCode)
- {
- GroupByCondition = " group by " + (GroupByCondition.Substring(0, GroupByCondition.Length - 1));
- }
- sql.Append("max(pib_id),");
- return "select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno = '" + pi_inoutno + "' and pib_outboxcode2 = " + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition;
- }
- public static void CustomerInit(string oContent)
- {
- if (oContent == ""|| oContent=="null"|| oContent==" ")
- return;
-
- CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();
-
- CompilerParameters objCompilerParameters = new CompilerParameters();
- objCompilerParameters.ReferencedAssemblies.Add("System.dll");
- objCompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
- objCompilerParameters.GenerateExecutable = false;
- objCompilerParameters.GenerateInMemory = true;
-
- CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromSource(objCompilerParameters, oContent);
- if (cr.Errors.HasErrors)
- {
- foreach (CompilerError err in cr.Errors)
- {
- Console.WriteLine(err.ErrorText);
- }
- }
- else
- {
-
- Assembly objAssembly = cr.CompiledAssembly;
- object objHelloWorld = objAssembly.CreateInstance("CustInitSpace.CustInitClass", true);
- MethodInfo objMI = objHelloWorld.GetType().GetMethod("CustInit");
- try
- {
- Console.WriteLine(objMI.Invoke(objHelloWorld, null));
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
- namespace CustInitSpace
- {
- using System;
- using System.Windows.Forms;
- public class CustInitClass
- {
- public void CustInit()
- {
- Form f = Form.ActiveForm;
- (f.Controls["LabelInf"] as DataGridView).Columns["pib_year"].Visible = false;
- (f.Controls["LabelInf"] as DataGridView).Columns["pib_month"].Visible = false;
- (f.Controls["LabelInf"] as DataGridView).Columns["pib_day"].Visible = false;
- (f.Controls["LabelInf"] as DataGridView).Columns["pib_custoutboxcode"].HeaderText = "芯片号";
- }
- }
- }
- }
|