Esempio n. 1
0
        private void tbtEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow == null)
            {
                MessageBox.Show("请选择一项!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            CView obj = (CView)dataGridView.CurrentRow.Tag;

            if (obj.VType == enumViewType.Single)
            {
                SingleViewInfo frm = new SingleViewInfo();
                frm.m_View       = obj;
                frm.m_Catalog_id = obj.UI_ViewCatalog_id;
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            else if (obj.VType == enumViewType.MasterDetail)
            {
                MasterDetailViewInfo frm = new MasterDetailViewInfo();
                frm.m_View       = obj;
                frm.m_Catalog_id = obj.UI_ViewCatalog_id;
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            else
            {
                MultMasterDetailViewInfo frm = new MultMasterDetailViewInfo();
                frm.m_View       = obj;
                frm.m_Catalog_id = obj.UI_ViewCatalog_id;
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            CBaseObjectMgr BaseObjectMgr = Program.Ctx.ViewMgr;

            DataGridViewRow row = dataGridView.CurrentRow;

            foreach (DataGridViewColumn column in dataGridView.Columns)
            {
                CColumn col = (CColumn)column.Tag;
                if (col.ColType == ColumnType.object_type)
                {
                    if (obj.GetColValue(col) != null)
                    {
                        row.Cells[column.Name].Value = "long byte";
                    }
                }
                else if (col.ColType == ColumnType.ref_type)
                {
                    CTable table = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                    if (table == null)
                    {
                        continue;
                    }
                    CColumn RefCol     = (CColumn)table.ColumnMgr.Find(col.RefCol);
                    CColumn RefShowCol = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                    object  objVal     = obj.GetColValue(col);


                    Guid guidParentId = Guid.Empty;
                    if (BaseObjectMgr.m_Parent != null && BaseObjectMgr.m_Parent.Id == (Guid)objVal)
                    {
                        row.Cells[column.Name].Value = BaseObjectMgr.m_Parent.GetColValue(RefShowCol);
                    }
                    else
                    {
                        CBaseObjectMgr objMgr = Program.Ctx.FindBaseObjectMgrCache(table.Code, Guid.Empty);
                        if (objMgr != null)
                        {
                            CBaseObject objCache = objMgr.FindByValue(RefCol, objVal);
                            if (objCache != null)
                            {
                                row.Cells[column.Name].Value = objCache.GetColValue(RefShowCol);
                            }
                        }
                        else
                        {
                            objMgr        = new CBaseObjectMgr();
                            objMgr.TbCode = table.Code;
                            objMgr.Ctx    = Program.Ctx;

                            string             sWhere   = string.Format(" {0}=?", RefCol.Code);
                            List <DbParameter> cmdParas = new List <DbParameter>();
                            cmdParas.Add(new DbParameter(RefCol.Code, obj.GetColValue(col)));
                            List <CBaseObject> lstObj2 = objMgr.GetList(sWhere, cmdParas);
                            if (lstObj2.Count > 0)
                            {
                                CBaseObject obj2 = lstObj2[0];
                                row.Cells[column.Name].Value = obj2.GetColValue(RefShowCol);
                            }
                        }
                    }
                }
                else
                {
                    row.Cells[column.Name].Value = obj.GetColValue(col);
                }
            }
        }
Esempio n. 2
0
        private void tbtNew_Click(object sender, EventArgs e)
        {
            SelViewType frmVT = new SelViewType();

            if (frmVT.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            CView obj = null;

            if (frmVT.m_enumViewType == enumViewType.Single)
            {
                SingleViewInfo frm = new SingleViewInfo();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                obj = frm.m_View;
            }
            else if (frmVT.m_enumViewType == enumViewType.MasterDetail)
            {
                MasterDetailViewInfo frm = new MasterDetailViewInfo();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                obj = frm.m_View;
            }
            else
            {
                MultMasterDetailViewInfo frm = new MultMasterDetailViewInfo();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                obj = frm.m_View;
            }

            CBaseObjectMgr BaseObjectMgr = Program.Ctx.ViewMgr;

            dataGridView.Rows.Add(1);
            DataGridViewRow row = dataGridView.Rows[dataGridView.Rows.Count - 1];

            row.Tag = obj;
            foreach (DataGridViewColumn column in dataGridView.Columns)
            {
                CColumn col = (CColumn)column.Tag;
                if (col.ColType == ColumnType.object_type)
                {
                    if (obj.GetColValue(col) != null)
                    {
                        row.Cells[column.Name].Value = "long byte";
                    }
                }
                else if (col.ColType == ColumnType.ref_type)
                {
                    CTable table = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                    if (table == null)
                    {
                        continue;
                    }
                    CColumn RefCol     = (CColumn)table.ColumnMgr.Find(col.RefCol);
                    CColumn RefShowCol = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                    object  objVal     = obj.GetColValue(col);


                    Guid guidParentId = Guid.Empty;
                    if (BaseObjectMgr.m_Parent != null && BaseObjectMgr.m_Parent.Id == (Guid)objVal)
                    {
                        row.Cells[column.Name].Value = BaseObjectMgr.m_Parent.GetColValue(RefShowCol);
                    }
                    else
                    {
                        CBaseObjectMgr objMgr = Program.Ctx.FindBaseObjectMgrCache(table.Code, Guid.Empty);
                        if (objMgr != null)
                        {
                            CBaseObject objCache = objMgr.FindByValue(RefCol, objVal);
                            if (objCache != null)
                            {
                                row.Cells[column.Name].Value = objCache.GetColValue(RefShowCol);
                            }
                        }
                        else
                        {
                            objMgr        = new CBaseObjectMgr();
                            objMgr.TbCode = table.Code;
                            objMgr.Ctx    = Program.Ctx;

                            string             sWhere   = string.Format(" {0}=?", RefCol.Code);
                            List <DbParameter> cmdParas = new List <DbParameter>();
                            cmdParas.Add(new DbParameter(RefCol.Code, obj.GetColValue(col)));
                            List <CBaseObject> lstObj2 = objMgr.GetList(sWhere, cmdParas);
                            if (lstObj2.Count > 0)
                            {
                                CBaseObject obj2 = lstObj2[0];
                                row.Cells[column.Name].Value = obj2.GetColValue(RefShowCol);
                            }
                        }
                    }
                }
                else
                {
                    row.Cells[column.Name].Value = obj.GetColValue(col);
                }
            }
            dataGridView.ClearSelection();
            row.Selected          = true;
            row.Cells[1].Selected = true;
        }