using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading; namespace Core.StlMes.Client.PlnSaleOrd.PlanStove { public class CommHelper { /// /// byWencheg设置列的顺序 /// /// /// /// public static void SetColumnPosition(Infragistics.Win.UltraWinGrid.UltraGridBand band, string key, int index) { if (band.Columns.Exists(key) && band.Columns.Count > index) { band.Columns[key].Swap(GetSpecPositionCol(band, index)); //band.Columns[key].Swap(band.Columns[index]); } } /// /// 获取指定位置的列 /// /// /// /// public static UltraGridColumn GetSpecPositionCol(UltraGridBand band, int position) { foreach (UltraGridColumn col in band.Columns) { if (col.Header.VisiblePosition == position) { return col; } } return null; } /// //byWenCheng 设置grid的band的列名和描述(列名和描述来自数据库的列名和描述) /// /// 需要设置的grid的band /// 与band对应的表名 /// OpenBase对象 public static void SetColandCaption(Infragistics.Win.UltraWinGrid.UltraGridBand band, string tablename, CoreFS.CA06.OpeBase ob) { if (band == null) { return; } System.Data.DataTable dt = GetDataBySql(string.Format(@"select column_name,comments from user_col_comments where table_name = '{0}'", tablename), ob); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (band.Columns.IndexOf(row[0].ToString()) < 0) { band.Columns.Add(row[0].ToString(), row[1].ToString()); } else { band.Columns[row[0].ToString()].Header.Caption = row[1].ToString(); } } } } /// ///byWenCheng 执行sql语句 /// /// /// /// public static System.Data.DataTable GetDataBySql(string sqlString, CoreFS.CA06.OpeBase _ob) { return Core.Mes.Client.Comm.Server.ServerHelper.GetData("com.steering.pss.plnsaleord.ordAmCal.OrderDemo.getDataBySql", new Object[] { sqlString }, _ob); } /// ///byWenCheng 设置某band的所有列不可编辑,除了ignoreColums里包含的列 /// /// 需要设置的band /// 需要忽略的列 public static void SetGridColNoEdit(Infragistics.Win.UltraWinGrid.UltraGridBand band, string[] ignoreColums) { foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in band.Columns) { if (ignoreColums.Length > 0 && !string.IsNullOrEmpty(ignoreColums.FirstOrDefault(c => c == col.Key))) { col.CellAppearance.BackColor = System.Drawing.Color.Yellow; continue; } col.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit; } } /// /// byWenCheng,复制数据到数据表,暂未测试速率,目前发现在查询数据时比较耗时,2000条数据2-3s /// /// /// /// public static void CopyDatabyDatatable(System.Data.DataTable srcDt, System.Data.DataTable desDt, bool ClearExsit) { if (srcDt.Rows.Count <= 0) { return; } if (ClearExsit) { desDt.Rows.Clear(); } foreach (DataRow row in srcDt.Rows) { desDt.LoadDataRow(row.ItemArray, false); } } /// ///byWenCheng 设置列宽根据内容自适应方法1 /// /// 需要设置的band public static void SetColumnAutoFitSize1(UltraGridBand band) { if (band != null) { band.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand,true); } } /// ///byWenCheng 设置列宽根据内容自适应方法2 /// /// 需要设置的band public static void SetColumnAutoFitSize2(UltraGridBand band) { if (band != null) { foreach (UltraGridColumn col in band.Columns) { col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand,true); } } } /// ///byWenCheng 设置行高根据内容自适应 /// /// public static void SetRowAutoFitSize(UltraGrid grid) { if (grid != null) { grid.DisplayLayout.Override.RowSizing = RowSizing.AutoFree; } } /// ///byWenCheng 获取grid的激活的行,如果该行有对应的父行,则取其父行。和selected选择的行有区别的是,selectedrow是可以有多行,activedrow只能是一行,而且一般是最后选择的那一行 /// /// /// public static UltraGridRow GetActiveRow(UltraGrid grid) { if (grid == null || grid.ActiveRow == null) { return null; } UltraGridRow ugr = grid.ActiveRow; if (ugr.HasParent()) { ugr = ugr.ParentRow; } return ugr; } /// /// byWencheng,获取小数点后指定位数的double值 /// /// 源double /// 指定小数点后的位数 /// 结果值 public static double GetSpecDecimalBit(double dsrc, int nBit) { return Convert.ToDouble(dsrc.ToString(string.Format("f{0}", nBit))); } /// /// 往指定位置插入一列,原来在这个位置上的列会被交换到末尾 /// /// /// /// /// /// public static Infragistics.Win.UltraWinGrid.UltraGridColumn InsertColumn(string key, string caption, Infragistics.Win.UltraWinGrid.UltraGridBand band, int index) { Infragistics.Win.UltraWinGrid.UltraGridColumn col = band.Columns.Add(key, caption); band.Columns[index].Swap(col); //SetColumnPosition(band, key, index); return col; } /// /// 设置列隐藏 /// /// /// public static void SetColumsHide(Infragistics.Win.UltraWinGrid.UltraGridBand band, List columnList) { foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in band.Columns) { if (columnList.Contains(col.Key)) { col.Hidden = true; } } } public static bool IsNullOrEmptry(string srcString) { if ((srcString + "").Length == 0) { return true; } return false; } public static string getProcessCode(string CustomInfo) { string strResult = ""; switch (CustomInfo) { case CustomInfoDef.DEFINE_CUSTOMER_DBK: strResult = "E"; break; case CustomInfoDef.DEFINE_CUSTOMER_JG: strResult = "G"; break; case CustomInfoDef.DEFINE_CUSTOMER_RCL: strResult = "F"; break; case CustomInfoDef.DEFINE_CUSTOMER_ZG: strResult = "D"; break; } return strResult; } public static string getProcessDesc(string CustomInfo) { string strResult = ""; switch (CustomInfo) { case CustomInfoDef.DEFINE_CUSTOMER_DBK: strResult = "镦拔扩"; break; case CustomInfoDef.DEFINE_CUSTOMER_JG: strResult = "加工线"; break; case CustomInfoDef.DEFINE_CUSTOMER_RCL: strResult = "热处理"; break; case CustomInfoDef.DEFINE_CUSTOMER_ZG: strResult = "轧管"; break; } return strResult; } #region 私有的一些算法 /// /// 求计划切后重量 /// /// 壁厚 /// 外径 /// 切后目标长度 /// 计划切后支数 /// public static double GetCutOutWeight(Object WALLTHICK, Object OUTDIAMETER, Object AIMLENGTH_CUT, Object CUT_OUT_NUM) { double result = 0; try { double dWallThick = Convert.ToDouble(WALLTHICK); double dOutDiamEter = Convert.ToDouble(OUTDIAMETER); double dAimlenthCut = Convert.ToDouble(AIMLENGTH_CUT); double dCutOutNum = Convert.ToDouble(CUT_OUT_NUM); double WtPerMile = PlanComm.WeightOfMi(dOutDiamEter, dWallThick); //0.02466 * dWallThick * (dOutDiamEter - dWallThick); result = WtPerMile * dAimlenthCut * dCutOutNum; result = CommHelper.GetSpecDecimalBit(result, 3); } catch { } return result; } /// /// 获取作业计划表表名 /// /// public static string GetZYMtablename(string CustomInfo) { string tablename = ""; switch (CustomInfo) { case CustomInfoDef.DEFINE_CUSTOMER_DBK: tablename = "PLN_ZY_DBK_M"; break; case CustomInfoDef.DEFINE_CUSTOMER_RCL: tablename = "PLN_ZY_RCL_M"; break; case CustomInfoDef.DEFINE_CUSTOMER_JG: tablename = "PLN_ZY_JGX_M"; break; case CustomInfoDef.DEFINE_CUSTOMER_ZG: tablename = "PLN_ZY_ZG_M"; break; } return tablename; } public static string GetOrdertableName(string CustomInfo) { string tablename = ""; switch (CustomInfo) { case CustomInfoDef.DEFINE_CUSTOMER_DBK: tablename = "PLN_ORDER_DBK_S"; break; case CustomInfoDef.DEFINE_CUSTOMER_JG: tablename = "PLN_ORDER_JGX_S"; break; case CustomInfoDef.DEFINE_CUSTOMER_RCL: tablename = "PLN_ORDER_RCL_S"; break; case CustomInfoDef.DEFINE_CUSTOMER_ZG: tablename = "PLN_ORDER_ZG_S"; break; } return tablename; } public static void init_Zy_Col(UltraGridBand band) { CommHelper.SetColumnPosition(band, "PlineName", 1); CommHelper.SetColumnPosition(band, "OrderNo", 2); CommHelper.SetColumnPosition(band, "OrderSeq", 3); CommHelper.SetColumnPosition(band, "ProPlanId", 4); CommHelper.SetColumnPosition(band, "GxPlanNo", 5); CommHelper.SetColumnPosition(band, "HeatPlanNo", 6); CommHelper.SetColumnPosition(band, "HeatnoLast", 7); CommHelper.SetColumnPosition(band, "ZgBatchNo", 8); CommHelper.SetColumnPosition(band, "LastBatchNo", 8); CommHelper.SetColumnPosition(band, "BatchGroudNo", 9); CommHelper.SetColumnPosition(band, "OrderSource", 10); CommHelper.SetColumnPosition(band, "OutNum", 11); CommHelper.SetColumnPosition(band, "OutWt", 12); CommHelper.SetColumnPosition(band, "InNum", 13); CommHelper.SetColumnPosition(band, "InWt", 14); CommHelper.SetColumsHide(band, new List() { "PlineCode", "InwlId" }); band.Columns["OrderSource"].Header.Caption = "主合同来源"; band.Columns["Planstatus"].Header.Caption = "执行状态"; } /// /// 管坯米单重=(7.8*3.1415926/4*直径*直径)/1000/1000 /// /// 管坯直径 /// public static double GetCutSingleWtPerMile(Object DIAMETER_GP) { double dRet = 0; try { double dEtergp = Convert.ToDouble(DIAMETER_GP); dRet = PlanComm.GpweightOfmi(dEtergp); dRet = CommHelper.GetSpecDecimalBit(dRet, 3); } catch { } return dRet; } /// /// 计划单倍坯支数=计划产出支数/分切数 /// /// 计划产出支数 /// 分切数 /// public static int GetCutSingleNum(Object OUT_NUM, Object OUTNUM_CUT) { int nRet = 0; try { int dOutnum = Convert.ToInt32(OUT_NUM); int dOutnumCut = Convert.ToInt32(OUTNUM_CUT); nRet = dOutnum / dOutnumCut; } catch { } return nRet; } /// /// CUT_SINGLE_WT计划单倍坯重量 = 计划单倍坯支数*管坯单重 /// /// public static double GetCutSingleWt(Object CUT_SINGLE_NUM, double CutSingleWtPerMile) { double dRet = 0; try { int nCutSinleNum = Convert.ToInt32(CUT_SINGLE_NUM); dRet = nCutSinleNum * CutSingleWtPerMile; dRet = CommHelper.GetSpecDecimalBit(dRet, 3); } catch { } return dRet; } /// /// 倍尺数=管坯长度/单倍坯长(取整) /// /// 管坯长度(m) /// 单倍坯长mm /// public static int GetMultipleNum(Object LENGTH_GP, Object LEN_GP_SINGLE) { int nRet = 0; try { double dlenthgp = Convert.ToDouble(LENGTH_GP); double dlengpsingle = Convert.ToDouble(LEN_GP_SINGLE)/1000; nRet = Convert.ToInt32(Math.Truncate(dlenthgp / dlengpsingle)); } catch { } return nRet; } /// /// 获取轧管的计划投入重量=ACT_WEIGHT--重量/ ACT_COUNT,--支数 * 计划投入支数 /// /// /// /// /// public static double GetIN_GP_WT(Object ACT_WEIGHT, Object ACT_COUNT, Object IN_GP_NUM) { double nRet = 0; try { double bActWt = Convert.ToDouble(ACT_WEIGHT); int nActCount = Convert.ToInt32(ACT_COUNT); int nInGpNum = Convert.ToInt32(IN_GP_NUM); nRet = CommHelper.GetSpecDecimalBit(nInGpNum * (bActWt / nActCount), 3); } catch { } return nRet; } /// /// OUT_WT 计划产出重量= 排产重量/排产支数*用户输入支数 /// /// 用户输入支数 /// 排产重量 /// 排产支数 /// public static double GetOutWeight(Object InNum, Object WeigthS, Object NumS) { double result = 0; double SingleWeight = Convert.ToDouble(WeigthS) / Convert.ToDouble(NumS); result = Convert.ToDouble(InNum) * SingleWeight; result = CommHelper.GetSpecDecimalBit(result, 3); return result; } #endregion } }