public string GetColumnRefDefaultVal(CColumnDefaultValInViewDetail cdvivd, CColumn col)
    {
        CTable         RefTable      = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Find(col.RefTable);
        CBaseObjectMgr BaseObjectMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(RefTable.Code, Guid.Empty);

        if (BaseObjectMgr == null)
        {
            BaseObjectMgr        = new CBaseObjectMgr();
            BaseObjectMgr.TbCode = RefTable.Code;
            BaseObjectMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());
        }

        CColumn            RefCol     = (CColumn)RefTable.ColumnMgr.Find(col.RefCol);
        CColumn            RefShowCol = (CColumn)RefTable.ColumnMgr.Find(col.RefShowCol);
        List <CBaseObject> lstObjRef  = BaseObjectMgr.GetList();
        string             defval     = GetColumnDefaultVal(cdvivd, col).ToString();

        foreach (CBaseObject objRef in lstObjRef)
        {
            string val = objRef.GetColValue(RefCol).ToString();
            if (defval == val)
            {
                return(objRef.GetColValue(RefShowCol).ToString());
            }
        }
        return("");
    }
Exemple #2
0
        //获取引用字段的显示值
        public object GetRefShowColVal(CColumn col)
        {
            CTable  RefTable   = (CTable)Ctx.TableMgr.Find(col.RefTable);
            CColumn RefCol     = (CColumn)RefTable.ColumnMgr.Find(col.RefCol);
            CColumn RefShowCol = (CColumn)RefTable.ColumnMgr.Find(col.RefShowCol);
            object  localVal   = GetColValue(col);
            //缓存数据优先
            CBaseObjectMgr BaseObjectMgr = Ctx.FindBaseObjectMgrCache(RefTable.Code, Guid.Empty);

            if (BaseObjectMgr == null)
            {
                BaseObjectMgr        = new CBaseObjectMgr();
                BaseObjectMgr.TbCode = RefTable.Code;
                BaseObjectMgr.Ctx    = Ctx;
                string sWhere = string.Format("{0}=", RefCol.Code);
                string sVal   = localVal.ToString();
                if (col.ColType == ColumnType.string_type ||
                    col.ColType == ColumnType.guid_type ||
                    col.ColType == ColumnType.ref_type ||
                    col.ColType == ColumnType.enum_type ||
                    col.ColType == ColumnType.datetime_type ||
                    col.ColType == ColumnType.text_type ||
                    col.ColType == ColumnType.path_type)
                {
                    sVal = string.Format("'{0}'", sVal);
                }
                sWhere += sVal;
                BaseObjectMgr.Load(sWhere);
                List <CBaseObject> lstObjRef = BaseObjectMgr.GetList();
                if (lstObjRef.Count == 0)
                {
                    return(null);
                }
                return(lstObjRef[0].GetColValue(RefShowCol));
            }
            else
            {
                List <CBaseObject> lstObjRef = BaseObjectMgr.GetList();

                var varObj = from objRef in lstObjRef
                             where (localVal.ToString().Equals(objRef.GetColValue(RefCol).ToString(), StringComparison.OrdinalIgnoreCase))
                             select objRef;

                if (varObj.Count() == 0)
                {
                    return(null);
                }
                CBaseObject obj = varObj.ToList().First();
                return(obj.GetColValue(RefShowCol));
            }
        }
Exemple #3
0
        public void LoadData()
        {
            if (BaseObjectMgr == null)
            {
                return;
            }
            if (TableInWindowControl == null)
            {
                return;
            }

            comboBox.Items.Clear();
            foreach (CBaseObject obj in BaseObjectMgr.GetList())
            {
                string sText  = TableInWindowControl.Text.ToLower();
                int    iStart = 0;
                while (sText.IndexOf('[', iStart) > -1)
                {
                    int idx1 = sText.IndexOf('[', iStart);
                    int idx2 = sText.IndexOf(']', idx1);
                    iStart = idx1 + 1;
                    if (idx2 > idx1)
                    {
                        string  sCodeN = sText.Substring(idx1, idx2 - idx1 + 1);
                        string  sCode  = sCodeN.Substring(1, sCodeN.Length - 2);
                        CColumn column = BaseObjectMgr.Table.ColumnMgr.FindByCode(sCode);
                        if (column == null)
                        {
                            continue;
                        }
                        string sVal = obj.GetColValue(column).ToString();
                        sText = sText.Replace(sCodeN, sVal);
                    }
                }

                DataItem item = new DataItem();
                item.name = sText;
                item.Data = obj;
                comboBox.Items.Add(item);
            }
        }
