private static void OnBatchSetCellValueCommand(object sender, ExecutedEventArgs e)
        {
            Xceed.Grid.Cell   contextMenuCell = sender as Xceed.Grid.DataCell;
            ArchiveGridHelper gridHelper      = e.Parameter as ArchiveGridHelper;

            string fieldName = contextMenuCell.ParentColumn.FieldName;

            // 开始操作

            gridHelper.m_grid.DisplayManager.BeginBatchOperation();
            List <Xceed.Grid.DataRow> modifiedRows = new List <Xceed.Grid.DataRow>();

            gridHelper.m_grid.GridControl.SuspendLayout();

            //bool userBreak = false;
            foreach (Xceed.Grid.DataRow row in gridHelper.m_grid.GridControl.SelectedRows)
            {
                if (!row.Visible)
                {
                    continue;
                }
                if (row == contextMenuCell.ParentRow)
                {
                    continue;
                }

                if (row.Cells[fieldName].ReadOnly)
                {
                    continue;
                }

                if (row.Cells[fieldName].Value == null && contextMenuCell.Value == null)
                {
                    continue;
                }

                if (row.Cells[fieldName].Value != null && contextMenuCell.Value != null &&
                    row.Cells[fieldName].Value.ToString() == contextMenuCell.Value.ToString())
                {
                    continue;
                }

                bool doit = true;
                if (row.Cells[fieldName].Value != null)
                {
                    if (gridHelper.m_allowSetListWarning)
                    {
                        DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("已有值 \"" + row.Cells[fieldName].GetDisplayText() + "\",是否改变?", "确认", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Information);
                        if (dialogResult == DialogResult.Cancel)
                        {
                            //userBreak = true;
                            break;
                        }
                        else
                        {
                            doit = (dialogResult == DialogResult.Yes);
                        }
                    }
                }

                if (doit)
                {
                    try
                    {
                        row.BeginEdit();
                        object oldValue = row.Cells[fieldName].Value;

                        // 设置目标列值
                        row.Cells[fieldName].Value = contextMenuCell.Value;

                        if (row.Cells[fieldName].Value == oldValue)
                        {
                            continue;
                        }

                        // 有些因为Combo的原因,设置值有限制
                        row.Cells[fieldName].EnterEdit();
                        row.Cells[fieldName].LeaveEdit(true);
                        if (row.Cells[fieldName].Value == null && contextMenuCell.Value != null)
                        {
                            row.Cells[fieldName].Value = oldValue;
                            row.CancelEdit();
                            continue;
                        }
                        try
                        {
                            row.EndEdit();
                        }
                        catch (Exception)
                        {
                            // 当保存不进去的时候,cancel
                            row.CancelEdit();
                        }

                        modifiedRows.Add(row);

                        gridHelper.m_grid.ControlManager.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, row.Index));

                        //CancelEventArgs ee = new CancelEventArgs();
                        //row_EndingEdit(row, ee);
                    }
                    // 不知道
                    //// when in 批量费用登记(有分组的界面)
                    //catch (Xceed.Grid.GridValidationException)
                    //{
                    //}
                    catch (Exception ex)
                    {
                        row.CancelEdit();

                        ExceptionProcess.ProcessWithNotify(ex);

                        if (!MessageForm.ShowYesNo("出现错误,是否继续?"))
                        {
                            break;
                        }
                    }
                }
            }

            // 即使用户取消,也要保存先前的内容
            //if (userBreak)
            //{
            //}
            //else
            //{
            IBatchDao batchDao = gridHelper.m_grid.ControlManager.Dao as IBatchDao;

            if (batchDao == null)
            {
                ServiceProvider.GetService <IMessageBox>().ShowWarning("不支持批量保存,将逐条保存!");
            }
            try
            {
                if (batchDao != null)
                {
                    batchDao.SuspendOperation();
                }

                foreach (Xceed.Grid.DataRow row in modifiedRows)
                {
                    object entity = row.Tag;
                    foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(gridHelper.m_grid.GridName))
                    {
                        if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                        {
                            if (row.Cells[info.GridColumnName].ReadOnly)
                            {
                                continue;
                            }

                            if (info.GridColumnType == GridColumnType.Normal)
                            {
                                EntityScript.SetPropertyValue(entity, info.Navigator, info.PropertyName,
                                                              row.Cells[info.GridColumnName].Value);
                            }
                        }
                    }
                    gridHelper.m_grid.ControlManager.Dao.Update(entity);
                }
                if (batchDao != null)
                {
                    batchDao.ResumeOperation();
                }
            }
            catch (Exception ex)
            {
                if (batchDao != null)
                {
                    batchDao.CancelSuspendOperation();
                }
                ExceptionProcess.ProcessWithNotify(ex);

                gridHelper.m_grid.ReloadData();
            }
            finally
            {
            }

            gridHelper.m_grid.GridControl.ResumeLayout();

            gridHelper.m_grid.DisplayManager.EndBatchOperation();

            MyGrid.SetCurrentRow(gridHelper.m_grid.GridControl, gridHelper.m_grid.DataRows[gridHelper.m_grid.DisplayManager.Position]);
            MyGrid.SyncSelectedRowToCurrentRow(gridHelper.m_grid.GridControl);
        }
