private static TableLayoutPanel CreateTableLayoutPanel() { int row = 10; int col = 3; TableLayoutPanel tlpLayout = new TableLayoutPanel(); tlpLayout.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; tlpLayout.Dock = DockStyle.Fill; tlpLayout.RowCount = row; tlpLayout.ColumnCount = col; for (int i = 0; i < row; i++) { tlpLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); } for (int i = 0; i < col; i++) { tlpLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); } //设置tablelayoutpanel控件的DoubleBuffered 属性为true,这样可以减少或消除由于不断重绘所显示图面的某些部分而导致的闪烁 tlpLayout.GetType() .GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .SetValue(tlpLayout, true, null); return tlpLayout; }
private void btnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (barEditItem1.EditValue == null || barEditItem2.EditValue == null) { XtraMessageBox.Show("请指定明确的楼层与区域.", "错误提示"); return; } splashScreenManager1.ShowWaitForm(); if (tableLayoutPanel1 != null) { groupControl3.Controls.Remove(tableLayoutPanel1); tableLayoutPanel1.Dispose(); } try { tableLayoutPanel1 = new TableLayoutPanel(); tableLayoutPanel1.BackColor = Color.White; tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.AutoScroll = true; tableLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null); this.groupControl3.Controls.Add(tableLayoutPanel1); dt = monthCalendar1.SelectionStart; iPeroid = radioGroup1.SelectedIndex; iFloorId = Convert.ToDecimal(barEditItem1.EditValue); iAreaId = Convert.ToDecimal(barEditItem2.EditValue); List<MACHINE_SCHEDULE> lstMc1 = db.Fetch<MACHINE_SCHEDULE>("where SCHEDULE_TIME = @0 and SCHEEDULE_PERIOD = @1 and FLOOR_ID = @2 and AREA_ID = @3", new object[] { monthCalendar1.SelectionStart, radioGroup1.SelectedIndex, barEditItem1.EditValue, barEditItem2.EditValue }); List<MACHINE_INFO> lstInfo = db.Fetch<MACHINE_INFO>("where FLOOR_ID = @0 and AREA_ID = @1 order by BED_NO", new object[] { barEditItem1.EditValue, barEditItem2.EditValue }); MACHINE_LAYOUT mL = db.SingleOrDefault<MACHINE_LAYOUT>("where floorid = @0 and areaid = @1", new object[] { barEditItem1.EditValue, barEditItem2.EditValue }); int iRow = 0; // 行数 int iCol = 0; // 列数 int iCount = 0; // 透析机总数 if (lstInfo != null && lstInfo.Count > 0 && mL != null) { iRow = Convert.ToInt32(mL.ROOMROWS); iCol = Convert.ToInt32(Math.Ceiling((decimal)lstInfo.Count / (decimal)mL.ROOMROWS)); // 向上取整 iCount = lstInfo.Count; tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.Size = new System.Drawing.Size(0, 0); tableLayoutPanel1.AutoSize = true; tableLayoutPanel1.RowStyles.Clear(); tableLayoutPanel1.Controls.Clear(); tableLayoutPanel1.RowCount = iRow; tableLayoutPanel1.ColumnCount = iCol; tableLayoutPanel1.ColumnStyles.Clear(); for (int i = 0; i < iRow; i++) { RowStyle rs = new RowStyle(); rs.SizeType = SizeType.Percent; tableLayoutPanel1.RowStyles.Add(rs); } for (int i = 0; i < iCol; i++) { ColumnStyle cs = new ColumnStyle(); cs.SizeType = SizeType.AutoSize; tableLayoutPanel1.ColumnStyles.Add(cs); } int iCnt = 0; for (int r = 0; r < iRow; r++) { for (int c = 0; c < iCol; c++) { if (iCnt < iCount) { // 生成控件 UcDialysis uc = new UcDialysis(lstPatientReg, lstPatientBaseInfo, dt, iFloorId, iAreaId, iPeroid, iFrmType); uc.No = lstInfo[iCnt].BED_NO; uc.Model = lstInfo[iCnt].MODEL; uc.M_Type = lstInfo[iCnt].MACHINETYPE; uc.SN = lstInfo[iCnt].SN; uc.InfoID = lstInfo[iCnt].ID; // 获取该设备的图片 MACHINE_TYPE mType = db.SingleOrDefault<MACHINE_TYPE>("where MODEL = @0 AND M_TYPE = @1", new object[] { lstInfo[iCnt].MODEL, lstInfo[iCnt].MACHINETYPE }); if (mType != null && mType.M_PICTURE != null && mType.M_PICTURE.Length > 0) uc.Pict = mType.M_PICTURE; // 根据不同功能,控件按钮全能 switch (iFrmType) { case 0: { uc.StatusOP = false; uc.CheckIn = false; uc.Maintence = false; uc.Idel = false; break; } case 1: { uc.StatusOP = false; uc.Maintence = false; uc.SearchPt = false; uc.Idel = false; break; } case 2: { uc.StatusOP = false; uc.SearchPt = false; uc.CheckIn = false; break; } } // 加载预约/签到/维护等信息 var v = lstMc1.Where(s => s.BED_NO == lstInfo[iCnt].BED_NO).FirstOrDefault<MACHINE_SCHEDULE>(); if (v != null) { if (v.MACHINE_STATUS != null) uc.Status = (decimal?)v.MACHINE_STATUS; else uc.Status = 74; // 空闲 uc.PtNo = Convert.ToInt32(v.PT_ID); uc.ScheduleID = v.ID; uc.CheckInTime = v.CHCKINTM; uc.ReservTm = v.RESERVATION; } else { uc.Status = 74; uc.PtNo = null; } try { tableLayoutPanel1.Controls.Add(uc); } catch (Exception err) { Console.WriteLine(err.Message); } } iCnt++; } } } else tableLayoutPanel1.Controls.Clear(); } catch(Exception err) { splashScreenManager1.CloseWaitForm(); MessageBox.Show("未知错误. 错误原因: " + err.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } splashScreenManager1.CloseWaitForm(); }
private void Display(object sender, DataEventArgs e) { IEnumerable<StockInfo> stockList = e.Stocks; if (!DataService.EnableStock) stockList = stockList.Where(r => r.IsSilver); try { #region format //简单通知 //string notifyFormat = "{0}:{1}{2}%{6}%"; string tipsFormat = @"{0} 涨:{9}% 换:{14}% 盈:{11} 现价:{3} 成本:{13} 股:{12} 最高:{4} 最低:{5} 今开:{1} 昨收:{2} 成交量/额:{6}手/{7}万元 买: 卖: {15} 代码:{16} 板块:{17} {18} 时间:{8} 当前:{10}"; string fiveDealFormat = @"{0}:{1} {2}:{3}"; #endregion #region 桌面控件初始化 TableLayoutPanel tableLayoutPanel1 = new TableLayoutPanel(); tableLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel1, true, null); tableLayoutPanel1.SuspendLayout(); var rowStyle = new RowStyle(SizeType.Absolute, 9); for (int j = 0; j < 50; j++) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 10)); } tableLayoutPanel1.ColumnCount = 1; tableLayoutPanel1.RowCount = stockList.Count(); tableLayoutPanel1.Height = tableLayoutPanel1.RowCount * 10; tableLayoutPanel1.Dock = DockStyle.Fill; List<Control> controls = new List<Control>(); foreach (Control item in tableLayoutPanel1.Controls) { controls.Add(item); } foreach (var item in controls) { item.Dispose(); } tableLayoutPanel1.Controls.Clear(); #endregion int rowIndex = 0; ToolTip tip = new ToolTip(); #region 显示每一只股票 //只显示指定的股票 并且先按Order+BuyCount排序 var stocks = stockList.Where(row => row.ShowInFolatWindow).OrderByDescending(row => row.Order).ThenByDescending(row => row.BuyCount); foreach (var rtStock in stocks) { Label stockLabel = this.GetNewlabel(rtStock.Order >= -1 && rtStock.Order <= 1); stockLabel.ForeColor = GetWarnColor(rtStock); #region 股票桌面信息 stockLabel.Tag = rtStock.Code; string nameInShort = GetUpOrDownArrowCompareToLastDay(rtStock) + " " + rtStock.SpellingInShort.PadLeft(4, ' '); stockLabel.Text = string.Format(Constants.Setting.DeskDisplayFormat , nameInShort //简称 , Math.Round(rtStock.PriceNow, rtStock.PriceNow >= 1000 ? 1 : 2).ToString().PadLeft(6, ' ') //当前价格 , (rtStock.SurgedRange.ToString() + "%").PadLeft(7, ' ') //当日涨幅 , (rtStock.CurrentProfit.ToString()).PadLeft(6, ' ') //当前盈亏 , Math.Round(rtStock.SumProfit, 0).ToString().PadLeft(6, ' ') //总盈亏 , (Math.Round(rtStock.SumProfitPercent * 100, 2).ToString() + "%").PadLeft(8, ' ') //总盈亏比例 , Math.Round(rtStock.BuyPrice, 2).ToString().PadLeft(6, ' ') //成本价 , rtStock.BuyCount.ToString().PadLeft(5, ' ') //股数 , (rtStock.TurnOver.ToString() + "%").PadLeft(7, ' ') //换手率 , rtStock.MarketValue.ToString().PadLeft(6, ' ') //当前市值 , Math.Round(rtStock.SumCost, 0).ToString().PadLeft(6, ' ') ); #endregion #region 股票提示信息 string fiveDeal = new StringBuilder() .AppendFormat(fiveDealFormat, rtStock.Buy1Price.ToString().PadLeft(5, ' '), rtStock.Buy1Count.ToString().PadLeft(6, ' '), rtStock.Sell1Price.ToString().PadLeft(5, ' '), rtStock.Sell1Count.ToString().PadLeft(6, ' ')).AppendLine() .AppendFormat(fiveDealFormat, rtStock.Buy2Price.ToString().PadLeft(5, ' '), rtStock.Buy2Count.ToString().PadLeft(6, ' '), rtStock.Sell2Price.ToString().PadLeft(5, ' '), rtStock.Sell2Count.ToString().PadLeft(6, ' ')).AppendLine() .AppendFormat(fiveDealFormat, rtStock.Buy3Price.ToString().PadLeft(5, ' '), rtStock.Buy3Count.ToString().PadLeft(6, ' '), rtStock.Sell3Price.ToString().PadLeft(5, ' '), rtStock.Sell3Count.ToString().PadLeft(6, ' ')).AppendLine() .AppendFormat(fiveDealFormat, rtStock.Buy4Price.ToString().PadLeft(5, ' '), rtStock.Buy4Count.ToString().PadLeft(6, ' '), rtStock.Sell4Price.ToString().PadLeft(5, ' '), rtStock.Sell4Count.ToString().PadLeft(6, ' ')).AppendLine() .AppendFormat(fiveDealFormat, rtStock.Buy5Price.ToString().PadLeft(5, ' '), rtStock.Buy5Count.ToString().PadLeft(6, ' '), rtStock.Sell5Price.ToString().PadLeft(5, ' '), rtStock.Sell5Count.ToString().PadLeft(6, ' ')) .ToString(); string stockTips = string.Format(tipsFormat , rtStock.Name , rtStock.PriceTodayStart , rtStock.PriceYesterdayEnd , rtStock.PriceNow , rtStock.PriceTodayHigh , rtStock.PriceTodayLow , rtStock.DealsStockAmt , rtStock.DealsMoney , rtStock.DateTime , rtStock.SurgedRange , rtStock.Now , rtStock.CurrentProfit , rtStock.BuyCount , rtStock.BuyPrice , rtStock.TurnOver , fiveDeal , rtStock.Code , rtStock.CategroyDesc , rtStock.Description ); tip.SetToolTip(stockLabel, stockTips); #endregion tableLayoutPanel1.Controls.Add(stockLabel, 0, rowIndex); rowIndex++; } #endregion #region 表格标题信息 Label columnNamesLabel = GetNewlabel(true); columnNamesLabel.Click += new EventHandler((label, args) => { EnableDisableAutoHide(); }); columnNamesLabel.Text = string.Format(Constants.Setting.DeskDisplayFormat , "Name".PadLeft(6, ' ') //简称 , "Now¥".PadLeft(6, ' ') //当前价格 , "↓↑%".PadLeft(7, ' ') //当日涨幅 , "PF".PadLeft(6, ' ') //当前盈亏 , "∑PF".PadLeft(6, ' ') //总盈亏 , "∑PF%".PadLeft(8, ' ') //总盈亏比例 , "Cost¥".PadLeft(6, ' ') //成本价 , "*".PadLeft(5, ' ') //股数 , "Turn%".PadLeft(7, ' ') //换手率 , "Mkt¥".PadLeft(6, ' ') //当前市值 , "∑Cost¥".PadLeft(6, ' ') //总成本 ); tip.SetToolTip(columnNamesLabel, string.Format(Constants.Setting.DeskDisplayFormat , "Name:简称" + Environment.NewLine //简称 , "Now¥:当前价格" + Environment.NewLine //当前价格 , "↓↑%:当日涨幅" + Environment.NewLine //当日涨幅 , "PF:当前盈亏" + Environment.NewLine //当前盈亏 , "∑PF:总盈亏" + Environment.NewLine //总盈亏 , "∑PF%:总盈亏比例" + Environment.NewLine //总盈亏比例 , "Cost¥:成本价" + Environment.NewLine //成本价 , "*:股数" + Environment.NewLine //股数 , "Turn%:换手率" + Environment.NewLine //换手率 , "Mkt¥:当前市值" + Environment.NewLine //当前市值 , "∑Cost¥:总成本" + Environment.NewLine //总成本 )); tableLayoutPanel1.Controls.Add(columnNamesLabel, 0, rowIndex++); #endregion #region 总盈亏信息 string[] summaryInfo = new string[] { "", "" }; if (DataService.EnableStock) summaryInfo = GetStockSummaryMessage(stockList); string summaryMessage = string.Format("{0}{1}", summaryInfo[0], e.Stocks.FirstOrDefault(r => r.IsSilver).PriceNow); Label summaryLabel = GetNewlabel(); tableLayoutPanel1.Tag = summaryLabel.Text = summaryMessage; if (!DataService.EnableStock) summaryLabel.Text = ""; tip.SetToolTip(summaryLabel, summaryInfo[1]); tableLayoutPanel1.Controls.Add(summaryLabel, 0, rowIndex++); #endregion tableLayoutPanel1.ResumeLayout(); #region 实时显示股票警告信息到桌面标题 FormInvokArgument argument = new FormInvokArgument() { tableLayoutPanel1 = tableLayoutPanel1, }; if (this.InvokeRequired == true) { this.Invoke(new Action<FormInvokArgument>(ShowStockInDesk), argument); } else { ShowStockInDesk(argument); } #endregion } catch (Exception ex) { MessageSvc.Default.Write(MessageLevel.Error, ex); } }