| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- 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
- {
- /// <summary>
- /// byWencheg设置列的顺序
- /// </summary>
- /// <param name="band"></param>
- /// <param name="key"></param>
- /// <param name="index"></param>
- 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]);
- }
- }
- /// <summary>
- /// 获取指定位置的列
- /// </summary>
- /// <param name="band"></param>
- /// <param name="position"></param>
- /// <returns></returns>
- public static UltraGridColumn GetSpecPositionCol(UltraGridBand band, int position)
- {
- foreach (UltraGridColumn col in band.Columns)
- {
- if (col.Header.VisiblePosition == position)
- {
- return col;
- }
- }
- return null;
- }
- /// <summary>
- //byWenCheng 设置grid的band的列名和描述(列名和描述来自数据库的列名和描述)
- /// </summary>
- /// <param name="band">需要设置的grid的band</param>
- /// <param name="tablename">与band对应的表名</param>
- /// <param name="ob">OpenBase对象</param>
- 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();
- }
-
- }
- }
- }
- /// <summary>
- ///byWenCheng 执行sql语句
- /// </summary>
- /// <param name="sqlString"></param>
- /// <param name="_ob"></param>
- /// <returns></returns>
- 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);
- }
- /// <summary>
- ///byWenCheng 设置某band的所有列不可编辑,除了ignoreColums里包含的列
- /// </summary>
- /// <param name="band">需要设置的band</param>
- /// <param name="ignoreColums">需要忽略的列</param>
- 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;
- }
- }
- /// <summary>
- /// byWenCheng,复制数据到数据表,暂未测试速率,目前发现在查询数据时比较耗时,2000条数据2-3s
- /// </summary>
- /// <param name="srcDt"></param>
- /// <param name="desDt"></param>
- /// <param name="ClearExsit"></param>
- 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);
- }
- }
- /// <summary>
- ///byWenCheng 设置列宽根据内容自适应方法1
- /// </summary>
- /// <param name="band">需要设置的band</param>
- public static void SetColumnAutoFitSize1(UltraGridBand band)
- {
- if (band != null)
- {
- band.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand,true);
- }
- }
- /// <summary>
- ///byWenCheng 设置列宽根据内容自适应方法2
- /// </summary>
- /// <param name="band">需要设置的band</param>
- public static void SetColumnAutoFitSize2(UltraGridBand band)
- {
- if (band != null)
- {
- foreach (UltraGridColumn col in band.Columns)
- {
- col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand,true);
- }
- }
- }
- /// <summary>
- ///byWenCheng 设置行高根据内容自适应
- /// </summary>
- /// <param name="grid"></param>
- public static void SetRowAutoFitSize(UltraGrid grid)
- {
- if (grid != null)
- {
- grid.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
- }
- }
- /// <summary>
- ///byWenCheng 获取grid的激活的行,如果该行有对应的父行,则取其父行。和selected选择的行有区别的是,selectedrow是可以有多行,activedrow只能是一行,而且一般是最后选择的那一行
- /// </summary>
- /// <param name="grid"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// byWencheng,获取小数点后指定位数的double值
- /// </summary>
- /// <param name="dsrc">源double</param>
- /// <param name="nBit">指定小数点后的位数</param>
- /// <returns>结果值</returns>
- public static double GetSpecDecimalBit(double dsrc, int nBit)
- {
- return Convert.ToDouble(dsrc.ToString(string.Format("f{0}", nBit)));
- }
-
- /// <summary>
- /// 往指定位置插入一列,原来在这个位置上的列会被交换到末尾
- /// </summary>
- /// <param name="key"></param>
- /// <param name="caption"></param>
- /// <param name="band"></param>
- /// <param name="index"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 设置列隐藏
- /// </summary>
- /// <param name="band"></param>
- /// <param name="columnList"></param>
- public static void SetColumsHide(Infragistics.Win.UltraWinGrid.UltraGridBand band, List<string> 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 私有的一些算法
- /// <summary>
- /// 求计划切后重量
- /// </summary>
- /// <param name="WALLTHICK">壁厚</param>
- /// <param name="OUTDIAMETER">外径</param>
- /// <param name="AIMLENGTH_CUT">切后目标长度</param>
- /// <param name="CUT_OUT_NUM">计划切后支数</param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取作业计划表表名
- /// </summary>
- /// <returns></returns>
- 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<string>() { "PlineCode", "InwlId" });
- band.Columns["OrderSource"].Header.Caption = "主合同来源";
- band.Columns["Planstatus"].Header.Caption = "执行状态";
- }
- /// <summary>
- /// 管坯米单重=(7.8*3.1415926/4*直径*直径)/1000/1000
- /// </summary>
- /// <param name="DIAMETER_GP">管坯直径</param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 计划单倍坯支数=计划产出支数/分切数
- /// </summary>
- /// <param name="OUT_NUM">计划产出支数</param>
- /// <param name="OUTNUM_CUT">分切数</param>
- /// <returns></returns>
- 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;
- }
-
- /// <summary>
- /// CUT_SINGLE_WT计划单倍坯重量 = 计划单倍坯支数*管坯单重
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 倍尺数=管坯长度/单倍坯长(取整)
- /// </summary>
- /// <param name="LENGTH_GP">管坯长度(m)</param>
- /// <param name="LEN_GP_SINGLE">单倍坯长mm</param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取轧管的计划投入重量=ACT_WEIGHT--重量/ ACT_COUNT,--支数 * 计划投入支数
- /// </summary>
- /// <param name="ACT_WEIGHT"></param>
- /// <param name="ACT_COUNT"></param>
- /// <param name="IN_GP_NUM"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// OUT_WT 计划产出重量= 排产重量/排产支数*用户输入支数
- /// </summary>
- /// <param name="InNum">用户输入支数</param>
- /// <param name="WeigthS">排产重量</param>
- /// <param name="NumS">排产支数</param>
- /// <returns></returns>
- 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
- }
- }
|