Exemple #4
0
        public void LoadData()
        {
            if (BaseObjectMgr == null)
            {
                return;
            }
            if (dataGridView.Columns.Count == 0)
            {
                return;
            }
            dataGridView.Rows.Clear();
            List <CBaseObject> lstObj = BaseObjectMgr.GetList();

            if (lstObj.Count == 0)
            {
                return;
            }
            dataGridView.Rows.Add(lstObj.Count);
            int nRowIdx = 0;

            foreach (CBaseObject obj in lstObj)
            {
                DataGridViewRow row = dataGridView.Rows[nRowIdx];
                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);
                    }
                }
                nRowIdx++;
            }
        }
    void GetData()
    {
        int page     = Convert.ToInt32(Request.Params["page"]);
        int pageSize = Convert.ToInt32(Request.Params["pagesize"]);

        CBaseObjectMgr BaseObjectMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(m_Table.Code, m_guidParentId);

        if (BaseObjectMgr == null)
        {
            BaseObjectMgr        = new CBaseObjectMgr();
            BaseObjectMgr.TbCode = m_Table.Code;
            BaseObjectMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());
        }

        string             sData  = "";
        List <CBaseObject> lstObj = BaseObjectMgr.GetList();

        int totalPage = lstObj.Count % pageSize == 0 ? lstObj.Count / pageSize : lstObj.Count / pageSize + 1; // 计算总页数

        int index = (page - 1) * pageSize;                                                                    // 开始记录数

        for (int i = index; i < pageSize + index && i < lstObj.Count; i++)
        {
            CBaseObject obj = (CBaseObject)lstObj[i];

            string sRow = "";
            foreach (CBaseObject objC in m_Table.ColumnMgr.GetList())
            {
                CColumn col = (CColumn)objC;
                if (col.ColType == ColumnType.object_type)
                {
                    string sVal = "";
                    if (obj.GetColValue(col) != null)
                    {
                        sVal = "long byte";
                    }
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
                else if (col.ColType == ColumnType.ref_type)
                {
                    CTable RefTable = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Find(col.RefTable);
                    if (RefTable == null)
                    {
                        continue;
                    }
                    CColumn RefCol     = (CColumn)RefTable.ColumnMgr.Find(col.RefCol);
                    CColumn RefShowCol = (CColumn)RefTable.ColumnMgr.Find(col.RefShowCol);
                    object  objVal     = obj.GetColValue(col);


                    string sVal         = "";
                    Guid   guidParentId = Guid.Empty;
                    if (BaseObjectMgr.m_Parent != null && BaseObjectMgr.m_Parent.Id == (Guid)objVal)
                    {
                        object objVal2 = BaseObjectMgr.m_Parent.GetColValue(RefShowCol);
                        if (objVal2 != null)
                        {
                            sVal = objVal2.ToString();
                        }
                    }
                    else
                    {
                        CBaseObjectMgr objRefMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(RefTable.Code, guidParentId);
                        if (objRefMgr != null)
                        {
                            CBaseObject objCache = objRefMgr.FindByValue(RefCol, objVal);
                            if (objCache != null)
                            {
                                object objVal2 = objCache.GetColValue(RefShowCol);
                                if (objVal2 != null)
                                {
                                    sVal = objVal2.ToString();
                                }
                            }
                        }
                        else
                        {
                            objRefMgr        = new CBaseObjectMgr();
                            objRefMgr.TbCode = RefTable.Code;
                            objRefMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());

                            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 = objRefMgr.GetList(sWhere, cmdParas);
                            if (lstObj2.Count > 0)
                            {
                                CBaseObject obj2    = lstObj2[0];
                                object      objVal2 = obj2.GetColValue(RefShowCol);
                                if (objVal2 != null)
                                {
                                    sVal = objVal2.ToString();
                                }
                            }
                        }
                    }
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
                else
                {
                    string sVal   = "";
                    object objVal = obj.GetColValue(col);
                    if (objVal != null)
                    {
                        sVal = objVal.ToString();
                    }
                    //转义特殊字符
                    Util.ConvertJsonSymbol(ref sVal);
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
            }
            sRow   = sRow.TrimEnd(",".ToCharArray());
            sRow   = "{" + sRow + "},";
            sData += sRow;
        }
        sData = sData.TrimEnd(",".ToCharArray());
        sData = "[" + sData + "]";
        string sJson = string.Format("{{\"Rows\":{0},\"Total\":\"{1}\"}}"
                                     , sData, lstObj.Count);

        Response.Write(sJson);
    }
    void GetData()
    {
        string pid = Request["pid"];

        if (string.IsNullOrEmpty(pid))
        {
            return;
        }

        CBaseObjectMgr BaseObjectMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(m_Table.Code, new Guid(pid));

        if (BaseObjectMgr == null)
        {
            BaseObjectMgr        = new CBaseObjectMgr();
            BaseObjectMgr.TbCode = m_Table.Code;
            BaseObjectMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());

            CColumn colF = (CColumn)m_Table.ColumnMgr.Find(m_ViewDetail.ForeignKey);
            if (colF == null)
            {
                return;
            }
            string sWhere0 = string.Format(" {0}='{1}'", colF.Code, pid);
            BaseObjectMgr.GetList(sWhere0);
        }
        List <CBaseObject> lstObj = BaseObjectMgr.GetList();

        string sData = "";

        foreach (CBaseObject obj in lstObj)
        {
            string sRow = "";
            foreach (CBaseObject objC in m_Table.ColumnMgr.GetList())
            {
                CColumn col = (CColumn)objC;
                //判断禁止权限字段
                if (m_sortRestrictColumnAccessType.ContainsKey(col.Id))
                {
                    AccessType accessType = m_sortRestrictColumnAccessType[col.Id];
                    if (accessType == AccessType.forbide)
                    {
                        string sVal = "";
                        sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                        continue;
                    }
                }
                //

                if (col.ColType == ColumnType.object_type)
                {
                    string sVal = "";
                    if (obj.GetColValue(col) != null)
                    {
                        sVal = "long byte";
                    }
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
                else if (col.ColType == ColumnType.ref_type)
                {
                    CTable RefTable = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Find(col.RefTable);
                    if (RefTable == null)
                    {
                        continue;
                    }
                    CColumn RefCol     = (CColumn)RefTable.ColumnMgr.Find(col.RefCol);
                    CColumn RefShowCol = (CColumn)RefTable.ColumnMgr.Find(col.RefShowCol);
                    object  objVal     = obj.GetColValue(col);


                    string sVal         = "";
                    Guid   guidParentId = Guid.Empty;
                    if (BaseObjectMgr.m_Parent != null && BaseObjectMgr.m_Parent.Id == (Guid)objVal)
                    {
                        object objVal2 = BaseObjectMgr.m_Parent.GetColValue(RefShowCol);
                        if (objVal2 != null)
                        {
                            sVal = objVal2.ToString();
                        }
                    }
                    else
                    {
                        CBaseObjectMgr objRefMgr = Global.GetCtx(Session["TopCompany"].ToString()).FindBaseObjectMgrCache(RefTable.Code, guidParentId);
                        if (objRefMgr != null)
                        {
                            CBaseObject objCache = objRefMgr.FindByValue(RefCol, objVal);
                            if (objCache != null)
                            {
                                object objVal2 = objCache.GetColValue(RefShowCol);
                                if (objVal2 != null)
                                {
                                    sVal = objVal2.ToString();
                                }
                            }
                        }
                        else
                        {
                            objRefMgr        = new CBaseObjectMgr();
                            objRefMgr.TbCode = RefTable.Code;
                            objRefMgr.Ctx    = Global.GetCtx(Session["TopCompany"].ToString());

                            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 = objRefMgr.GetList(sWhere, cmdParas);
                            if (lstObj2.Count > 0)
                            {
                                CBaseObject obj2    = lstObj2[0];
                                object      objVal2 = obj2.GetColValue(RefShowCol);
                                if (objVal2 != null)
                                {
                                    sVal = objVal2.ToString();
                                }
                            }
                        }
                    }
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
                else
                {
                    string sVal   = "";
                    object objVal = obj.GetColValue(col);
                    if (objVal != null)
                    {
                        sVal = objVal.ToString();
                    }
                    //转义特殊字符
                    Util.ConvertJsonSymbol(ref sVal);
                    sRow += string.Format("\"{0}\":\"{1}\",", col.Code, sVal);
                }
            }
            sRow   = sRow.TrimEnd(",".ToCharArray());
            sRow   = "{" + sRow + "},";
            sData += sRow;
        }
        sData = sData.TrimEnd(",".ToCharArray());
        sData = "[" + sData + "]";
        string sJson = string.Format("{{\"Rows\":{0},\"Total\":\"{1}\"}}"
                                     , sData, lstObj.Count);

        Response.Write(sJson);
    }