private void DownFile() { if (_displayList == null) { return; } for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i]; if (pd.fieldType == "IMAGE" && pd.fieldValue == null) //下载文件,每行只下载一次 { try { byte[] barrImage = (byte[])pd.fieldValue; if (barrImage.Length <= 8)//空文件 { continue; } int iFileType = 8; byte[] barrType = new byte[iFileType]; byte[] barrData = new byte[barrImage.Length - iFileType]; Array.Copy(barrImage, 0, barrType, 0, iFileType); Array.Copy(barrImage, iFileType, barrData, 0, barrImage.Length - iFileType); string fileType = Encoding.ASCII.GetString(barrType); fileType.Trim('\0'); int ips = fileType.IndexOf('\0'); if (ips >= 0) { fileType = fileType.Substring(0, ips); } MemoryStream ms = new MemoryStream(barrData); Random rdom = new Random(); string filename = System.Windows.Forms.Application.StartupPath + "\\temp\\f" + rdom.Next(1000).ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); if (fileType.Length > 0) { filename += "." + fileType; } FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Write); stream.SetLength(barrData.LongLength); stream.Write(barrData, 0, barrData.Length); //将二进制文件写到指定目录 stream.Close(); pd.fileName = filename; } catch (Exception fileEx) { string info = string.Format("下载文件失败:{0}", fileEx.Message); PMS.Libraries.ToolControls.PMSPublicInfo.Message.Warnning(PMS.Libraries.ToolControls.PMSPublicInfo.CurrentPrjInfo.CurrentLoginUserID, info, false); } _displayList[i] = pd; } } }
public PmsDisplay(PmsDisplay pd) { this.fieldName = pd.fieldName; this.fieldTag = pd.fieldTag; this.bDisplay = pd.bDisplay; this.uSort = pd.uSort; this.uSortOrder = pd.uSortOrder; this.bStandard = pd.bStandard; this.fieldValue = pd.fieldValue; this.fieldValue1 = pd.fieldValue1; this.fieldValue2 = pd.fieldValue2; this.fieldType = pd.fieldType; this.columnWidth = pd.columnWidth; this.fileName = pd.fileName; this.bInEditList = pd.bInEditList; this.FormatColor = pd.FormatColor; }
/// <summary> /// 2012.1.31 增加 /// 目的:增加了成组控件后需要递归给其子控件的赋值 /// </summary> /// <param name="Aim">子控件集合</param> /// <returns>返回处理结果</returns> private int SetChildrenValue(Control.ControlCollection Aim) { int result = 0; if (Aim == null) { return(result); } foreach (Control cmp in Aim) { if (cmp is TextBoxEx) { TextBoxEx pTB = (TextBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i]; if (pd.fieldName == pTB.RField) { if (pd.fieldValue != null) { pTB.Text = pd.fieldValue.ToString(); } break; } } } else if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { string strValue = ""; if (pd.fieldValue != null) { strValue = pd.fieldValue.ToString(); } for (int iPos = 0; iPos < pTB.Items.Count; iPos++) { string strItem = (string)pTB.Items[iPos]; int nPos = strItem.IndexOf(" -> "); if (nPos < 0) { pTB.Text = strValue; goto ComboBoxEnd; } strItem = strItem.Substring(0, nPos); if (strItem == strValue) { pTB.SelectedIndex = iPos; goto ComboBoxEnd; } } pTB.Text = strValue; break; } } } else if (cmp is ForeignKeyCtrlEx) { ForeignKeyCtrlEx pTB = (ForeignKeyCtrlEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { if (this._runPageData.BReplace) { pTB.Tag = pd.fieldValue1; } else { pTB.Tag = pd.fieldValue; } if (pd.fieldValue != null) { pTB.Text = pd.fieldValue.ToString(); } pTB.tag1 = pd.fieldValue2; break; } } } else if (cmp is CheckBoxEx) { CheckBoxEx pTB = (CheckBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { try { pTB.Checked = Convert.ToBoolean(pd.fieldValue); } catch { pTB.Checked = false; } break; } } } else if (cmp is RadioButtonEx) { RadioButtonEx pTB = (RadioButtonEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { try { pTB.Checked = Convert.ToBoolean(pd.fieldValue); } catch { pTB.Checked = false; } break; } } } else if (cmp is GroupBoxEx) { GroupBoxEx pTB = (GroupBoxEx)cmp; if (pTB.Controls != null) { SetChildrenValue(pTB.Controls); } } if (cmp is NumericUpDownEx) { NumericUpDownEx pTB = (NumericUpDownEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i]; if (pd.fieldName == pTB.RField) { if (pd.fieldValue != null) { try { pTB.Value = Convert.ToDecimal(pd.fieldValue); } catch (System.Exception ex) { PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(ex.Message); } } break; } } } else if (cmp is FileDisplay) { FileDisplay pTB = (FileDisplay)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { pTB.Url = pd.fileName; } } } ComboBoxEnd: cmp.Invalidate(); if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; if (pTB.Items.Count > 0 && pTB.SelectedIndex < 0) { pTB.SelectedIndex = 0; } } } return(result); }
private void setNewValue() { if (_displayList == null) { return; } DownFile(); try { foreach (TabPage tabPage in tabControl1.TabPages) { foreach (Control cmp in tabPage.Controls) { #region textbox if (cmp is TextBoxEx) { TextBoxEx pTB = (TextBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i]; if (pd.fieldName == pTB.RField) { if (pd.fieldValue != null) { pTB.Text = pd.fieldValue.ToString(); } break; } } } else if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { string strValue = ""; if (pd.fieldValue != null) { strValue = pd.fieldValue.ToString(); } for (int iPos = 0; iPos < pTB.Items.Count; iPos++) { string strItem = (string)pTB.Items[iPos]; int nPos = strItem.IndexOf(" -> "); if (nPos < 0) { pTB.Text = strValue; goto ComboBoxEnd; } strItem = strItem.Substring(0, nPos); if (strItem == strValue) { pTB.SelectedIndex = iPos; goto ComboBoxEnd; } } pTB.Text = strValue; break; } } } else if (cmp is ForeignKeyCtrlEx) { ForeignKeyCtrlEx pTB = (ForeignKeyCtrlEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { if (this._runPageData.BReplace) { pTB.Tag = pd.fieldValue1; } else { pTB.Tag = pd.fieldValue; } if (pd.fieldValue != null) { pTB.Text = pd.fieldValue.ToString(); } pTB.tag1 = pd.fieldValue2; break; } } } else if (cmp is CheckBoxEx) { CheckBoxEx pTB = (CheckBoxEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { try { pTB.Checked = Convert.ToBoolean(pd.fieldValue); } catch { pTB.Checked = false; } break; } } } else if (cmp is RadioButtonEx) { RadioButtonEx pTB = (RadioButtonEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { try { pTB.Checked = Convert.ToBoolean(pd.fieldValue); } catch { pTB.Checked = false; } break; } } } else if (cmp is GroupBoxEx) { GroupBoxEx pTB = (GroupBoxEx)cmp; if (pTB.Controls != null) { SetChildrenValue(pTB.Controls); } } else if (cmp is NumericUpDownEx) { NumericUpDownEx pTB = (NumericUpDownEx)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i]; if (pd.fieldName == pTB.RField) { if (pd.fieldValue != null) { try { pTB.Value = Convert.ToDecimal(pd.fieldValue); } catch (System.Exception ex) { PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(ex.Message); } } break; } } } else if (cmp is FileDisplay) { FileDisplay pTB = (FileDisplay)cmp; for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pd = _displayList[i];//ElementAt(i); if (pd.fieldName == pTB.RField) { pTB.Url = pd.fileName; } } } ComboBoxEnd: cmp.Invalidate(); if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; if (pTB.Items.Count > 0 && pTB.SelectedIndex < 0) { pTB.SelectedIndex = 0; } } #endregion } } } catch (Exception e) { PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(PMS.Libraries.ToolControls.PMSPublicInfo.CurrentPrjInfo.CurrentLoginUserID, "设置数据异常:" + e.Message.ToString() + " " + e.GetBaseException().ToString(), true); } }
/// <summary> /// 2012.1.31 增加 /// 目的:增加了成组控件后需要递归获取其子控件的值 /// </summary> /// <param name="Aim">子控件集合</param> /// <returns>返回处理结果</returns> private int GetChildrenValue(Control.ControlCollection Aim) { int result = 0; if (Aim == null) { return(result); } if (_displayList == null) { return(result); } for (int i = 0; i < _displayList.Count; i++) { _displayList[i].bInEditList = false; } for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pf = _displayList[i]; bool bFind = false; foreach (Control cmp in Aim) { if (cmp is TextBoxEx) { TextBoxEx pTB = (TextBoxEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Text; bFind = true; } } else if (cmp is FileDisplay) { FileDisplay pTB = (FileDisplay)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Url; bFind = true; } } else if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = ""; int nPos = pTB.Text.IndexOf(" -> "); if (nPos < 0) { strValue1 = pTB.Text; } else { strValue1 = pTB.Text.Substring(0, nPos); } pf.fieldValue = strValue1; bFind = true; } } else if (cmp is ForeignKeyCtrlEx) { ForeignKeyCtrlEx pTB = (ForeignKeyCtrlEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Tag; bFind = true; } } else if (cmp is CheckBoxEx) { CheckBoxEx pTB = (CheckBoxEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = string.Format("{0}", pTB.Checked); pf.fieldValue = strValue1; bFind = true; } } else if (cmp is RadioButtonEx) { RadioButtonEx pTB = (RadioButtonEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = string.Format("{0}", pTB.Checked); pf.fieldValue = strValue1; bFind = true; } } else if (cmp is GroupBoxEx) { GroupBoxEx pTB = (GroupBoxEx)cmp; if (pTB.Controls != null) { GetChildrenValue(pTB.Controls); } } else if (cmp is NumericUpDownEx) { NumericUpDownEx pTB = (NumericUpDownEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Value; bFind = true; break; } } } if (bFind == true) { pf.bInEditList = true; } } return(result); }
private void getNewValue() { if (_displayList == null) { return; } for (int i = 0; i < _displayList.Count; i++) { _displayList[i].bInEditList = false; } for (int i = 0; i < _displayList.Count; i++) { PmsDisplay pf = _displayList[i]; bool bFind = false; foreach (TabPage tabPage in tabControl1.TabPages) { IEnumerator enumerator = tabPage.Controls.GetEnumerator(); while (enumerator.MoveNext()) { #region 取控件值 Control cmp = (Control)enumerator.Current; if (cmp is TextBoxEx) { TextBoxEx pTB = (TextBoxEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Text; bFind = true; break; } } else if (cmp is FileDisplay) { FileDisplay pTB = (FileDisplay)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Url; bFind = true; break; } } else if (cmp is ComboBoxEx) { ComboBoxEx pTB = (ComboBoxEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = ""; int nPos = pTB.Text.IndexOf(" -> "); if (nPos < 0) { strValue1 = pTB.Text; } else { strValue1 = pTB.Text.Substring(0, nPos); } pf.fieldValue = strValue1; bFind = true; break; } } else if (cmp is ForeignKeyCtrlEx) { ForeignKeyCtrlEx pTB = (ForeignKeyCtrlEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Tag; bFind = true; break; } } else if (cmp is CheckBoxEx) { CheckBoxEx pTB = (CheckBoxEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = string.Format("{0}", pTB.Checked); pf.fieldValue = strValue1; bFind = true; break; } } else if (cmp is RadioButtonEx) { RadioButtonEx pTB = (RadioButtonEx)cmp; if (pf.fieldName == pTB.RField) { string strValue1 = string.Format("{0}", pTB.Checked); pf.fieldValue = strValue1; bFind = true; break; } } else if (cmp is GroupBoxEx) { GroupBoxEx pTB = (GroupBoxEx)cmp; if (pTB.Controls != null) { GetChildrenValue(pTB.Controls); } } else if (cmp is NumericUpDownEx) { NumericUpDownEx pTB = (NumericUpDownEx)cmp; if (pf.fieldName == pTB.RField) { pf.fieldValue = pTB.Value; bFind = true; break; } } #endregion } if (bFind == true) { pf.bInEditList = true; break; } } } }