Files
lserp_cs_5.0/插件库/Lskj.PubModuleCard/FrmMain.cs
T
2026-07-10 15:25:05 +08:00

1830 lines
76 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data.Linq;
using System.Linq;
using System.Diagnostics;
using System.Collections;
using System.Text.RegularExpressions;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using ExcelPlus;
using CommonLib;
using CommonLib.utils;
using Lskj.Common;
using CommonLib.data;
using System.Reflection;
using Lskj.MyControl;
using DevExpress.XtraTab;
using System.IO;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Layout;
using Lskj.PubModuleCard.Properties;
using System.Threading;
using System.Runtime.InteropServices;
namespace Lskj.PubModuleCard
{
public partial class FrmMain : FormBase
{
private bool mRunSum = false;
private DataTable mSumTable = new DataTable();//统计列
private MySearchCreateControl mSearch = new MySearchCreateControl();
private MySearchCreateControl mSearchTop = new MySearchCreateControl();
private DataTable mSearchTable = new DataTable(); // 顶部查询条件
private List<LayoutViewColumn> _images = new List<LayoutViewColumn>();
private LayoutViewColumn _colObj;
#region 私有属性
/// <summary>
/// 左边显示类型
/// </summary>
private int mLeftType { get; set; }
/// <summary>
/// 树控件表名
/// </summary>
private string TreeSql { get; set; }
/// <summary>
/// DbDataAdapter
/// </summary>
private SqlDataAdapter da { get; set; }
/// <summary>
/// 操作Dataset
/// </summary>
private DataSet ds = new DataSet();
/// <summary>
/// 系统配置表
/// </summary>
private DataRow mTabRow;
/// <summary>
/// 数据库字段配置
/// </summary>
private DataRow mTabWordRow;
/// <summary>
///
/// </summary>
private List<ToolStripMenuItem> tsmMenuList = new List<ToolStripMenuItem>();
/// <summary>
/// 条件颜色
/// </summary>
private DataTable mColorsTable;
/// <summary>
/// 搜索字段
/// </summary>
private DataTable cbSearchFiled;
private DataTable dtColumns;
/// <summary>
/// 必须录入字段
/// </summary>
private DataRow[] nullableFields;
// 不包含图片SQL,暂时解决方案:查询的时候,假如配置了bmp图片,则替换bmp字段,用于表格查询,双击显示数据则使用配置的字段
private string MyNotBmpSql;
private bool isSearch = true; // 是否为点击查询按钮获取数据
//表格编辑
private Boolean gridEdited;
private string addCond; //修改条件
private string modifyCond; //修改条件
private string deleteCond; //删除条件
private string dragCond; // 拖动条件
private string exportCond = string.Empty;
private string printCond = string.Empty;
private bool needModified;
private string serverAttachPath;
private int mSearchHide;//是否显示搜索
private int mLeftWidth; //宽度
private int mSeearchMode; // 查询模式,1.查询条件,2.下拉列表查询
private string beforeSearchSQL;
public string ModuleDllId { get; set; }
public string LeftCond;
public string UnionWhere;
public string[] Params;
private bool mInitFinish = false;
private string mParmaryKey = string.Empty;
private int mModulePriv = 0;
private Stack<string> StackObj = new Stack<string>();
#endregion
#region 缓存数据
/// <summary>
/// 基础档案、报表明细列表数据
/// </summary>
private DataTable moduleDetailTable = new DataTable();
private DataTable moduleDetailBottomTable = new DataTable();
//缓存bitmap对象资源方便进行释放
List<Bitmap> Bitlists = new List<Bitmap>();
#endregion
#region 构造函数
public FrmMain()
{
//DevExpress.XtraGrid.Localization.GridResLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraGridCHS();
//DevExpress.XtraEditors.Controls.Localizer.Active = new Dxper.LocalizationCHS.Win.XtraEditorsCHS();
//DevExpress.XtraLayout.Localization.LayoutLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraLayoutCHS();
//DevExpress.XtraPrinting.Localization.PreviewLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraPrintingCHS();
InitializeComponent();
// 左侧树设置
tvLeft.GetTreeView.AfterSelect += new TreeViewEventHandler(tvLeft_AfterSelect);
// 主界面表格设置
gcMain.LayoutView.DoubleClick += new EventHandler(GridViewpub_DoubleClick);
gcMain.LayoutView.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(gridView_SelectionChanged);
gcMain.LayoutView.ShowingEditor += new CancelEventHandler(gridView_ShowingEditor);
//gcMain.LayoutView.RowStyle += new RowStyleEventHandler(gvList_RowCellStyle);
// 左侧表格设置
gridLeft.gridView.OptionsSelection.MultiSelect = false;
gridLeft.gridView.RowCellClick += new RowCellClickEventHandler(gridView_RowCellClick);
//gridLeft.gridView.FocusedRowChanged += new FocusedRowChangedEventHandler(gridViewLeft_FocusedRowChanged);
//gcMain.gridView.CellValueChanged += new CellValueChangedEventHandler(gridBillInfo_CellValueChanged);
}
#endregion
#region 初始化数据
private void FrmGridTree_Load(object sender, EventArgs e)
{
try
{
//this.label3.Text = DateTime.Now.ToString();
this.Text = FormText;
string moduleName = Path.GetFileName(this.GetType().Assembly.Location);
DataTable dtTable = SqlHelper.ExecuteDataTable("select * from P_systemtab");
if (dtTable != null && dtTable.Rows.Count > 0)
{
if (dtTable.Columns.Contains("serverattachpath"))
serverAttachPath = dtTable.Rows[0]["serverattachpath"] + "";
}
DLLCoid = string.IsNullOrEmpty(ModuleDllId) ? DLLCoid : ModuleDllId;
mModulePriv = PubClass.GetPrivModule(DLLCoid, moduleName, OperatorId, OperatorName);
mTabRow = SqlHelper.ExecuteDataSet("select * from P_systemDlltab where DLLCoid='" + DLLCoid + "'").Tables[0].Rows[0];
mTabRow["SQL"] = PubClass.ReplaceWhereCond(PubClass.ReqSqlParam(mTabRow["SQL"] + "", OperatorId, OperatorName)) + UnionWhere;
mLeftType = Convert.ToInt32(mTabRow["dllType"]);
// #[^##]+# 左右结构的时候配置,取左侧表格数据
HandleBmp(Regex.Replace(mTabRow["SQL"] + "", "#[^##]+#", " 1=1 "));
gridEdited = !(string.IsNullOrEmpty(mTabRow["selfEdit"] + "") || mTabRow["selfEdit"] + "" == "0" || mTabRow["selfEdit"] + "" == "False");
//gcMain.gridView.OptionsBehavior.Editable = gridEdited;
addCond = mTabRow["addCond"] + "".Trim();
modifyCond = mTabRow["modifyCond"] + "".Trim();
deleteCond = mTabRow["deleteCond"] + "".Trim();
dragCond = mTabRow["dragCond"].ToString().Trim();
if (mTabRow.Table.Columns.Contains("exportCond"))
exportCond = mTabRow["exportCond"] + "";
if (mTabRow.Table.Columns.Contains("printCond"))
printCond = mTabRow["printCond"] + "";
if (mTabRow.Table.Columns.Contains("cardWidth"))
{
gcMain.CardWidth = string.IsNullOrEmpty(mTabRow["cardWidth"] + "") ? 0 : Convert.ToInt32(mTabRow["cardWidth"] + "");
}
if (mModulePriv != 1)
{
gridEdited = false;
//gcMain.gridView.OptionsBehavior.Editable = false;
addCond = addCond == "" ? " 1<>1 " : addCond + " and 1<>1";
modifyCond = modifyCond == "" ? "1<>1" : modifyCond + " and 1<>1";
deleteCond = deleteCond == "" ? "1<>1" : deleteCond + " and 1<>1";
dragCond = dragCond == "" ? "1<>1" : dragCond + " and 1<>1 ";
BtnDel.Visible = btnSave.Visible = BtnAdd.Visible = btnImprt.Visible = false;
BtnPrint.Enabled = btnExport.Enabled = BtnDel.Enabled = btnSave.Enabled = BtnAdd.Enabled = btnImprt.Enabled = false;
}
mSearchHide = Convert.ToInt32(mTabRow["searchHide"] + "");
mLeftWidth = Convert.ToInt32(mTabRow["leftWidth"] + "");
DataTable dtTag3 = SqlHelper.ExecuteDataTable(string.Format("select * from P_systemwordbooktab where tab='{0}' and fieldsqlTag=3", DLLCoid));
if (dtTag3 != null && dtTag3.Rows.Count > 0)
mTabWordRow = dtTag3.Rows[0];
mParmaryKey = PubClass.GetPrimaryKey(DLLCoid);
mColorsTable = SqlHelper.ExecuteDataTable(string.Format("select * from P_systemwordbookcolor where tab='{0}' and useflag=0 order by orderid", DLLCoid));
//加载表格
InitColumns();
//初始化菜单
if (mModulePriv == 1)
InitMenu();
cbSearchFiled = SqlHelper.ExecuteDataSet("select * from P_systemwordbooktab where tab='" + DLLCoid + "' and ifSearch =0 and isnull(username1,'')<>''").Tables[0];
//加载筛选框
cbField.DataSource = cbSearchFiled;
cbField.DisplayMember = "username1";
cbField.ValueMember = "fieldname";
if (mSearchHide == 1)
{
pl_search.Visible = false;
}
if (mLeftWidth > 0)
{
plLeft.Width = mLeftWidth;
}
//左边树结构
if (mLeftType == 1)
{
tvLeft.Visible = true;
gridLeft.Visible = panel1.Visible = pl_right_where.Visible = false;
string treeSql = mTabWordRow["fieldsql"] + "";
treeSql = PubClass.ReqSqlParam(treeSql, OperatorId, OperatorName);
PubClass.BindTree(treeSql, tvLeft.GetTreeView);
//gcMain.gridView.OptionsSelection.MultiSelect = true;
//if (mModulePriv == 1)
// gridDragTree = new GridDragTree(this, gcMain.gridControl, tvLeft.GetTreeView, Drag_EventHandler, mTabWordRow, mTabRow["SQLDT1"] + "", mParmaryKey);
}
else if (mLeftType == 2)
{
tvLeft.Visible = false;
gridLeft.Visible = true;
gridLeft.RowColorCondtion = SqlHelper.ExecuteDataSet(string.Format("select * from p_systemwordbookcolor where tab='{0}' and isnull(useflag,0)=0 order by orderid", mTabWordRow["fieldKey"] + "")).Tables[0];
string sql = "select * from p_systemwordbookgrid where fieldid=" + mTabWordRow["id"] + " order by orderid";
DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
GridColumn gridColumn = new GridColumn();
gridColumn.FieldName = row["fieldname"] + "";
gridColumn.Name = row["fieldname"] + "";
gridColumn.VisibleIndex = i;
gridColumn.Caption = row["username"].ToString();
gridColumn.Width = Convert.ToInt32(row["width"]);
gridColumn.Visible = Convert.ToInt32(row["visible"]) == 0;
if (Convert.ToInt32(row["width"]) == 0)
gridColumn.Visible = false;
gridColumn.OptionsColumn.AllowEdit = false;
gridLeft.gridView.Columns.Add(gridColumn);
}
SearchCraeteControl();
GridDrag2GridUpdate g2g = null;
//if (mModulePriv == 1)
// g2g = new GridDrag2GridUpdate(gcMain.gridControl, gridLeft.gridControl, DragGridCallBack);
string width = Lskj.PubUtils.INIHelper.Read("base_width_" + DLLCoid);
if (!string.IsNullOrEmpty(width))
{
panel1.Width = Convert.ToInt32(width);
splitterControl1.SplitPosition = Convert.ToInt32(width);
}
mInitFinish = true;
}
else
{
plLeft.Visible = false;
splitterControl1.Visible = false;
}
SearchCreateTopControl();
//模板添加删除修改导入导出
BtnAdd.Enabled = mTabRow["addEnable"] + "" == "1";
BtnDel.Enabled = mTabRow["deleteEnable"] + "" == "1";
btnSave.Enabled = mTabRow["modifyEnable"] + "" == "1" && gridEdited;
//gcMain.gridView.OptionsBehavior.Editable = mTabRow["modifyEnable"] + "" == "1" && gridEdited;
btnImprt.Enabled = mTabRow["importEnable"] + "" == "1";
btnExport.Enabled = mTabRow["exportEnable"] + "" == "1";
needModified = mTabRow["modifyEnable"] + "" == "1";
btnCondSearch_1.Enabled = mTabRow["searchEnable"] + "" == "1";
cbField.Enabled = mTabRow["searchEnable"] + "" == "1";
txtKey.Enabled = mTabRow["searchEnable"] + "" == "1";
//查询统计列
mSumTable = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemwordbooktab where tab='{0}' and isnull(vislble,0)=0 and isnull(calcExpr,'')<>''order by calcOrder asc", DLLCoid));
gcMain.SumFieldsTable = mSumTable;
if (mModulePriv != 1)
needModified = false;
HandleAddButtonState();
}
catch (Exception ex)
{
}
//this.label4.Text = DateTime.Now.ToString();
}
/// <summary>
/// 创建查询条件
/// </summary>
public void SearchCraeteControl()
{
string sql = string.Format("exec p_getControlLocation '{0}','{1}','{2}'", mTabWordRow["fieldKey"], DLLCoid, OperatorName);
DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
string SearchSql = PubClass.ReqSqlParam(mTabWordRow["fieldsql"] + " " + LeftCond, OperatorId, OperatorName);
if (dt != null && dt.Rows.Count > 0)
{
string condSql = string.Format("select * from p_systembillsourcecond where formKey='{0}'", mTabWordRow["fieldKey"]);
mSearch.LoginId = OperatorId;
mSearch.LoginName = OperatorName;
mSearch.SearchSql = PubClass.ReplaceWhereCond(SearchSql);
mSearch.ctr = pl_right_where;
mSearch.gce = gridLeft.gridControl;
mSearch.dllType = mLeftType;
mSearch.otherParams = Params;
mSearch.condDt = SqlHelper.ExecuteDataSet(condSql).Tables[0];
CreateControlModel cm = new CreateControlModel();
cm.dt = dt;
cm.ctr = pl_right_where;
cm.loginid = OperatorId;
cm.loginname = OperatorName;
int height = mSearch.CreateControlByModel(cm);
pl_right_where.Height = height;
Control[] ctl = pl_right_where.Controls.Find("btnCondSearch", true);
if ((ctl != null) && (ctl.Length > 0))
{
(ctl[0] as SimpleButton).Width = 72;
}
mSearch.runQuery();
}
else
{
gridLeft.gridControl.DataSource = SqlHelper.ExecuteDataSet(SearchSql).Tables[0];
pl_right_where.Visible = false;
}
}
/// <summary>
/// 顶部查询条件(保留之前的按列查询)
/// </summary>
public void SearchCreateTopControl()
{
string sql = string.Format("exec p_getControlLocation '{0}','{1}','{2}'", mTabRow["condKey"], DLLCoid, OperatorName);
mSearchTable = SqlHelper.ExecuteDataSet(sql).Tables[0];
if (mSearchTable != null && mSearchTable.Rows.Count > 0)
{
mSeearchMode = 1;
string condSql = string.Format("select * from p_systembillsourcecond where formKey='{0}'", mTabRow["condKey"]);
mSearchTop.LoginId = OperatorId;
mSearchTop.ModuleId = ModuleId;
mSearchTop.LoginName = OperatorName;
mSearchTop.SearchSql = PubClass.ReplaceWhereCond(MyNotBmpSql);
mSearchTop.ctr = pl_search;
mSearchTop.tvLeft = tvLeft;
mSearchTop.tvLeftDataRow = mTabWordRow;
mSearchTop.gce = gcMain.GridControl;
mSearchTop.dllType = mLeftType;
mSearchTop.otherParams = Params;
mSearchTop.onSearchClick += new EventHandler(mSearchTop_onSearchClick);
mSearchTop.condDt = SqlHelper.ExecuteDataSet(condSql).Tables[0];
mSearchTop.RememberRow = true;
CreateControlModel cm = new CreateControlModel();
cm.dt = mSearchTable;
cm.ctr = pl_search;
cm.loginid = OperatorId;
cm.loginname = OperatorName;
int height = mSearchTop.CreateControlByModel(cm);
pl_search.Height = height;
Control[] ctl = pl_search.Controls.Find("btnCondSearch", true);
if ((ctl != null) && (ctl.Length > 0))
{
(ctl[0] as SimpleButton).Width = 72;
}
if (mTabRow["searchEnable"].ToString() == "1")
{
string sqlValue = mSearchTop.SetSearchSqlValue();
if (!string.IsNullOrEmpty(sqlValue))
{
InitData(sqlValue);
}
}
}
else
{
mSeearchMode = 2;
// 假如未配置查询条件,则显示之前的下拉查询条件
label1.Visible = true;
cbField.Visible = true;
txtKey.Visible = true;
btnCondSearch_1.Visible = true;
if (mTabRow["searchEnable"].ToString() == "1")
btnSearch_Click(null, null);
}
}
public void mSearchTop_onSearchClick(object sender, EventArgs e)
{
try
{
getServerImages();
}
catch (Exception)
{
}
}
/// <summary>
///
/// </summary>
public void InitMenu()
{
GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gcMain.GridControl);
gm.DirId = mTabRow["dirid"] + "";
gm.filedKey = mParmaryKey;
gm.BindGridMenuWQ(DLLCoid);
gm.OnGridMenuClickRefreshData += new EventHandler(gm_OnGridMenuClickRefreshData);
if (mTabWordRow == null)
return;
string DllCoidLeft = mTabWordRow["fieldkey"].ToString();
GridMenu gm1 = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DllCoidLeft, "", gridLeft.gridControl);
gm1.DirId = mTabRow["dirid"] + "";
//gm1.filedKey = dtSystemwordbooktaNo["fieldname"].ToString();
gm1.BindGridMenuWQ(DllCoidLeft);
}
/// <summary>
/// 执行右键菜单后刷新表格数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gm_OnGridMenuClickRefreshData(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(beforeSearchSQL))
{
if (mSeearchMode == 1)
{
string sqlValue = mSearchTop.SetSearchSqlValue();
if (!string.IsNullOrEmpty(sqlValue))
{
InitData(sqlValue);
}
}
else
{
btnSearch_Click(null, null);
}
}
else
InitData(beforeSearchSQL);
}
public void Drag_EventHandler(object sender, DragEventArgs e)
{
MessageBox.Show("类别修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 处理图片
/// </summary>
/// <param name="sql"></param>
private void HandleBmp(string sql)
{
this.MyNotBmpSql = sql;
DataTable dtBmps = SqlHelper.ExecuteDataSet("select fieldname from P_systemwordbooktab where tab='" + DLLCoid + "' and fieldSqlTag=99").Tables[0];
foreach (DataRow row in dtBmps.Rows)
{
string fieldName = row["fieldname"] + "";
MyNotBmpSql = MyNotBmpSql.Replace(" ", "-").Replace("-", "").Replace(", ", ",").Replace(" ,", ",");
MyNotBmpSql = MyNotBmpSql.Replace("," + fieldName + ",", ",").Replace("," + fieldName, " ");
}
}
#endregion
#region 选择树
protected void tvLeft_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Action == TreeViewAction.ByMouse)
{
isSearch = false; // 设置当前查询模式为部分数据查询
string strWhere = " and " + mTabWordRow["fieldname"] + " like '" + e.Node.Name + "%'";
string sql = PubClass.ReplaceWhereCond(MyNotBmpSql) + strWhere;
//MessageBox.Show(sql);
InitData(sql);
}
}
#endregion
#region 生成行号
protected void GridViewpub_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
if (e.Info.IsRowIndicator)
{
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
}
#endregion
#region 表格拖动
/// <summary>
/// 拖动权限
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
private bool CanDragRowState(DataRow dr)
{
try
{
string tempCond = dragCond;
bool canDrag = string.IsNullOrEmpty(dragCond);
if (!string.IsNullOrEmpty(tempCond))
{
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canDrag = Convert.ToBoolean(Evaluator.Eval(tempCond));
}
return canDrag;
}
catch (Exception)
{
return false;
}
}
public void DragGridCallBack(object sender)
{
if (XtraMessageBox.Show("您确定要拖动选中记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
GridView targetGridView = (sender as GridControl).FocusedView as GridView;
string tableName = mTabRow["SQLDT1"] + "";
string unionField = mTabWordRow["fieldname"] + "";
string valueField = mTabWordRow["fieldsqlid"] + "";
int[] sourceSelectRows = gcMain.LayoutView.GetSelectedRows();
int[] targetSelectRows = targetGridView.GetSelectedRows();
try
{
// 拖动结果
int dragSuccess = 0, dragError = 0, result = 0;
string ids = string.Empty;
foreach (int item in sourceSelectRows)
{
DataRow dr = gcMain.LayoutView.GetDataRow(item);
if (CanDragRowState(dr))
{
ids += "'" + dr[mParmaryKey] + "',";
dragSuccess++;
}
else
{
dragError++;
}
}
if (!string.IsNullOrEmpty(ids) && targetSelectRows.Count() > 0)
{
DataRow drTarget = targetGridView.GetDataRow(targetSelectRows[0]);
string sqlValue = string.Format("UPDATE {0} SET {1}='{2}' WHERE {3} IN ({4})",
tableName, unionField, drTarget[valueField], mParmaryKey, ids.Trim(','));
result = SqlHelper.ExecuteNonQuery(sqlValue);
// 刷新左侧表格数据
//mcc.runQuery();
// 刷新主表格数据
if (mTabRow["searchEnable"].ToString() == "1")
{
if (mSeearchMode == 1)
{
sqlValue = mSearchTop.SetSearchSqlValue();
if (!string.IsNullOrEmpty(sqlValue))
{
InitData(sqlValue);
}
}
else
{
btnSearch_Click(null, null);
}
}
XtraMessageBox.Show("拖动成功 " + dragSuccess + " 条," + "失败 " + dragError + " 条", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (string.IsNullOrEmpty(ids))
{
MessageBox.Show("未选中需要拖动的纪录");
}
if (targetSelectRows.Count() < 1)
{
MessageBox.Show("没有选中目标进行拖动");
}
}
}
catch (Exception)
{
}
}
}
#endregion
#region 绑定数据
public void InitData(string sql)
{
try
{
int oldRowHandle = (gcMain.LayoutView as LayoutView).FocusedRowHandle;
beforeSearchSQL = sql;
//这个绑定数据源
da = SqlHelper.ExecuteAdapter(CommandType.Text, sql);
if (ds != null && ds.Tables.Count > 0)
ds.Clear();
da.Fill(ds);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataTable dtTable = ds.Tables[0];
gcMain.GridControl.DataSource = dtTable;
getServerImages();
//(gcMain.GridControl.MainView as LayoutView).FocusedRowHandle = oldRowHandle;
}
catch (Exception)
{
}
}
/// <summary>
/// 获取服务器图片
/// </summary>
private void getServerImages()
{
try
{
Bitlists.Clear();
DataTable dtTable = gcMain.GridControl.DataSource as DataTable;
_images = new List<LayoutViewColumn>();
_colObj = gcMain.LayoutView.Columns.Cast<LayoutViewColumn>().FirstOrDefault(x => x.ColumnEdit != null && x.ColumnEdit is RepositoryItemPictureEdit);
if (_colObj != null)
{
//timer1.Start();
if (!dtTable.Columns.Contains(_colObj.FieldName))
{
dtTable.Columns.Add(_colObj.FieldName, typeof(Image));
}
// 下载图片
foreach (DataRow rowObj in dtTable.Rows)
{
string fieldName = _colObj.FieldName.Replace("_image", "");
if (!string.IsNullOrWhiteSpace(rowObj[fieldName] + ""))
{
string fieldValue = rowObj[fieldName] + "";
if (!string.IsNullOrEmpty(fieldValue))
{
string sqlValue = string.Format("select dbo.fun_fm_getAbsolutePath('{0}') filePath", fieldValue);
DataTable dtFile = SqlHelper.ExecuteDataTable(sqlValue);
if (dtFile.Rows.Count > 0)
{
try
{
string start_url = Application.StartupPath + "\\tempfiles\\";
string download_url = dtFile.Rows[0]["filePath"] + "";
string local_url = start_url + download_url.Replace(Path.GetFileName(download_url), "");
string bmp_url = start_url + download_url;
if (!Directory.Exists(local_url))
{
Directory.CreateDirectory(local_url);
}
if (File.Exists(bmp_url))
{
// 加载本地缓存数据
using (FileStream fs = File.OpenRead(bmp_url))
{
//Image img = Image.FromStream(fs);
Bitmap bit = new Bitmap(fs);
rowObj[_colObj.FieldName] = bit;
Bitlists.Add(bit);
//bit.Dispose();
//rowObj[_colObj.FieldName] = new Bitmap(Resources.empty);
}
}
else
{
rowObj[_colObj.FieldName] = new Bitmap(Resources.downloading);
// 启用下载
TParamsData pd = new TParamsData(this.Handle);
pd.CallDownload(serverAttachPath + download_url);
Thread.Sleep(2000);
}
_colObj.Tag = bmp_url;
}
catch (Exception)
{
}
}
}
else
{
rowObj[_colObj.FieldName] = new Bitmap(Resources.empty);
}
}
else
{
// 加载默认图片
rowObj[_colObj.FieldName] = new Bitmap(Resources.empty);
}
}
}
}
catch (Exception)
{
}
}
/// <summary>
/// 检查图片是否下载完成
/// </summary>
private void checkLocalImages()
{
try
{
if (_colObj != null)
{
//string bmpUrl = _colObj.Tag + "";
string fieldName = _colObj.FieldName.Replace("_image", "");
string bmpUrl = Application.StartupPath + "\\tempfiles";
DataTable dtTable = gcMain.GridControl.DataSource as DataTable;
foreach (DataRow rowObj in dtTable.Rows)
{
string imageUrl = bmpUrl + "\\" + rowObj[fieldName];
if (File.Exists(imageUrl))
{
// 加载本地缓存数据
FileStream fs = File.OpenRead(imageUrl);
rowObj[_colObj.FieldName] = new Bitmap(fs);
Thread.Sleep(500);
}
}
}
}
catch (Exception)
{
}
}
#endregion
#region 加载表格列
/// <summary>
/// 加载表格列头
/// </summary>
/// <param name="tab"></param>
public void InitColumns()
{
SqlParameter[] p =
{
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@operatorname",SqlDbType.VarChar,20)
};
p[0].Value = DLLCoid;
p[1].Value = OperatorName;
dtColumns = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "[p_getBaseModuleField]", "temp", p).Tables[0];
nullableFields = dtColumns.Rows.OfType<DataRow>().Where(x => x["tagid"] + "" == "1").ToArray();
gcMain.ModuleKey = DLLCoid;
gcMain.FormKey = mTabRow["formkey"] + "";
gcMain.ModuleType = 1;
gcMain.SetColumns(gcMain.ResetColumns(dtColumns));
}
#endregion
#region 添加数据
/// <summary>
/// 添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnAdd_Click(object sender, EventArgs e)
{
string fieldsqlid = string.Empty;
string fieldsqlname = string.Empty;
string strTag = string.Empty;
string jsonData = string.Empty;
if (!string.IsNullOrEmpty(mTabRow["AddDllName"] + ""))
{
if (mLeftType == 1)
{
if (tvLeft.GetTreeView.SelectedNode == null)
{
XtraMessageBox.Show("请选择类别", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (tvLeft.GetTreeView.SelectedNode.Nodes.Count > 0)
{
XtraMessageBox.Show("请选择根级节点", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//MessageBox.Show(tvLeft.GetTreeView.SelectedNode.Name);
String bllNO = PubClass.GetBillNo(tvLeft.GetTreeView.SelectedNode.Name + "", DLLCoid);
if (string.IsNullOrEmpty(bllNO))
{
XtraMessageBox.Show("请修改编码前缀", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
return;
}
fieldsqlid = tvLeft.GetTreeView.SelectedNode.Name;
fieldsqlname = tvLeft.GetTreeView.SelectedNode.Text;
strTag = tvLeft.GetTreeView.SelectedNode.Tag + "";
}
else if (mLeftType == 2)
{
int[] rows = gridLeft.gridView.GetSelectedRows();
if (rows.Length == 0)
{
XtraMessageBox.Show("请选择类别", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DataRow row = gridLeft.gridView.GetDataRow(rows[0]);
fieldsqlid = row[mTabWordRow["fieldsqlid"] + ""] + "";
fieldsqlname = row[mTabWordRow["fieldsqlname"] + ""] + "";
DataTable dtGcHeader = gridLeft.gridControl.DataSource as DataTable;
if (dtGcHeader != null && dtGcHeader.Rows.Count > 0)
{
DataTable dtTemp = dtGcHeader.Clone();
dtTemp.ImportRow(row);
jsonData = dtTemp.ToJson();
}
}
string[] args = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
"",
"0",
"",
fieldsqlid,
fieldsqlname,
strTag,
"",
"",
getSearchAllData(),
jsonData
};
IForm form = PubUtil.LoadDllForm(mTabRow["AddDllName"] + "", args);
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK)
{
//string where = string.Empty;
//if (dtSystemwordbooktabTag3 != null) where = " and " + dtSystemwordbooktabTag3["fieldname"] + " like '" + fieldsqlid + "%'";
//if (string.IsNullOrEmpty(beforeSearchSQL))
//{
// InitData(PubClass.ReplaceWhereCond(MyNotBmpSql) + where);
//}
//else
//{
// InitData(PubClass.ReplaceWhereCond(beforeSearchSQL));
//}
if (!string.IsNullOrEmpty(beforeSearchSQL))
{
InitData(PubClass.ReplaceWhereCond(beforeSearchSQL));
}
else
{
Control[] ctr = pl_search.Controls.Find("btnCondSearch", true);
if ((ctr == null) || (ctr.Length < 1))
{
if (!string.IsNullOrEmpty(beforeSearchSQL))
InitData(beforeSearchSQL);
}
else
{
(ctr[0] as SimpleButton).PerformClick();
}
}
}
}
else
{
XtraMessageBox.Show("请配置弹出添加界面!");
}
}
/// <summary>
/// 添加行
/// </summary>
/// <param name="view"></param>
protected void AddRow(LayoutView view)
{
int prevDataRowIndex = view.GetFocusedDataSourceRowIndex();
view.AddNewRow();
//默认值
foreach (GridColumn item in view.Columns)
{
if (item.Tag != null)
{
MyTagModel cmt = item.Tag as MyTagModel;
if (cmt != null)
{
string defaultValue = PubClass.GetDefaultValue(cmt.DefaultValue.ToString(), OperatorId, OperatorName);
if (defaultValue != "")
{
view.SetRowCellValue(view.FocusedRowHandle, item, defaultValue);
}
}
}
// 检查是否配置有查询条件,根据查询条件设置数据(设置规则:查询条件名称=字段,则设置)
if (mSearchTable != null && mSearchTable.Rows.Count > 0)
{
DataRow row = mSearchTable.Rows.Cast<DataRow>().FirstOrDefault(x => x["fieldname"] + "" == item.FieldName);
if (row != null)
{
view.SetRowCellValue(view.FocusedRowHandle, item, mSearchTop.GetSearchControlText(item.FieldName));
}
}
}
//关键字段赋值
if (mLeftType == 2)
{
int[] rows = gridLeft.gridView.GetSelectedRows();
if (rows.Length > 0)
{
DataRow row = gridLeft.gridView.GetDataRow(rows[0]);
GridColumn tmpcol = gcMain.LayoutView.Columns[mTabWordRow["fieldname"] + ""];
view.SetRowCellValue(gcMain.LayoutView.FocusedRowHandle, tmpcol, row[mTabWordRow["fieldsqlid"] + ""]);
view.UpdateCurrentRow();
view.ShowEditor();
}
}
if (mLeftType == 1)
{
TreeNode tn = tvLeft.GetTreeView.SelectedNode;
GridColumn tmpcol = gcMain.LayoutView.Columns[mTabWordRow["fieldname"] + ""];
view.SetRowCellValue(gcMain.LayoutView.FocusedRowHandle, tmpcol, tn.Name);
view.UpdateCurrentRow();
view.ShowEditor();
}
}
#endregion
#region 删除数据
private void BtnDel_Click(object sender, EventArgs e)
{
string noDeleteIds = string.Empty;
int[] rowid = gcMain.LayoutView.GetSelectedRows();
if (rowid.Length == 0)
{
XtraMessageBox.Show("没有选择要删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (XtraMessageBox.Show("您确定要删除选中 " + rowid.Length + "条 记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string ids = string.Empty;
foreach (int rid in rowid)
{
DataRow dr = gcMain.LayoutView.GetDataRow(rid);
//判断删除条件是否符合
Boolean canDelete = string.IsNullOrEmpty(deleteCond);
string tempCond = deleteCond;
if (!canDelete)
{
tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName);
tempCond = PubClass.ReqSqlWhere(dr, tempCond);
canDelete = Convert.ToBoolean(Evaluator.Eval(tempCond));
}
if (canDelete)
{
//删除检查
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@keyvalue",SqlDbType.VarChar,40),
pMsg,
returnValue
};
param[0].Value = DLLCoid;
param[1].Value = dr[mParmaryKey];
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_VerifyCanDelete", "baseSave", param);
string msg = pMsg.Value.ToString();
int rVaule = Convert.ToInt32(returnValue.Value.ToString());
if (rVaule == 1)
{
ids += "'" + dr[mParmaryKey] + "',";
}
else
{
noDeleteIds += dr[mParmaryKey] + " >> " + msg + "\n";
}
}
else
{
noDeleteIds += dr[mParmaryKey] + " >>不符删除合条件\n";
}
}
if (ids != string.Empty)
{
string sql = "delete from " + mTabRow["SQLDT1"] + " where " + mParmaryKey + " in(" + ids.Trim(',') + ")";
SqlHelper.ExecuteNonQuery(sql);
//InitData(MyNotBmpSql);
// 移除表格选中数据
gcMain.LayoutView.DeleteSelectedRows();
string strHint = "记录删除成功";
if (!string.IsNullOrEmpty(noDeleteIds))
{
strHint = strHint + ",但是发现如下记录不符合删除条件\n" + noDeleteIds;
XtraMessageBox.Show(strHint, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
SqlHelper.AddLogTab(DLLCoid, FormText + "-->删除", FormText + "[" + ids + "]", FormText, OperatorName);
(gcMain.GridControl.DataSource as DataTable).AcceptChanges();
}
else
{
string strHint = "没有符合删除条件的记录";
if (!string.IsNullOrEmpty(noDeleteIds))
strHint = strHint + ",发现如下记录不符合删除条件\n" + noDeleteIds;
XtraMessageBox.Show(strHint, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
/// <summary>
/// 验证是否可以删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
int[] rows = gcMain.LayoutView.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
DataRow row = gcMain.LayoutView.GetDataRow(rows[0]);
this.HandleDelButtonState(row); // 验证删除按钮是否可以用
this.HandleEditRowState(row);
}
}
//表格编辑
private void gridView_ShowingEditor(object sender, CancelEventArgs e)
{
//DataRow dr = gcMain.gridView.GetDataRow(gcMain.gridView.FocusedRowHandle);
//if (dr!=null)
// e.Cancel = !(CanEditRowState(dr) && dtSystemDlltab["modifyEnable"].ToString() == "1");
e.Cancel = !btnSave.Enabled;
}
#endregion
#region 查询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSearch_Click(object sender, EventArgs e)
{
isSearch = true; // 设置当前查询模式为全部数据查询
SearchData();
}
/// <summary>
/// 查询所有数据
/// </summary>
private void SearchData()
{
string field = cbField.SelectedValue + "";
string strWhere = " ";
treeTags = string.Empty;
if (mLeftType == 1)
{
foreach (TreeNode tn in tvLeft.GetTreeView.Nodes)
GetCheckedState(tn);
}
if (!string.IsNullOrEmpty(field))
strWhere += " and (dbo.P_getpy(" + field + ") like '%" + txtKey.Text + "%' or " + field + " like '%" + txtKey.Text + "%')";
if (!string.IsNullOrEmpty(treeTags))
strWhere += " and " + mTabWordRow["fieldname"] + " in (" + treeTags.Trim(',') + ")";
InitData(PubClass.ReplaceWhereCond(MyNotBmpSql) + strWhere);
}
/// <summary>
/// 查询数据(按当前模式,树点击or表格点击or点击查询按钮)
/// </summary>
private void SearchCondData()
{
// 假如为树形结构,并且为点击树查询数据
if (string.IsNullOrEmpty(beforeSearchSQL))
{
if (mLeftType == 1 && !isSearch)
{
TreeNode treeNode = tvLeft.GetTreeView.SelectedNode;
if (treeNode != null)
InitData(PubClass.ReplaceWhereCond(MyNotBmpSql) + " and " + mTabWordRow["fieldname"] + " like '" + treeNode.Name + "%' ");
else
InitData(MyNotBmpSql);
}
// 假如左侧为表格数据,并且为点击表格查询数据
else if (mLeftType == 2 && !isSearch)
{
int[] rows = gridLeft.gridView.GetSelectedRows();
if (rows.Length == 0)
return;
DataRow row = gridLeft.gridView.GetDataRow(rows[0]);
InitData(PubClass.ReplaceWhereCond(MyNotBmpSql) + " and " + mTabWordRow["fieldname"] + " like '" + row[mTabWordRow["fieldsqlid"] + ""] + "%' ");
}
else
{
// 查询所有数据
InitData(MyNotBmpSql);
}
}
else
InitData(beforeSearchSQL);
}
#endregion
#region 保存
private void btnSave_Click(object sender, EventArgs e)
{
if (gridRequired())
{
try
{
DataTable dtTable = gcMain.GridControl.DataSource as DataTable;
da.Update(dtTable);
}
catch (InvalidOperationException ioe)
{
// 多表保存失败
gridSave();
return;
}
catch (DBConcurrencyException dce)
{
// 并发异常
XtraMessageBox.Show("数据已更新,请刷新后重试.");
return;
}
catch (Exception ex)
{
if (ex.Message.IndexOf("ix", StringComparison.OrdinalIgnoreCase) != -1)
{
XtraMessageBox.Show("系统检测到录入信息重复,请检查", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
XtraMessageBox.Show(ex.Message);
return;
}
}
(gcMain.GridControl.DataSource as DataTable).AcceptChanges();
SearchCondData();
XtraMessageBox.Show("修改成功");
}
}
/// <summary>
/// 表格必须录入验证
/// </summary>
/// <returns></returns>
private bool gridRequired()
{
DataTable dtBillItem = gcMain.GridControl.DataSource as DataTable;
DataColumnCollection dtBillRow = dtBillItem.Columns;
LayoutView gridView = gcMain.LayoutView;
GridColumnCollection gridColumns = gridView.Columns;
foreach (DataRow drGrid in dtBillItem.Rows)
{
foreach (DataRow dr in nullableFields)
{
string fieldName = dr["fieldName"] + "";
string fieldText = dr["username1"] + "";
if (string.IsNullOrEmpty(drGrid[fieldName] + ""))
{
XtraMessageBox.Show(string.Format("[{0}] 不能为空", fieldText));
gridView.Focus();
gridView.FocusedRowHandle = dtBillItem.Rows.IndexOf(drGrid);
gridView.FocusedColumn = gridColumns[fieldName];
//gridView.SelectCell(gridView.FocusedRowHandle, gridColumns[fieldName]);
gridView.ShowEditorByMouse();
return false;
}
}
}
return true;
}
/// <summary>
/// 多表表格修改
/// </summary>
private void gridSave()
{
try
{
string tabName = mTabRow["SQLDT1"] + "";
if (string.IsNullOrEmpty(tabName))
{
XtraMessageBox.Show("检测到未设置表名");
return;
}
List<string> mList = new List<string>();
StringBuilder mBuilder = new StringBuilder();
DataColumnCollection columns = SqlHelper.ExecuteDataTable(string.Format("select * from {0} where 1<>1", tabName)).Columns;
DataTable dtTable = gcMain.GridControl.DataSource as DataTable;
List<DataRow> modifiedRows = dtTable.Rows.Cast<DataRow>().Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added).ToList();
foreach (DataRow row in modifiedRows)
{
string updateSql = "update {0} set {1} where {2}='{3}';";
string insertSql = "insert into {0}({1}) values({2});";
string updateFields = string.Empty;
string insertFields = string.Empty;
string insertValues = string.Empty;
foreach (DataColumn col in columns)
{
DataRow hasContainRow = dtColumns.Rows.Cast<DataRow>().FirstOrDefault(x => x["fieldname"] + "" == col.ColumnName);
if (hasContainRow != null && col.ColumnName != mParmaryKey)
{
if (row.RowState == DataRowState.Modified)
{
updateFields += string.Format("{0}='{1}',", col.ColumnName, row[col.ColumnName]);
}
else if (row.RowState == DataRowState.Added)
{
insertFields += col.ColumnName + ",";
insertValues += "'" + row[col.ColumnName] + "',";
}
}
}
updateFields = updateFields.TrimEnd(',');
insertFields = insertFields.TrimEnd(',');
insertValues = insertValues.TrimEnd(',');
if (!string.IsNullOrEmpty(updateFields))
{
updateSql = string.Format(updateSql, tabName, updateFields, mParmaryKey, row[mParmaryKey]);
mList.Add(updateSql);
}
if (!string.IsNullOrEmpty(insertFields))
{
insertSql = string.Format(insertSql, tabName, insertFields, insertValues);
mList.Add(insertSql);
}
}
// 由于数据sql长度限制,每次只保存10条数据
int resultCount = 0;
for (int i = 0; i < mList.Count; i++)
{
if (i == mList.Count - 1 || (i != 0 && i % 10 == 0))
{
if (i == mList.Count - 1)
mBuilder.Append(mList[i]);
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@baseSql",SqlDbType.VarChar,8000),
new SqlParameter("@saveType",SqlDbType.Int),
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@tablename",SqlDbType.VarChar,50),
new SqlParameter("@keyfield",SqlDbType.VarChar,50),
new SqlParameter("@keyvalue",SqlDbType.VarChar,50),
new SqlParameter("@Operatorid",SqlDbType.Int),
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
pMsg,
returnValue
};
param[0].Value = mBuilder.ToString();
param[1].Value = 8;// --8新增保存,9修改保存,10 删除条码
param[2].Value = DLLCoid;
param[3].Value = tabName;
param[4].Value = mParmaryKey;
param[5].Value = "";
param[6].Value = OperatorId;
param[7].Value = OperatorName;
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "P_BaseSave", "baseSave", param);
string rMsg = pMsg.Value.ToString();
resultCount += Convert.ToInt32(returnValue.Value.ToString());
mBuilder.Clear();
}
mBuilder.Append(mList[i]);
}
if (resultCount > 0)
{
if (resultCount == mList.Count)
{
(gcMain.GridControl.DataSource as DataTable).AcceptChanges();
SearchCondData();
XtraMessageBox.Show("修改成功");
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
}
#endregion
#region 打印
private void BtnPrint_Click(object sender, EventArgs e)
{
PubClass.Preview(gcMain.GridControl);
}
#endregion
#region 树选中操作
/// <summary>
///
/// </summary>
/// <returns></returns>
public string GetTreeCheck()
{
treeTags = string.Empty;
foreach (TreeNode item in tvLeft.GetTreeView.Nodes)
{
GetCheckedState(item);
}
return treeTags;
}
/// <summary>
///
/// </summary>
protected string treeTags = string.Empty;
/// <summary>
/// 选中节点之后,选中节点的所有子节点
/// </summary>
/// <param name="currNode"></param>
/// <param name="state"></param>
private void GetCheckedState(TreeNode currNode)
{
if (currNode.Checked)
treeTags += "" + currNode.Name + ",";
TreeNodeCollection nodes = currNode.Nodes;
if (nodes.Count > 0)
{
foreach (TreeNode tn in nodes)
{
if (tn.Checked)
treeTags += "'" + tn.Name + "',";
GetCheckedState(tn);
}
}
}
#endregion
#region 修改
private void GridViewpub_DoubleClick(object sender, EventArgs e)
{
try
{
int[] rows = gcMain.LayoutView.GetSelectedRows();
if (rows != null && rows.Length > 0 && _colObj != null)
{
int rowHandler = gcMain.LayoutView.GetRowHandle(rows[0]);
Image image = gcMain.LayoutView.GetRowCellValue(rowHandler, _colObj.FieldName) as Image;
if (image != null && !string.IsNullOrEmpty(_colObj.Tag + ""))
{
FrmImageDialog imageView = new FrmImageDialog();
imageView.ImageSource = image;
imageView.ShowDialog();
}
}
}
catch (Exception)
{
}
}
public bool UpdateModel()
{
int[] rows = gcMain.LayoutView.GetSelectedRows();
if (rows.Length > 0)
{
DataRow dr = gcMain.LayoutView.GetDataRow(rows[0]);
//判断修改条件是否符合
Boolean canModify = string.IsNullOrEmpty(modifyCond);
if (needModified == true)
{
string tempCond = modifyCond;
if (!canModify)
{
tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName);
tempCond = PubClass.ReqSqlWhere(dr, tempCond);
canModify = tempCond.Trim() == "" ? true : Convert.ToBoolean(Evaluator.Eval(tempCond));
}
}
else
canModify = false;
string productId = dr[mParmaryKey].ToString();
string[] args = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
"",
Convert.ToInt32( !canModify).ToString(),
productId,
"",
"",
""
};
IForm form = PubUtil.LoadDllForm(mTabRow["AddDllName"] + "", args);
DialogResult dialogResult = form.SubForm.ShowDialog();
if (dialogResult == DialogResult.Cancel || dialogResult == DialogResult.No)
return false;
}
return true;
}
#endregion
#region 左边树点击事件
private void gridViewLeft_RowCellClick(object sender, RowCellClickEventArgs e)
{
isSearch = false; // 设置当前查询模式为部分数据查询
DataRow row = gridLeft.gridView.GetDataRow(e.RowHandle);
//MessageBox.Show("OK");
string tmpsql = PubClass.ReplaceWhereCond(MyNotBmpSql) + " and " + mTabWordRow["fieldname"] + " = '" + row[mTabWordRow["fieldsqlid"] + ""] + "' ";
if (row.Table.Columns.Contains("condition"))
{
tmpsql = tmpsql + row["condition"];
}
//MessageBox.Show(tmpsql);
InitData(tmpsql);
}
#endregion
#region 窗体关闭事件
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (PubUtil.ModuleForms.ContainsKey(ModuleId))
{
DllModule dm = PubUtil.ModuleForms[ModuleId];
if (dm != null)
{
dm.ModuleForm = null;
dm.ModuleInPtr = IntPtr.Zero;
PubUtil.ModuleForms.Remove(ModuleId);
}
}
}
#endregion
#region 帮助手册
private void btnHelp_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(DLLCoid))
{
MessageBox.Show("物料编码不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int id = 0;
object obj = SqlHelper.ExecuteScalar(CommandType.Text, "select dirid from P_fm_DirectoryTab where ParentId=3 and PID='" + DLLCoid + "'");
id = obj == null ? 0 : Convert.ToInt32(obj);
if (id == 0)
{
string sql = "insert into P_fm_DirectoryTab (sName,ParentId,creator,SpeciesNo,relationCode,PID) values('" + DLLCoid + "',3,1,'0201',0,'" + DLLCoid + "');select @@identity";
id = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sql));
}
string[] args =
{
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
ModuleId,
id.ToString()
};
IForm form = PubUtil.LoadDllForm2("Lskj.Attachment.dll", args);
form.SubForm.ShowDialog();
}
#endregion
#region Execl 操作
/// <summary>
/// 导入操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnImprt_Click(object sender, EventArgs e)
{
//string leftField = string.Empty;
//string leftValue = string.Empty;
//if (mLeftType != 3)
//{
// leftField = mTabWordRow["fieldname"] + "";
// leftValue = tvLeft.GetSelectValue();
//}
//string columnPrefix = PubClass.GetColumnPrefix(mTabRow["SQLDT1"].ToString());
//frmImport frm = new frmImport(gcMain, mTabRow["SQLDT1"].ToString(), "", "", OperatorId, OperatorName, columnPrefix, leftField, leftValue);
//DialogResult result = frm.ShowDialog();
//if (result == DialogResult.OK)
//{
// InitData(beforeSearchSQL);
//}
}
/// <summary>
/// 导出操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExport_Click(object sender, EventArgs e)
{
PubClass.SaveXls(gcMain.GridControl);
}
#endregion
#region 添加、删除、修改按钮处理
/// <summary>
/// 处理删除按钮
/// </summary>
private void HandleDelButtonState(DataRow dr)
{
try
{
string tempCond = deleteCond;
bool canDel = string.IsNullOrEmpty(deleteCond);
if (!string.IsNullOrEmpty(tempCond))
{
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canDel = Convert.ToBoolean(Evaluator.Eval(tempCond));
}
BtnDel.Enabled = canDel && mTabRow["deleteEnable"].ToString() == "1";
}
catch (Exception)
{
}
}
/// <summary>
/// 设置添加按钮状态
/// </summary>
private void HandleAddButtonState()
{
try
{
string tempCond = addCond;
bool canDel = string.IsNullOrEmpty(addCond);
if (!string.IsNullOrEmpty(tempCond))
{
tempCond = PubClass.SqlToCode(PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canDel = Convert.ToBoolean(Evaluator.Eval(tempCond));
}
BtnAdd.Enabled = canDel && (mTabRow["addEnable"].ToString() == "1") && (mModulePriv == 1);
btnImprt.Enabled = canDel && (mTabRow["importEnable"].ToString() == "1") && (mModulePriv == 1);
tempCond = printCond;
tempCond = PubClass.SqlToCode(PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canDel = Convert.ToBoolean(Evaluator.Eval(tempCond));
canDel = canDel && (mModulePriv == 1);
BtnPrint.Enabled = canDel;
tempCond = exportCond;
tempCond = PubClass.SqlToCode(PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canDel = Convert.ToBoolean(Evaluator.Eval(tempCond));
btnExport.Enabled = canDel && (mTabRow["exportEnable"].ToString() == "1") && (mModulePriv == 1);
}
catch (Exception)
{
}
}
/// <summary>
/// 验证是否可以编辑行
/// </summary>
/// <param name="dr"></param>
private void HandleEditRowState(DataRow dr)
{
btnSave.Enabled = CanEditRowState(dr) && mTabRow["modifyEnable"].ToString() == "1";
}
/// <summary>
/// 是否可以拖动
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
private bool CanEditRowState(DataRow dr)
{
try
{
string tempCond = modifyCond;
bool canEdit = string.IsNullOrEmpty(modifyCond);
if (!string.IsNullOrEmpty(tempCond))
{
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
canEdit = Convert.ToBoolean(Evaluator.Eval(tempCond));
}
return canEdit;
}
catch (Exception)
{
return false;
}
}
#endregion
#region 行颜色
private void gvList_RowCellStyle(object sender, RowStyleEventArgs e)
{
//if (e.RowHandle >= 0)
//{
// DataRow row = gcMain.gridView.GetDataRow(e.RowHandle);
// string cond = string.Empty;
// string color = string.Empty;
// string forecolor = string.Empty;
// foreach (DataRow dr in mColorsTable.Rows)
// {
// List<string> condition = PubClass.GetParamValue(dr["condition"].ToString());
// cond = dr["condition"].ToString();
// foreach (string item in condition)
// {
// string filedName = item.Replace("{", "").Replace("}", "");
// cond = cond.Replace(item, row[filedName].ToString());
// }
// cond = PubClass.SqlToCode(cond);
// color = dr["backcolor"] + "";
// forecolor = dr["forcecolor"].ToString() + "";
// string obj = Evaluator.Eval(cond) + "";
// if (obj.IndexOf("true", StringComparison.OrdinalIgnoreCase) != -1)
// {
// if (!string.IsNullOrEmpty(color))
// {
// System.Drawing.Color color1 = System.Drawing.ColorTranslator.FromHtml(color);
// e.Appearance.BackColor = color1;
// }
// if (!string.IsNullOrEmpty(forecolor))
// {
// System.Drawing.Color foreColor = System.Drawing.ColorTranslator.FromHtml(forecolor);
// e.Appearance.ForeColor = foreColor;
// }
// FontStyle fst = new FontStyle();
// if (dr["ifBold"].ToString() == "1")
// {
// fst = fst | FontStyle.Bold;
// }
// if (dr["ifItalic"].ToString() == "1")
// {
// fst = fst | FontStyle.Italic;
// }
// if (dr["ifStrickOut"].ToString() == "1")
// {
// fst = fst | FontStyle.Strikeout;
// }
// if (dr["ifUnderLine"].ToString() == "1")
// {
// fst = fst | FontStyle.Underline;
// }
// e.Appearance.Font = new Font(e.Appearance.Font, fst);
// }
// }
//}
}
#endregion
#region GridViewpub_KeyDown事件
private void GridViewpub_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control & e.KeyCode == Keys.C)
{
Clipboard.SetDataObject((sender as GridView).GetFocusedRowCellValue((sender as GridView).FocusedColumn));
e.Handled = true;
}
}
#endregion
/// <summary>
/// 获取顶部查询条件所有数据
/// </summary>
/// <returns>key=value</returns>
private string getSearchAllData()
{
string result = string.Empty;
foreach (DataRow item in mSearchTable.Rows)
{
string fieldName = item["fieldname"] + "";
result += fieldName + "=" + mSearchTop.GetSearchControlText(fieldName) + "|";
}
return result.TrimEnd('|');
}
private void txtKey_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
btnCondSearch_1.PerformClick();
}
private void gridView_RowCellClick(object sender, RowCellClickEventArgs e)
{
string dragState = gridLeft.gridView.Tag + "";
if ((dragState == "0") || (dragState == ""))
{
isSearch = false; // 设置当前查询模式为部分数据查询
DataRow row = gridLeft.gridView.GetDataRow(e.RowHandle);
//MessageBox.Show("OK");
if (row != null)
{
string sqlValue = mTabRow["SQL"] + "";
if (sqlValue.Contains("#"))
{
sqlValue = PubClass.ReqSql(row, sqlValue.Replace("#", ""));
}
else
{
sqlValue = MyNotBmpSql;
}
string tmpsql = PubClass.ReplaceWhereCond(sqlValue) + " and " + mTabWordRow["fieldname"] + " = '" + row[mTabWordRow["fieldsqlid"] + ""] + "' ";
if (row.Table.Columns.Contains("condition"))
{
tmpsql = tmpsql + row["condition"];
}
//MessageBox.Show(tmpsql);
InitData(tmpsql);
}
}
}
private void gridViewLeft_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
string dragState = gridLeft.gridView.Tag + "";
if ((dragState == "0") || (dragState == ""))
{
isSearch = false; // 设置当前查询模式为部分数据查询
DataRow row = gridLeft.gridView.GetDataRow(e.FocusedRowHandle);
//MessageBox.Show("OK");
if (row != null)
{
string sqlValue = mTabRow["SQL"] + "";
if (sqlValue.Contains("#"))
{
sqlValue = PubClass.ReqSql(row, sqlValue.Replace("#", ""));
}
else
{
sqlValue = MyNotBmpSql;
}
string tmpsql = PubClass.ReplaceWhereCond(sqlValue) + " and " + mTabWordRow["fieldname"] + " = '" + row[mTabWordRow["fieldsqlid"] + ""] + "' ";
if (row.Table.Columns.Contains("condition"))
{
tmpsql = tmpsql + row["condition"];
}
//MessageBox.Show(tmpsql);
InitData(tmpsql);
}
}
}
private void panel2_Resize(object sender, EventArgs e)
{
if (mInitFinish)
{
Lskj.PubUtils.INIHelper.Write("base_width_" + DLLCoid, panel1.Width + "");
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Bitmap bit in Bitlists)
{
bit.Dispose();
}
}
}
}