private GridColumn CreateGridColumn(GridView gv, DataRow dr, BindingSource ds, string tablename, int index, bool isuseredit) { //******************************特别提示********************************************* //Tip:如果要在Grid中取得自定义添加的控件,例如lkp,cbx,mtxt,btxt,mlkp控件 //lkp控件:用Controls.Find()方法来查找出lkp控件 //其他类型:用GridControl.RepositoryItems集合中查找 //*********************************************************************************** GridColumn cols = new GridColumn(); string sControlType = dr["sControlType"].ToString(); switch (sControlType) { //LookUp查询 case "lkp": { if (!string.IsNullOrEmpty(dr["sLookupNo"].ToString())) { SunriseLookUp lkp = new SunriseLookUp(); lkp.Name = "collkp" + tablename + dr["sFieldName"].ToString(); lkp.DataBindings.Add("EditValue", ds, dr["sFieldName"].ToString()); this.pnlMain.Controls.Add(lkp); lkp.SendToBack(); Base.InitLookup(lkp, dr["sLookupNo"].ToString()); if (!string.IsNullOrEmpty(dr["sLookupAutoSetControl"].ToString())) { string[] sItem = Public.GetSplitString(dr["sLookupAutoSetControl"].ToString(), ","); foreach (var s in sItem) { string[] ss = Public.GetSplitString(s, "="); lkp.AutoSetValue(ss[0], ss[1]); } } RepositoryItemButtonEdit btnRepositoryItem = new RepositoryItemButtonEdit(); btnRepositoryItem.ButtonClick += lkp.LookUpSelfClick; btnRepositoryItem.TextEditStyle = TextEditStyles.DisableTextEditor; //加这句是让了焦点更新,Grid中才会显示新的数据值,其实在后台是已经存在了的,只是在Grid中没有显示出来 //此处设置为查询完成后自动跳转到Grid中的下一列中 lkp.LookUpAfterPost += new SunriseLookUp.SunriseLookUpEvent(lkp_LookUpAfterPost); cols.ColumnEdit = btnRepositoryItem; gv.GridControl.RepositoryItems.Add(btnRepositoryItem); } break; } //下拉框 case "cbx": { if (!string.IsNullOrEmpty(dr["sLookupNo"].ToString())) { RepositoryItemImageComboBox cbxRepositoryItem = new RepositoryItemImageComboBox(); cbxRepositoryItem.Name = "colcbx" + tablename + dr["sFieldName"].ToString(); Base.InitRepositoryItemComboBox(cbxRepositoryItem, dr["sLookupNo"].ToString(), dr["sFieldType"].ToString()); cols.ColumnEdit = cbxRepositoryItem; gv.GridControl.RepositoryItems.Add(cbxRepositoryItem); } break; } //带按钮的文本框 case "btxt": { RepositoryItemButtonEdit btxtRepositoryItem = new RepositoryItemButtonEdit(); btxtRepositoryItem.Name = "colbtxt" + tablename + dr["sFieldName"].ToString(); cols.ColumnEdit = btxtRepositoryItem; gv.GridControl.RepositoryItems.Add(btxtRepositoryItem); break; } //多行文本框 case "mtxt": { RepositoryItemMemoExEdit btxtRepositoryItem = new RepositoryItemMemoExEdit(); btxtRepositoryItem.Name = "colmtxt" + tablename + dr["sFieldName"].ToString(); cols.ColumnEdit = btxtRepositoryItem; gv.GridControl.RepositoryItems.Add(btxtRepositoryItem); break; } case "dett": { RepositoryItemDateEdit dettRespositoryItem = new RepositoryItemDateEdit(); dettRespositoryItem.Name = "coldett" + tablename + dr["sFieldName"].ToString(); dettRespositoryItem.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dettRespositoryItem.DisplayFormat.FormatString = "g"; dettRespositoryItem.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dettRespositoryItem.EditFormat.FormatString = "g"; dettRespositoryItem.EditMask = "g"; cols.ColumnEdit = dettRespositoryItem; gv.GridControl.RepositoryItems.Add(dettRespositoryItem); break; } //MLookUp查询 case "mlkp": { if (!string.IsNullOrEmpty(dr["sLookupNo"].ToString())) { SunriseMLookUp mlkp = new SunriseMLookUp(); mlkp.Name = "colmlkp" + tablename + dr["sFieldName"].ToString(); mlkp.DataBindings.Add("EditValue", ds, dr["sFieldName"].ToString()); mlkp.IsUsedInGrid = true; Base.InitMLookup(mlkp, dr["sLookupNo"].ToString()); if (!string.IsNullOrEmpty(dr["sLookupAutoSetControl"].ToString())) { string[] sItem = Public.GetSplitString(dr["sLookupAutoSetControl"].ToString(), ","); foreach (var s in sItem) { string[] ss = Public.GetSplitString(s, "="); mlkp.AutoSetValue(ss[0], ss[1]); } } RepositoryItemPopupContainerEdit btnRepositoryItem = new RepositoryItemPopupContainerEdit(); btnRepositoryItem.Name = "gridmlkp" + tablename + dr["sFieldName"].ToString(); //原本默认的显示Popup的按钮隐藏掉 btnRepositoryItem.Buttons[0].Visible = false; btnRepositoryItem.Buttons.Add(new EditorButton(ButtonPredefines.Ellipsis)); btnRepositoryItem.ButtonClick += mlkp.LookUpSelfClick; btnRepositoryItem.TextEditStyle = TextEditStyles.Standard; btnRepositoryItem.Popup += mlkp.mlkpDataNo_Popup; btnRepositoryItem.KeyDown += mlkp.mlkpDataNo_KeyDown; btnRepositoryItem.Closed += mlkp.mlkpDataNo_Closed; gv.GridControl.PreviewKeyDown += mlkp.mlkpDataNo_PreviewKeyDown; btnRepositoryItem.PopupControl = mlkp.mlkpPopup; btnRepositoryItem.EditValueChanged += mlkp.mlkpDataNo_TextChanged; //加这句是让了焦点更新,Grid中才会显示新的数据值,其实在后台是已经存在了的,只是在Grid中没有显示出来 //此处设置为查询完成后自动跳转到Grid中的下一列中 mlkp.LookUpAfterPost += new SunriseLookUp.SunriseLookUpEvent(lkp_LookUpAfterPost); cols.ColumnEdit = btnRepositoryItem; gv.GridControl.RepositoryItems.Add(btnRepositoryItem); this.pnlMain.Controls.Add(mlkp); mlkp.SendToBack(); //pnlDynamic.Controls.Add(mlkp); //mlkp.Visible = false; } break; } } cols.Caption = LangCenter.Instance.IsDefaultLanguage ? dr["sCaption"].ToString() : dr["sEngCaption"].ToString(); cols.FieldName = dr["sFieldName"].ToString(); //Grid 列命名为col+表名+列名 cols.Name = "col" + tablename + dr["sFieldName"].ToString(); cols.Width = 120; if (dr["sColumnType"].ToString() == "002") { //检测是否有价格权限 bool HasPrice = SC.CheckAuth(SecurityOperation.Price, FormID); if (!HasPrice) return null; //设置价格数据显示格式 cols.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; cols.DisplayFormat.FormatString = Base.FormatPrice; } else if (dr["sColumnType"].ToString() == "003") { //检测是否有数量权限 bool HasNum = SC.CheckAuth(SecurityOperation.Num, FormID); if (!HasNum) return null; //设置数量数据显示格式 cols.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; cols.DisplayFormat.FormatString = Base.FormatQuantity; } else cols.Visible = true; //不需要权限控制的价格数量显示格式化 //无权限控制价格 if (dr["sColumnType"].ToString() == "004") { cols.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; cols.DisplayFormat.FormatString = Base.FormatNullAuthPrice; } //无权限控制数量 else if (dr["sColumnType"].ToString() == "005") { cols.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; cols.DisplayFormat.FormatString = Base.FormatNullAuthQuantity; } cols.VisibleIndex = index; //检测窗体字段设置中是否可编辑 //这里检测的时候是先以窗体设置中的权限优先,窗体上设置不可编辑,用户字段设置可编辑,以窗体上设置为准,不可编辑 cols.OptionsColumn.AllowEdit = Convert.ToBoolean(dr["bEdit"]); //先通过数量和价格权限检测后再设置其用户字段权限 if (Convert.ToBoolean(dr["bEdit"])) { cols.OptionsColumn.AllowEdit = isuseredit; } //Grid Footer显示 if (dr["sFooterType"].ToString() != "001") { //001 无 //002 求和 //003 计数 //004 平均值 //005 最大值 //006 最小值 cols.SummaryItem.FieldName = dr["sFieldName"].ToString(); if (dr["sFooterType"].ToString() == "002") cols.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; else if (dr["sFooterType"].ToString() == "003") cols.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count; else if (dr["sFooterType"].ToString() == "004") cols.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average; else if (dr["sFooterType"].ToString() == "005") cols.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Max; else if (dr["sFooterType"].ToString() == "006") cols.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Min; //设置GridFooter汇总格式 //价格 if (dr["sColumnType"].ToString() == "002") cols.SummaryItem.DisplayFormat = Base.FormatPrice; //数量 else if (dr["sColumnType"].ToString() == "003") cols.SummaryItem.DisplayFormat = Base.FormatQuantity; //无权限控制价格 else if (dr["sColumnType"].ToString() == "004") cols.SummaryItem.DisplayFormat = Base.FormatNullAuthPrice; //无权限控制数量 else if (dr["sColumnType"].ToString() == "005") cols.SummaryItem.DisplayFormat = Base.FormatNullAuthQuantity; gv.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, dr["sFieldName"].ToString(), cols); } //设置非空字段颜色 if (Convert.ToBoolean(dr["bSaveData"]) && Convert.ToBoolean(dr["bNotNull"])) { cols.AppearanceHeader.ForeColor = Color.FromName(Base.GetSystemParamter("001")); cols.AppearanceHeader.Options.UseForeColor = true; } return cols; }
/// <summary> ///初始化员工查询 /// </summary> /// <param name="lkp">LookUp控件</param> /// <param name="sReturnField">设置返回字段</param> public static void InitLkpSystemUser(SunriseLookUp lkp,string sReturnField) { InitLookUpBase(lkp, "SELECT ID,sUserID,sUserCName,sUserEName,sDeptNo,sDeptName,sRemark FROM vwsysUser WHERE bIsLock=0", sReturnField, "sUserCName", "sUserID,sUserCName,sUserEName,sDeptName,sRemark", "用户编号,中文名,英文名,部门,备注", "员工信息"); }
/// <summary> /// 初始化LookUp控件 /// </summary> /// <param name="lkp">LookUp控件</param> /// <param name="sql">查询SQL</param> /// <param name="returnfield">返回字段</param> /// <param name="displayfield">显示字段</param> /// <param name="columnfield">查询窗口Grid显示列</param> /// <param name="columntetx">查询窗口Grid列显示名称</param> /// <param name="text">查询窗体标题</param> public static void InitLookUpBase(SunriseLookUp lkp, string sql, string returnfield, string displayfield, string columnfield, string columntetx, string text) { lkp.SearchFormText = text; lkp.SQL = sql; lkp.DataField = returnfield; lkp.DisplayField = displayfield; lkp.GridDisplayField = columnfield; lkp.GridColumnText = columntetx; }
/// <summary> /// 选择门店信息 /// </summary> /// <param name="lkp">LookUp控件</param> public static void InitLkpShopID(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT sShopID,sShopCName,sShopEName,sRemark FROM hrCompanyShopInfo", "sShopID", "sShopCName", "sShopID,sShopCName,sShopEName,sRemark", "门店编号,门店名称,英文名称,备注", "门店"); }
/// <summary> /// 选择供应商 /// </summary> /// <param name="lkp">LookUp控件</param> /// <param name="sReturnField">设置返回字段</param> public static void InitLkpSupplier(SunriseLookUp lkp,string sReturnField) { InitLookUpBase(lkp, "SELECT ID,sSupplierID,sSupplierSName,sSupplierCName,sSupplierEName,sSupplierTypeName FROM vwbasSupplierMaster", sReturnField, "sSupplierSName", "sSupplierID,sSupplierSName,sSupplierCName,sSupplierEName,sSupplierTypeName", "供应商编号,供应商简称,供应商名称,英文名称,供应商类型", "供应商"); }
/// <summary> /// /// </summary> /// <param name="gv"></param> /// <param name="dr"></param> /// <param name="tableName"></param> /// <param name="index"></param> /// <param name="isuseredit"></param> /// <param name="formID"></param> /// <returns></returns> public static GridColumn GridCreateColumn(Form frm, GridView gv, DataRow drConfig, string tableName, int index, bool allowEdit, int formID, object lpkBindSource, SunriseLookUp.SunriseLookUpEvent slookHandler) { GridColumn gc = new GridColumn(); string sControlType = drConfig["sControlType"].ToString(); string sFieldName = drConfig["sFieldName"].ToString(); string sLookupNo = drConfig["sLookupNo"].ToString(); string sColumnType = drConfig["sColumnType"].ToString(); #region 设置ColumnEdit switch (sControlType) { case "lkp": #region LookUp查询 if (!string.IsNullOrEmpty(sLookupNo) && lpkBindSource != null) { SunriseLookUp lkp = new SunriseLookUp(); lkp.Name = string.Format("collkp{0}{1}", tableName, sFieldName); lkp.DataBindings.Add("EditValue", lpkBindSource, sFieldName); Base.InitLookup(lkp, sLookupNo); string sLookupAutoSetControl = drConfig["sLookupAutoSetControl"].ToString(); if (!string.IsNullOrEmpty(sLookupAutoSetControl)) { string[] sItem = Public.GetSplitString(sLookupAutoSetControl, ","); foreach (var s in sItem) { string[] ss = Public.GetSplitString(s, "="); lkp.AutoSetValue(ss[0], ss[1]); } } RepositoryItemButtonEdit btnRepositoryItem = new RepositoryItemButtonEdit(); btnRepositoryItem.ButtonClick += lkp.LookUpSelfClick; btnRepositoryItem.TextEditStyle = TextEditStyles.DisableTextEditor; //加这句是让了焦点更新,Grid中才会显示新的数据值,其实在后台是已经存在了的,只是在Grid中没有显示出来 //此处设置为查询完成后自动跳转到Grid中的下一列中 if (slookHandler != null) lkp.LookUpAfterPost += slookHandler; //if (slookHandler != null) lkp.LookUpAfterPost += new SunriseLookUp.SunriseLookUpEvent(lkp_LookUpAfterPost); gc.ColumnEdit = btnRepositoryItem; gv.GridControl.RepositoryItems.Add(btnRepositoryItem); } break; #endregion case "cbx": #region 下拉框 if (!string.IsNullOrEmpty(sLookupNo)) { RepositoryItemImageComboBox cbxRepositoryItem = new RepositoryItemImageComboBox(); Base.InitRepositoryItemComboBox(cbxRepositoryItem, sLookupNo, (string)drConfig["sFieldType"]); gc.ColumnEdit = cbxRepositoryItem; gv.GridControl.RepositoryItems.Add(cbxRepositoryItem); } break; #endregion case "btxt": #region 带按钮的文本框 RepositoryItemMemoExEdit btxtRepositoryItem = new RepositoryItemMemoExEdit(); gc.ColumnEdit = btxtRepositoryItem; gv.GridControl.RepositoryItems.Add(btxtRepositoryItem); break; #endregion //modify by han #region //多行文本框 case "mtxt": RepositoryItemMemoExEdit mtxtRepositoryItem = new RepositoryItemMemoExEdit(); mtxtRepositoryItem.Name = "colmtxt" + tableName + drConfig["sFieldName"].ToString(); gc.ColumnEdit = mtxtRepositoryItem; gv.GridControl.RepositoryItems.Add(mtxtRepositoryItem); break; case "dett": RepositoryItemDateEdit dettRespositoryItem = new RepositoryItemDateEdit(); dettRespositoryItem.Name = "coldett" + tableName + drConfig["sFieldName"].ToString(); dettRespositoryItem.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dettRespositoryItem.DisplayFormat.FormatString = "g"; dettRespositoryItem.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dettRespositoryItem.EditFormat.FormatString = "g"; dettRespositoryItem.EditMask = "g"; gc.ColumnEdit = dettRespositoryItem; gv.GridControl.RepositoryItems.Add(dettRespositoryItem); break; //MLookUp查询 case "mlkp": { if (!string.IsNullOrEmpty(drConfig["sLookupNo"].ToString())) { SunriseMLookUp mlkp = new SunriseMLookUp(); mlkp.Name = "colmlkp" + tableName + drConfig["sFieldName"].ToString(); mlkp.DataBindings.Add("EditValue", lpkBindSource, drConfig["sFieldName"].ToString()); mlkp.IsUsedInGrid = true; Base.InitMLookup(mlkp, drConfig["sLookupNo"].ToString()); if (!string.IsNullOrEmpty(drConfig["sLookupAutoSetControl"].ToString())) { string[] sItem = Public.GetSplitString(drConfig["sLookupAutoSetControl"].ToString(), ","); foreach (var s in sItem) { string[] ss = Public.GetSplitString(s, "="); mlkp.AutoSetValue(ss[0], ss[1]); } } RepositoryItemPopupContainerEdit btnRepositoryItem = new RepositoryItemPopupContainerEdit(); btnRepositoryItem.Name = "gridmlkp" + tableName + drConfig["sFieldName"].ToString(); //原本默认的显示Popup的按钮隐藏掉 btnRepositoryItem.Buttons[0].Visible = false; btnRepositoryItem.Buttons.Add(new EditorButton(ButtonPredefines.Ellipsis)); btnRepositoryItem.ButtonClick += mlkp.LookUpSelfClick; btnRepositoryItem.TextEditStyle = TextEditStyles.Standard; btnRepositoryItem.Popup += mlkp.mlkpDataNo_Popup; btnRepositoryItem.KeyDown += mlkp.mlkpDataNo_KeyDown; btnRepositoryItem.Closed += mlkp.mlkpDataNo_Closed; gv.GridControl.PreviewKeyDown += mlkp.mlkpDataNo_PreviewKeyDown; btnRepositoryItem.PopupControl = mlkp.mlkpPopup; btnRepositoryItem.EditValueChanged += mlkp.mlkpDataNo_TextChanged; //加这句是让了焦点更新,Grid中才会显示新的数据值,其实在后台是已经存在了的,只是在Grid中没有显示出来 //此处设置为查询完成后自动跳转到Grid中的下一列中 // mlkp.LookUpAfterPost += new SunriseLookUp.SunriseLookUpEvent(lkp_LookUpAfterPost); mlkp.LookUpAfterPost += slookHandler; gc.ColumnEdit = btnRepositoryItem; gv.GridControl.RepositoryItems.Add(btnRepositoryItem); frm.Controls.Add(mlkp); mlkp.Location = new Point(frm.Size.Height / 2, frm.Size.Width / 2); mlkp.SendToBack(); } break; } #endregion } #endregion gc.Caption = LangCenter.Instance.IsDefaultLanguage ? drConfig["sCaption"].ToString() : drConfig["sEngCaption"].ToString(); gc.FieldName = sFieldName; gc.Name = string.Format("col{0}{1}", tableName, sFieldName);//Grid 列命名为col+表名+列名 gc.Width = 120; if (sColumnType == "002" && !SC.CheckAuth(SecurityOperation.Price, formID)) return null;//检测是否有价格权限 if (sColumnType == "003" && !SC.CheckAuth(SecurityOperation.Num, formID)) return null;//检测是否有数量权限 gc.Visible = true; gc.VisibleIndex = index; #region 检测窗体字段设置中是否可编辑 //这里检测的时候是先以窗体设置中的权限优先,窗体上设置不可编辑,用户字段设置可编辑,以窗体上设置为准,不可编辑 bool bEdit = Convert.ToBoolean(drConfig["bEdit"]); //先通过数量和价格权限检测后再设置其用户字段权限 if (bEdit) bEdit = allowEdit; gc.OptionsColumn.AllowEdit = bEdit; #endregion #region Grid Footer显示 string sFooterType = (string)drConfig["sFooterType"]; gc.SummaryItem.FieldName = sFieldName; DevExpress.Data.SummaryItemType sitype = DevExpress.Data.SummaryItemType.None; if (sFooterType == "001") sitype = DevExpress.Data.SummaryItemType.None; //001 无 if (sFooterType == "002") sitype = DevExpress.Data.SummaryItemType.Sum;//002 求和 if (sFooterType == "003") sitype = DevExpress.Data.SummaryItemType.Count;//003 计数 if (sFooterType == "004") sitype = DevExpress.Data.SummaryItemType.Average;//004 平均值 if (sFooterType == "005") sitype = DevExpress.Data.SummaryItemType.Max;//005 最大值 if (sFooterType == "006") sitype = DevExpress.Data.SummaryItemType.Min;//006 最小值 gc.SummaryItem.SummaryType = sitype; if (sitype != DevExpress.Data.SummaryItemType.None) gv.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, sFieldName, gc); #endregion //modify by han //设置非空字段颜色 if (Convert.ToBoolean(drConfig["bSaveData"]) && Convert.ToBoolean(drConfig["bNotNull"])) { gc.AppearanceHeader.ForeColor = Color.FromName(Base.GetSystemParamter("001")); gc.AppearanceHeader.Options.UseForeColor = true; } return gc; }
/// <summary> /// 从库存中选择商品 /// </summary> /// <param name="lkp"></param> public static void InitLkpGoodInfoFromStock(SunriseLookUp lkp) { string sSql = "SELECT sGoodID,sSpec,fBasePrice,fSalePrice,fQuantity,sGoodCName,sGoodEName,sGoodTypeID, " + "sUnitID,sShopID,sGoodTypeName,sShopCName,sUnitName " + "FROM vwstkGoodStkInfoView "; InitLookUpBase(lkp, sSql, "sGoodID", "sGoodID", "sGoodID,sGoodCName,sGoodEName,sSpec,sUnitName", "商品编号,商品名称,英文名称,规格,单位", "商品信息"); }
/// <summary> /// 选择单据状态 /// </summary> /// <param name="lkp"></param> public static void InitLkpFlag(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT ID,iFlag,sFlagName FROM basBillState", "iFlag", "sFlagName", "iFlag,sFlagName", "状态值,状态", "单据状态"); }
/// <summary> /// 选择单据 /// </summary> /// <param name="lkp">LookUp控件</param> public static void InitLkpFormID(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT TOP 100 PERCENT iFormID,sMenuName FROM sysMenu WHERE iFormID<>0 ORDER BY iSort", "iFormID", "sMenuName", "iFormID,sMenuName", "FormID,模块名称", "单据"); }
/// <summary> /// 初始化数据字典 /// </summary> /// <param name="lkp">LookUp控件</param> /// <param name="sdictcategoryno">数据编号</param> public static void InitLkpDataDict(SunriseLookUp lkp, string sdictcategoryno) { string sText = Sunrise.ERP.DataAccess.DbHelperSQL.GetSingle("SELECT sDictCategoryCName FROM basDataDictMaster WHERE sDictCategoryNo='" + sdictcategoryno + "'").ToString(); InitLookUpBase(lkp, "SELECT sDictDataNo,sDictDataCName,sDictDataEName,sRemark FROM vwbasDataDictDetail WHERE bIsStop=0 AND sDictCategoryNo='" + sdictcategoryno + "'", "sDictDataNo", "sDictDataCName", "sDictDataNo,sDictDataCName,sDictDataEName,sRemark", "编号,中文名称,英文名称,备注/说明", sText); }
/// <summary> ///初始用户部门查询 /// </summary> /// <param name="lkp">LookUp控件</param> public static void InitLkpDept(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT ID,sDeptNo, sDeptName, sDeptEName, sRemark FROM vwDepartment WHERE bIsLock=0", "ID", "sDeptName", "sDeptNo,sDeptName,sDeptEName,sRemark", "部门编号,中文名称,英文名称,备注", "部门信息"); }
/// <summary> /// 选择币别 /// </summary> /// <param name="lkp">LookUp控件</param> public static void InitLkpCurrency(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT sCurrencyID,sCurrencyCName,fExchangeRate,sRemark FROM basCurrency", "sCurrencyID", "sCurrencyCName", "sCurrencyID,sCurrencyCName,fExchangeRate,sRemark", "编号,币别名称,英文名称,汇率,备注", "币别"); }
/// <summary> /// 选择公司信息 /// </summary> /// <param name="lkp"></param> public static void InitLkpCompany(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT ID,sCompanyID,sCompanySName,sCompanyCName,sCompanyEName FROM hrCompanyMaster ", "ID", "sCompanyCName", "sCompanyID,sCompanySName,sCompanyCName,sCompanyEName", "公司编号,公司简称,公司中文名称,公司英文名称", "公司信息"); }
/// <summary> /// 创建明细数据表Grid列 /// </summary> /// <param name="gv">需要创建的Grid</param> /// <param name="formID"></param> /// <param name="tablename">明细数据表名称</param> /// <param name="lpkBindSource"></param> public static void GridCreateColumns(Form frm, GridView gv, int formID, string tableName, object lpkBindSource, SunriseLookUp.SunriseLookUpEvent slookHandler) { if (gv == null) return; DataTable dtColumnsConfig = Base.GetDynamicTableData(formID, tableName); //列配置数据 gv.BeginUpdate(); gv.Columns.Clear(); int iIndex = 0; string sFilter = string.Format("bShowInGrid=1 AND sTableName='{0}'", tableName); DataRow[] drs = dtColumnsConfig.Select(sFilter); foreach (DataRow dr in drs) { string sFieldName = dr["sFieldName"].ToString(); GridColumn gc = null; DataRow[] drFields = GetFormFieldSetting(formID).Select(string.Format("sTableName='{0}' and sFieldName='{1}'", tableName, sFieldName)); bool allowEdit = true; //如果已经设置过界面字段数据 if (drFields.Length > 0) { DataRow drField = drFields[0]; if ((bool)drField["bVisiable"] == false) continue; allowEdit = (bool)drField["bEdit"]; } gc = GridCreateColumn(frm, gv, dr, tableName, iIndex, allowEdit, formID, lpkBindSource, slookHandler); iIndex++; if (gc != null) gv.Columns.Add(gc); } gv.EndUpdate(); }
/// <summary> /// 创建查询条件控件 /// </summary> private void CreatSearchControl() { try { if (dtDetail != null && dtMain != null && dtMain.Rows.Count > 0) { //每行控件数 int iControlColumn = Convert.ToInt32(dtMain.Rows[0]["iControlColumn"]); //控件间距 int iControlSpace = Convert.ToInt32(dtMain.Rows[0]["iControlSpace"]); //先计算需要生成查询的数据 DataRow[] dr = dtDetail.Select("bIsQuery=1"); //计算控件总共行数 int iRows = 0; if (dr.Length > 0) { if (dr.Length % iControlColumn != 0) { iRows = (int)Math.Floor(Convert.ToDecimal(dr.Length / iControlColumn)) + 1; } else { iRows = Convert.ToInt32(dr.Length / iControlColumn); } //设置控件数计数 int iControl = 0; for (int j = 0; j < iRows; j++) { for (int i = 0; i < iControlColumn; i++) { //控件类型 string sColumnType = dr[iControl]["sColumnType"].ToString(); //取得查询条件默认值 object oColumnDefaultValue = dr[iControl]["sDefaultValue"]; if (oColumnDefaultValue.ToString().ToLower() == "<userid>") { oColumnDefaultValue = Sunrise.ERP.Security.SecurityCenter.CurrentUserID; } //默认值中日期类型解析 if (oColumnDefaultValue.ToString().ToLower().Contains("<getdate>") && sColumnType == "D") { if (oColumnDefaultValue.ToString().Length == 9) { oColumnDefaultValue = DateTime.Now.ToShortDateString(); } else if (oColumnDefaultValue.ToString().ToLower().Contains("+")) { int iDays = Convert.ToInt32(oColumnDefaultValue.ToString().Trim().Substring(10)); oColumnDefaultValue = DateTime.Now.AddDays(iDays); } else if (oColumnDefaultValue.ToString().ToLower().Contains("-")) { int iDays = Convert.ToInt32(oColumnDefaultValue.ToString().Trim().Substring(10)); oColumnDefaultValue = DateTime.Now.AddDays(-iDays); } } if (oColumnDefaultValue.ToString() != "" && sColumnType == "K" && Convert.ToInt32(oColumnDefaultValue.ToString()) == 1) { oColumnDefaultValue = true; } else if (oColumnDefaultValue.ToString() != "" && sColumnType == "K" && Convert.ToInt32(oColumnDefaultValue.ToString()) == 0) { oColumnDefaultValue = false; } //创建控件 //Lable大小控制为80X21,其他输入控件大小为120X21 Label lbl = new Label(); lbl.AutoSize = false; lbl.Size = new Size(80, 21); lbl.Location = new Point(10 + (80 + 120 + iControlSpace) * i, 25 + (21 + 10) * j); //控件命名规则:lbl+字段名+数据行号 lbl.Name = "lbl" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); lbl.TextAlign = ContentAlignment.BottomLeft; //当控件类型为复选框时不创建Lable控件 if (sColumnType != "K") { lbl.Text = dr[iControl]["sColumnCaption"].ToString(); } grbFilter.Controls.Add(lbl); //不同类型创建不同控件 switch (sColumnType) { //字符型,数字型 case "S": case "N": { DevExpress.XtraEditors.TextEdit txt = new DevExpress.XtraEditors.TextEdit(); txt.Size = new Size(120, 21); txt.Name = "txt" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); txt.Location = new Point(10 + (80 + 120 + iControlSpace) * i + 80, 28 + (21 + 10) * j); txt.Text = oColumnDefaultValue.ToString(); //用Tag来存储查询类型 txt.Tag = dr[iControl]["sColumnFieldName"].ToString() + " " + dr[iControl]["sSearchType"].ToString(); grbFilter.Controls.Add(txt); break; } //ComboBox类型 case "C": { DevExpress.XtraEditors.ComboBoxEdit cbx = new DevExpress.XtraEditors.ComboBoxEdit(); cbx.Size = new Size(120, 21); cbx.Name = "cbx" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); cbx.Location = new Point(10 + (80 + 120 + iControlSpace) * i + 80, 28 + (21 + 10) * j); cbx.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; //写入ComboBox选择值 foreach (var item in dr[iControl]["sReturnValue"].ToString().Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { cbx.Properties.Items.Add(item); } if (dr[iControl]["sReturnValue"].ToString() != "") { if (oColumnDefaultValue.ToString() != "" && dr[iControl]["sReturnValue"].ToString().Contains(oColumnDefaultValue.ToString())) { cbx.Text = oColumnDefaultValue.ToString(); } else { cbx.SelectedIndex = -1; } } //用Tag来存储查询类型 cbx.Tag = dr[iControl]["sColumnFieldName"].ToString() + " " + dr[iControl]["sSearchType"].ToString(); grbFilter.Controls.Add(cbx); break; } //日期型 case "D": { DevExpress.XtraEditors.DateEdit det = new DevExpress.XtraEditors.DateEdit(); det.Size = new Size(120, 21); det.Name = "det" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); det.Location = new Point(10 + (80 + 120 + iControlSpace) * i + 80, 28 + (21 + 10) * j); det.Tag = dr[iControl]["sColumnFieldName"].ToString() + " " + dr[iControl]["sSearchType"].ToString(); if (oColumnDefaultValue.ToString() != "") { det.DateTime = Convert.ToDateTime(oColumnDefaultValue); } else { det.EditValue = null; } grbFilter.Controls.Add(det); break; } //复选框 case "K": { DevExpress.XtraEditors.CheckEdit chk = new DevExpress.XtraEditors.CheckEdit(); chk.Size = new Size(120, 21); chk.Name = "chk" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); chk.Location = new Point(10 + (80 + 120 + iControlSpace) * i + 80, 28 + (21 + 10) * j); //CheckBox过滤条件特殊处理 string sReturnValue = ""; if (dr[iControl]["sSearchType"].ToString().Contains("LIKE")) { sReturnValue = " '%" + dr[iControl]["sReturnValue"].ToString() + "%'"; } else { sReturnValue = " '" + dr[iControl]["sReturnValue"].ToString() + "'"; } chk.Tag = dr[iControl]["sColumnFieldName"].ToString() + " " + dr[iControl]["sSearchType"].ToString() + sReturnValue; if (oColumnDefaultValue.ToString() != "") { chk.Checked = Convert.ToBoolean(oColumnDefaultValue); } else { chk.CheckState = CheckState.Unchecked; } chk.Text = dr[iControl]["sColumnCaption"].ToString(); grbFilter.Controls.Add(chk); break; } case "L": { SunriseLookUp lkp = new SunriseLookUp(); lkp.Size = new Size(120, 21); lkp.Name = "chk" + dr[iControl]["sColumnFieldName"].ToString() + iControl.ToString(); lkp.Location = new Point(10 + (80 + 120 + iControlSpace) * i + 80, 28 + (21 + 10) * j); lkp.Tag = dr[iControl]["sColumnFieldName"].ToString() + " " + dr[iControl]["sSearchType"].ToString(); //初始化Lkp break; } } iControl++; //当计数大于等于要创建的控件数量时则退出循环 if (iControl >= dr.Length) { break; } } } } //分组条件控件设置 grbGroup.Visible = IsGroup; //grbGroup.Location = new Point(10, iRows * 31 + toolStrip1.Height); grbGroup.Location = new Point(10, iRows * 31 + 30); grbGroup.Controls.Clear(); for (int i = 0; i < dtDetail.Select("bIsGroup=1").Length; i++) { DevExpress.XtraEditors.CheckEdit chk = new DevExpress.XtraEditors.CheckEdit(); chk.Size = new Size(80, 21); chk.Location = new Point(5 + (80 + 5) * i, 25); chk.Name = "chkGrp" + dtDetail.Select("bIsGroup=1")[i]["sColumnFieldName"].ToString() + i.ToString(); chk.Text = dtDetail.Select("bIsGroup=1")[i]["sColumnCaption"].ToString(); chk.Tag = dtDetail.Select("bIsGroup=1")[i]["sColumnFieldName"].ToString(); chk.Checked = true; grbGroup.Controls.Add(chk); } grbGroup.Height = 45; grbGroup.Width = dtDetail.Select("bIsGroup=1").Length * 85 + 10; //设置查询条件面板高度 grbFilter.Height = iRows * 31 + 55 + (IsGroup == true ? grbGroup.Height : 0); } } catch (Exception ex) { Public.SystemInfo("创建查询条件控件错误!" + ex.Message, true); } }
/// <summary> /// 选择商品信息 /// </summary> /// <param name="lkp"></param> public static void InitLkpGoodInfo(SunriseLookUp lkp) { InitLookUpBase(lkp, "SELECT ID,sGoodID,sGoodCName,sGoodEName,sGoodTypeID,sUnitID,sShopID,sGoodTypeName,sUnitCName,sShopCName,ISNULL(fBasePrice,0) AS fBasePrice,ISNULL(fSalePrice,0) AS fSalePrice,dPriceDate FROM vwsalGoodInfoMasterView", "sGoodID", "sGoodCName", "sGoodID,sGoodCName,sGoodEName,sGoodTypeName,sUnitCName,sShopCName,fBasePrice,fSalePrice,dPriceDate", "商品编号,商品名称,英文名称,商品类型,单位,所属门店,进价,销售价,价格日期", "商品信息"); }
/// <summary> /// 初始化Lookup控件 /// </summary> /// <param name="lkp">LookUp控件</param> /// <param name="lookupno">Lookup配置编号</param> public static void InitLookup(SunriseLookUp lkp, string lookupno) { string sSql = "SELECT sLookupNo, sSQL, sDataField, sDisplayField, sGridDisplayField, " + "sGridColumnText, sEnGridColumnText, sSearchFormText, sEnSearchFormText " + "FROM sysLookupSetting " + "WHERE sType='LookUp' AND sLookupNo='" + lookupno + "'"; DataTable dtTmp = DbHelperSQL.Query(sSql).Tables[0]; if (dtTmp != null && dtTmp.Rows.Count > 0) { string SearchFormText = LangCenter.Instance.IsDefaultLanguage ? dtTmp.Rows[0]["sSearchFormText"].ToString() : dtTmp.Rows[0]["sEnSearchFormText"].ToString(); string SQL = dtTmp.Rows[0]["sSQL"].ToString(); string DataField = dtTmp.Rows[0]["sDataField"].ToString(); string DisplayField = dtTmp.Rows[0]["sDisplayField"].ToString(); string GridDisplayField = dtTmp.Rows[0]["sGridDisplayField"].ToString(); string GridColumnText = LangCenter.Instance.IsDefaultLanguage ? dtTmp.Rows[0]["sGridColumnText"].ToString() : dtTmp.Rows[0]["sEnGridColumnText"].ToString(); SystemPublic.InitLookUpBase(lkp, SQL, DataField, DisplayField, GridDisplayField, GridColumnText, SearchFormText); } }
/// <summary> /// 创建自定义控件 /// </summary> public void CreateDynamicControl() { if (DynamicMasterTableData.Select("bSystemColumn=0").Length > 0) { pnlDynamic.Visible = true; //每行控件数 int iControlColumn = Convert.ToInt32(DynamicMasterTableData.Rows[0]["iControlColumn"]); //控件间距 int iControlSpace = Convert.ToInt32(DynamicMasterTableData.Rows[0]["iControlSpace"]); //先计算需要生成控件的数据,去除如果在自定义字段权限设置中设置为不可见的数据 List<DataRow> drs = DynamicMasterTableData.Select("bSystemColumn=0 AND bShowInPanel=1").ToList(); if (!SecurityCenter.IsAdmin && FormFieldSetting.Rows.Count > 0) { for (int i = 0; i < drs.Count; i++) { //取只有是主表/单表的数据 foreach (DataRow drField in FormFieldSetting.Select("sTableName='" + MasterTableName + "'")) { if (drs[i]["sFieldName"].ToString() == drField["sFieldName"].ToString() && !Convert.ToBoolean(drField["bVisiable"])) { drs.Remove(drs[i]); } } } } //计算控件总共行数 int iRows = 0; if (drs.Count > 0) { if (drs.Count % iControlColumn != 0) { iRows = (int)Math.Floor(Convert.ToDecimal(drs.Count / iControlColumn)) + 1; } else { iRows = Convert.ToInt32(drs.Count / iControlColumn); } //设置控件数计数 int iControl = 0; for (int j = 0; j < iRows; j++) { for (int i = 0; i < iControlColumn; i++) { //控件类型 string sControlType = drs[iControl]["sControlType"].ToString(); //创建控件 //Lable大小控制为80X21,其他输入控件大小为120X21 Label lblControl = new Label(); lblControl.AutoSize = false; lblControl.Size = new Size(80, 21); lblControl.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i, ControlY + (21 + 10) * j); //控件命名规则:lbl+字段名 lblControl.Name = "lbl" + drs[iControl]["sFieldName"].ToString(); lblControl.TextAlign = ContentAlignment.BottomLeft; //当控件类型为复选框\单选\Label标签时不创建Lable控件 if (sControlType != "chk" && sControlType != "rad" && sControlType != "lbl") { lblControl.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sCaption"].ToString(); } else lblControl.Visible = false; pnlDynamic.Controls.Add(lblControl); switch (sControlType) { case "txt": { TextEdit txt = new TextEdit(); txt.Size = new Size(120, 21); txt.Name = "txt" + drs[iControl]["sFieldName"].ToString(); txt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(txt); break; } case "mtxt": { MemoEdit mtxt = new MemoEdit(); mtxt.Size = new Size(120, 21); mtxt.Name = "mtxt" + drs[iControl]["sFieldName"].ToString(); mtxt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(mtxt); break; } case "btxt": { MemoExEdit btxt = new MemoExEdit(); btxt.Size = new Size(120, 21); btxt.Name = "btxt" + drs[iControl]["sFieldName"].ToString(); btxt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(btxt); break; } case "cbx": { ImageComboBoxEdit cbx = new ImageComboBoxEdit(); cbx.Size = new Size(120, 21); cbx.Name = "cbx" + drs[iControl]["sFieldName"].ToString(); cbx.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(cbx); break; } case "chk": { CheckEdit chk = new CheckEdit(); chk.Size = new Size(120, 21); chk.Name = "chk" + drs[iControl]["sFieldName"].ToString(); chk.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); chk.CheckState = CheckState.Unchecked; chk.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sEngCaption"].ToString(); pnlDynamic.Controls.Add(chk); break; } case "det": { DateEdit det = new DateEdit(); det.Size = new Size(120, 21); det.Name = "det" + drs[iControl]["sFieldName"].ToString(); det.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); det.EditValue = null; pnlDynamic.Controls.Add(det); break; } case "dett": { DateEdit dett = new DateEdit(); dett.Size = new Size(120, 21); dett.Name = "dett" + drs[iControl]["sFieldName"].ToString(); dett.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); dett.EditValue = null; dett.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dett.Properties.DisplayFormat.FormatString = "g"; dett.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime; dett.Properties.EditFormat.FormatString = "g"; dett.Properties.EditMask = "g"; pnlDynamic.Controls.Add(dett); break; } case "img": { ImageEdit img = new ImageEdit(); img.Size = new Size(120, 21); img.Name = "img" + drs[iControl]["sFieldName"].ToString(); img.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(img); break; } case "lbl": { LabelControl lbl = new LabelControl(); lbl.Size = new Size(120, 21); lbl.Name = "lbl" + drs[iControl]["sFieldName"].ToString() + iControl.ToString(); lbl.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); lbl.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sEngCaption"].ToString(); pnlDynamic.Controls.Add(lbl); break; } case "lkp": { SunriseLookUp lkp = new SunriseLookUp(); lkp.Size = new Size(120, 21); lkp.Name = "lkp" + drs[iControl]["sFieldName"].ToString(); lkp.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(lkp); break; } case "mlkp": { SunriseMLookUp mlkp = new SunriseMLookUp(); mlkp.Size = new Size(120, 21); mlkp.Name = "mlkp" + drs[iControl]["sFieldName"].ToString(); mlkp.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(mlkp); break; } case "rad": { RadioGroup rad = new RadioGroup(); rad.Size = new Size(120, 21); rad.Name = "rad" + drs[iControl]["sFieldName"].ToString(); rad.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j); pnlDynamic.Controls.Add(rad); break; } } iControl++; //当计数大于等于要创建的控件数量时则退出循环 if (iControl >= drs.Count) break; } } } pnlDynamic.Height = ControlY + iRows * 31; } //初始化数据绑定 InitDataBindings(); }