Exemplo n.º 1
0
        public void LoadAssembly(ToolStripButton Button, Action <object, EventArgs> Refresh, string FullName)
        {
            Assembly assembly = Assembly.LoadFrom(_msfileName);

            Type type = assembly.GetType(FullName);

            if (type == null)
            {
                return;
            }

            object obj = Activator.CreateInstance(type);

            if (obj == null)
            {
                return;
            }

            if (obj is ComponentToolBarPlugins)
            {
                ComponentToolbar toolbar = Button.GetCurrentParent() as ComponentToolbar;

                ComponentToolBarPlugins abPlugin = obj as ComponentToolBarPlugins;
                abPlugin.DataGrid        = toolbar.DataGrid;
                abPlugin.User            = GlobalInvariant.User;
                abPlugin.RefreshDataGrid = Refresh;

                abPlugin.OnActivated();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Refresh Button OnClick Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RefreshClick(object sender, EventArgs e)
        {
            ToolStripButton  button = sender as ToolStripButton;
            ComponentToolbar tool   = null;

            if (button == null)
            {
                tool = sender as ComponentToolbar;
            }
            else
            {
                tool = button.GetCurrentParent() as ComponentToolbar;
            }

            string    sql       = (tool.DataGrid.DataSource as DataTable).Namespace;
            string    tablename = (tool.DataGrid.DataSource as DataTable).TableName;
            DataTable dt        = DBHelper.GetDataTable(sql);

            dt.Namespace             = sql;
            dt.TableName             = tablename;
            tool.DataGrid.DataSource = dt;

            if (dt != null && dt.Rows.Count > 0)
            {
                tool.DataGrid.Rows[0].Cells[0].Selected = true;
                CommonCellClick(tool.DataGrid, new DataGridViewCellEventArgs(0, 0));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 对工具栏添加按钮
        /// </summary>
        /// <param name="toolstrip"></param>
        /// <param name="dr"></param>
        private static void AddButton(ComponentToolbar toolstrip, DataRow dr)
        {
            var button = new ToolStripButton()
            {
                Name         = dr["fbtnname"] + "",
                Text         = dr["fbtntext"] + "",
                DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
            };

            if ("custom".Equals(dr["fbtnname"] + "", StringComparison.OrdinalIgnoreCase) &&
                !string.IsNullOrEmpty(dr["fCustomName"] + ""))
            {
                button.Text = dr["fCustomName"] + "";
                button.Name = dr["fAssamblyName"] + "";
            }
            toolstrip.Items.Add(button);

            if (!string.IsNullOrEmpty(dr["fbtnimage"] + ""))
            {
                if (File.Exists(dr["fbtnimage"] + ""))
                {
                    Image image = Image.FromFile(dr["fbtnimage"] + "");
                    button.Image = image;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Edit Button OnClick Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditClick(object sender, EventArgs e)
        {
            ToolStripButton button = sender as ToolStripButton;

            ComponentToolbar  tool = null;
            ComponentDataGrid grid = null;

            if (button != null)
            {
                tool = button.GetCurrentParent() as ComponentToolbar;
                grid = tool.DataGrid;
            }
            else
            {
                grid = sender as ComponentDataGrid;
            }

            var rows = grid.SelectedRows;

            if (rows == null || rows.Count == 0)
            {
                MessageBox.Show("当前没有可以编辑的数据!", "title", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            frmModule form = new frmModule(grid, true);

            form.atRefresh = RefreshClick;
            form.InitializeData();
            form.ShowDialog();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add Button OnClick Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddClick(object sender, EventArgs e)
        {
            ToolStripButton  button = sender as ToolStripButton;
            ComponentToolbar tool   = button.GetCurrentParent() as ComponentToolbar;
            var grid = tool.DataGrid;

            frmModule form = new frmModule(grid);

            form.atRefresh = RefreshClick;
            form.InitializeData();
            form.ShowDialog();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Delete Button OnClick Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteClick(object sender, EventArgs e)
        {
            ToolStripButton  button = sender as ToolStripButton;
            ComponentToolbar tool   = button.GetCurrentParent() as ComponentToolbar;
            var grid = tool.DataGrid;

            var rows = grid.SelectedRows;

            if (rows == null || rows.Count == 0)
            {
                MessageBox.Show("当前没有可以删除的数据!", "title", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DialogResult dr = MessageBox.Show($"是否删除选中的{rows.Count}行", "title", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                int iIndex = rows[0].Index;

                // List<DataGridViewRow> lisRow = new List<DataGridViewRow>();

                List <string> lisStr = new List <string>(rows.Count);

                foreach (DataGridViewRow row in rows)
                {
                    var rowDelete = row.DataBoundItem as DataRowView;
                    rowDelete.Delete();
                    lisStr.Add($@"delete from {(grid.DataSource as DataTable).TableName} where fid ={(int)rowDelete["fid"]}");
                }

                DBHelper.RunSql(lisStr, CommandType.Text, null);

                //删除后自动点击
                if (grid.RowCount == iIndex && grid.RowCount != 0)
                {
                    int rowIndex = iIndex - 1;
                    grid.Rows[rowIndex].Selected = true;
                    CommonCellClick(grid, new DataGridViewCellEventArgs(0, rowIndex));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add events for toolbar
        /// </summary>
        /// <param name="toolbar">Toolbar</param>
        private void ToolbarAddEvent(ComponentToolbar toolbar)
        {
            foreach (ToolStripButton button in toolbar.Items)
            {
                string name = button.Name;
                switch (name)
                {
                case "add":
                    button.Click += AddClick;
                    break;

                case "refresh":
                    button.Click += RefreshClick;
                    break;

                case "delete":
                    button.Click += DeleteClick;
                    break;

                case "edit":
                    button.Click += EditClick;
                    break;

                default:

                    string   sassamblyFullName = button.Name;
                    string[] arrFullName       = sassamblyFullName.Split(',');
                    string   sfielName         = Path.Combine(Application.StartupPath, "Locallib", arrFullName[0] + ".dll");

                    if (!File.Exists(sfielName))
                    {
                        button.Visible = false;
                    }
                    else
                    {
                        button.Click += CustomClick;
                    }

                    break;
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建一个工具栏
        /// </summary>
        /// <param name="Name">工具栏Name,一般是容器数据源</param>
        /// <returns>ComponentToolbar</returns>
        internal static ComponentToolbar NewToolStrip(string Name)
        {
            var toolstrip = new ComponentToolbar();

            DataTable ButtonData = DBHelper.GetDataTable($@"
select *
from t_toolstrip a WITH(NOLOCK)
LEFT JOIN T_Button b on a.fToolName = b.fBtnName
where a.fInterFaceName = '{Name}'");

            if (ButtonData == null || ButtonData.Rows.Count == 0)
            {
                return(toolstrip);
            }

            foreach (DataRow dr in ButtonData.Rows)
            {
                AddButton(toolstrip, dr);
            }
            return(toolstrip);
        }