Пример #2
0
        private static bool InternalExecuteWindowMenu2(IControlManager cm, WindowMenuInfo info, Form parentForm)
        {
            object entity = cm.DisplayManager.CurrentItem;
            int    pos    = cm.DisplayManager.Position;

            //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm;
            switch (info.Type)
            {
            case WindowMenuType.Add:
            {
                ArchiveOperationForm.DoAddS(cm);
            }
            break;

            case WindowMenuType.Edit:
            {
                ArchiveOperationForm.DoEditS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Delete:
            {
                ArchiveOperationForm.DoDeleteS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Confirm:
            {
                parentForm.ValidateChildren();
                ArchiveDetailForm.DoSaveS(cm);
            }
            break;

            case WindowMenuType.Cancel:
            {
                ArchiveDetailForm.DoCancelS(cm);
            }
            break;

            case WindowMenuType.Submit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = true;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = true;
                            rep.BeginTransaction();
                            dao.Submit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Unsubmit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要撤销提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认撤销提交?", "确认", true))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = false;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = false;
                            rep.BeginTransaction();
                            dao.Unsubmit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = true;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.SubmitMulti:
            {
                if (cm.DisplayManager.Count == 0)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交(当前全部)?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    IBatchDao batchDao = cm.Dao as IBatchDao;
                    if (batchDao != null)
                    {
                        batchDao.SuspendOperation();
                    }

                    for (int i = 0; i < cm.DisplayManager.Count; ++i)
                    {
                        cm.DisplayManager.Position = i;
                        cm.EditCurrent();
                        (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                        cm.EndEdit();
                    }

                    if (batchDao != null)
                    {
                        batchDao.ResumeOperation();
                    }
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            rep.BeginTransaction();
                            for (int i = 0; i < cm.DisplayManager.Count; ++i)
                            {
                                (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                                dao.Submit(rep, cm.DisplayManager.Items[i]);
                            }
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Cancellate:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要作废的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认作废?", "确认", true))
                {
                    return(true);
                }

                ICancellateDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ICancellateDao;
                if (dao == null)
                {
                    throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ICancellateDao!");
                }
                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        dao.Cancellate(rep, entity);
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.DaoProcess:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要操作的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否要执行" + info.Text + "?"))
                {
                    return(true);
                }

                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length != 2)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam should be IDao;MethodName!");
                }
                IRepositoryDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(ss[0].Trim()) as IRepositoryDao;
                if (dao == null)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam's first part should be IDao!");
                }

                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        Feng.Utils.ReflectionHelper.RunInstanceMethod(ss[0].Trim(), ss[1].Trim(), dao, new object[] { rep, entity });
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.Select:
            {
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length == 0)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveCheckForm form = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveCheckForm;
                if (ss.Length > 1)
                {
                    string exp = ss[1];
                    exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName)
                        {
                            Tuple <string, object> t = EventProcessUtils.GetDataControlValue(paramName, cm.DisplayManager);
                            if (t.Item2 == null)
                            {
                                throw new InvalidUserOperationException(string.Format("请先填写{0}!", paramName));
                            }
                            cm.DisplayManager.DataControls[t.Item1].ReadOnly = true;
                            // save controlValue to entity because readonly will not save
                            EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, t.Item1, t.Item2);

                            return(t.Item2);
                        }));
                    if (string.IsNullOrEmpty(form.DisplayManager.SearchManager.AdditionalSearchExpression))
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = exp;
                    }
                    else
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = "(" + form.DisplayManager.SearchManager.AdditionalSearchExpression + ") and " + exp;
                    }
                }

                int detailGridIdx = 0;
                if (ss.Length > 2)
                {
                    detailGridIdx = Feng.Utils.ConvertHelper.ToInt(ss[2]).Value;
                }
                if (form.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                {
                    IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)(parentForm as IArchiveMasterForm).ArchiveDetailForm).DetailGrids[detailGridIdx] as IArchiveGrid).ControlManager;

                    var nowList = detailCm.DisplayManager.Items;
                    foreach (object i in form.SelectedEntites)
                    {
                        if (nowList.Contains(i))
                        {
                            continue;
                        }

                        detailCm.AddNew();
                        detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = i;
                        detailCm.EndEdit();
                    }
                }
                form.Dispose();
            }
            break;

            case WindowMenuType.Input:
                throw new NotSupportedException("Not supported now!");

            case WindowMenuType.ManyToOneWindow:
            {
                if (cm.DisplayManager.CurrentItem == null)
                {
                    MessageForm.ShowInfo("无当前项,不能操作!");
                    return(true);
                }
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length < 2)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveDetailForm selectForm   = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveDetailForm;
                string            propertyName = ss[1];
                object            masterEntity = EntityScript.GetPropertyValue(cm.DisplayManager.CurrentItem, propertyName);
                if (masterEntity == null)
                {
                    ArchiveOperationForm.DoAddS(selectForm.ControlManager);
                    selectForm.UpdateContent();
                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        cm.EditCurrent();
                        EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, propertyName, selectForm.DisplayManager.CurrentItem);
                        cm.EndEdit();

                        cm.OnCurrentItemChanged();
                    }
                }
                else
                {
                    selectForm.ControlManager.AddNew();
                    selectForm.DisplayManager.Items[selectForm.DisplayManager.Position] = masterEntity;
                    selectForm.ControlManager.EndEdit(false);
                    ArchiveOperationForm.DoEditS(selectForm.ControlManager, selectForm.GridName);
                    selectForm.UpdateContent();

                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        ((parentForm as IArchiveMasterForm).MasterGrid as IBoundGrid).ReloadData();
                    }
                }
                selectForm.Dispose();
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
Пример #3
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (m_haveSaved)
            {
                if (!ServiceProvider.GetService <IMessageBox>().ShowYesNoDefaultNo("已保存过一次,是否再次保存(会导致2份记录)?", "确认"))
                {
                    return;
                }
            }
            int cnt = 0;

            IBatchDao batchDao = m_cm.Dao as IBatchDao;

            if (batchDao == null)
            {
                ServiceProvider.GetService <IMessageBox>().ShowWarning("不支持批量保存,将逐条保存!");
            }

            try
            {
                m_cm.CancelEdit();
                MyGrid.CancelEditCurrentDataRow(m_excelGrid);

                if (batchDao != null)
                {
                    batchDao.SuspendOperation();
                }

                foreach (Xceed.Grid.DataRow row in m_excelGrid.DataRows)
                {
                    bool hasValue = false;
                    foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(m_excelGrid.GridName))
                    {
                        if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                        {
                            if (row.Cells[info.GridColumnName].ReadOnly)
                            {
                                continue;
                            }
                            if (row.Cells[info.GridColumnName].Value != null)
                            {
                                hasValue = true;
                            }
                        }
                    }
                    if (!hasValue)
                    {
                        continue;
                    }

                    object entity = m_cm.AddNew();
                    if (entity == null)
                    {
                        continue;
                    }

                    foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(m_excelGrid.GridName))
                    {
                        if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                        {
                            if (row.Cells[info.GridColumnName].ReadOnly)
                            {
                                continue;
                            }

                            EntityScript.SetPropertyValue(entity, info.Navigator, info.PropertyName, row.Cells[info.GridColumnName].Value);
                        }
                    }

                    m_cm.EndEdit(false);

                    m_cm.Dao.Save(entity);
                    cnt++;
                }
                if (batchDao != null)
                {
                    batchDao.ResumeOperation();
                }

                m_haveSaved = true;
                MessageForm.ShowInfo(string.Format("已保存{0}条记录!", cnt));
            }
            catch (Exception ex)
            {
                if (batchDao != null)
                {
                    batchDao.CancelSuspendOperation();
                }
                ExceptionProcess.ProcessWithNotify(ex);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            //首先获取wcf监控服务器的信息
            IWcfServerDao     serverdao  = CastleContext.Instance.GetService <IWcfServerDao>();
            IList <WcfServer> serverlist = serverdao.FindAll();

            //首先建立批次信息
            Batch batch = new Batch();

            batch.CreateTime = DateTime.Now;
            IBatchDao batchdao = CastleContext.Instance.GetService <IBatchDao>();
            int       batchid  = batchdao.Insert(batch);

            IWcfServerPerformanceDao perfdao    = CastleContext.Instance.GetService <IWcfServerPerformanceDao>();
            IClientConnInfoDao       clientdao  = CastleContext.Instance.GetService <IClientConnInfoDao>();
            IOperationInfoDao        operatedao = CastleContext.Instance.GetService <IOperationInfoDao>();

            foreach (WcfServer server in serverlist)
            {
                string ip = server.IP + ":" + server.Point;
                PCData pcdata;
                double memCount;
                Dictionary <string, LinkModel> modellist = getLinkModel(ip, out pcdata, out memCount);
                int all_connnums = 0;

                foreach (string key in modellist.Keys)
                {
                    LinkModel model = modellist[key];
                    Dictionary <string, UrlInfo> infolist = model.UrlInfoList;

                    foreach (string url in infolist.Keys)
                    {
                        UrlInfo info = infolist[url];
                        all_connnums += info.ConnNums;

                        foreach (string opereateName in info.OperateNums.Keys)
                        {
                            //加入操作信息表
                            OperationInfo oinfo = new OperationInfo();
                            oinfo.Adress        = url;
                            oinfo.BatchID       = batchid;
                            oinfo.IP            = model.ClientIP.Split('_')[0];
                            oinfo.OperationName = opereateName;
                            oinfo.OperationNums = info.OperateNums[opereateName];
                            oinfo.ServerID      = server.ID;
                            oinfo.AppName       = model.ClientIP.Split('_')[1];

                            operatedao.Insert(oinfo);
                        }

                        //加入客户端连接信息表
                        ClientConnInfo clientinfo = new ClientConnInfo();
                        clientinfo.Adress   = url;
                        clientinfo.BatchID  = batchid;
                        clientinfo.IP       = model.ClientIP.Split('_')[0];
                        clientinfo.LinkNums = info.ConnNums;
                        clientinfo.ServerID = server.ID;
                        clientinfo.AppName  = model.ClientIP.Split('_')[1];

                        clientdao.Insert(clientinfo);
                    }
                }

                //存入服务器性能表
                WcfServerPerformance sperf = new WcfServerPerformance();
                sperf.BatchID         = batchid;
                sperf.Cpu             = (decimal)pcdata.Cpu;
                sperf.AllMem          = (decimal)memCount;
                sperf.Mem             = (decimal)pcdata.Mem;
                sperf.ProcessId       = pcdata.ProcessId;
                sperf.ServerID        = server.ID;
                sperf.ThreadCount     = pcdata.ThreadCount;
                sperf.CurrentConnNums = all_connnums;

                perfdao.Insert(sperf);
            }
        }