Beispiel #1
0
        /// <summary>
        /// 生成要返回给page的Json数据.
        /// </summary>
        /// <param name="fk_md"></param>
        /// <param name="en"></param>
        public void LoadFrmData(string fk_md, Entity en)
        {
            var dictParams = new ReplaceFieldList(); //主表参数值集合
            var fields     = new List <string>();    // 主表参数名集合

            dictParams.Add("No", WebUser.No, "string");
            dictParams.Add("Name", WebUser.Name, "string");
            dictParams.Add("FK_Dept", WebUser.FK_Dept, "string");
            dictParams.Add("FK_DeptName", WebUser.FK_DeptName, "string");

            var    mes  = new MapExts(fk_md);
            MapExt item = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull) as MapExt;
            //把数据装载到表里,包括从表数据,主表数据未存储.
            MapDtls  dtls   = new MapDtls(fk_md);
            MapAttrs mattrs = new MapAttrs(fk_md);

            en = BP.WF.Glo.DealPageLoadFull(en, item, mattrs, dtls); // 处理表单装载数据.

            //MapData md=new MapData(this.FK_MapData);
            foreach (MapAttr mapattr in mattrs)
            {
                fields.Add(mapattr.KeyOfEn);
                dictParams.Add(mapattr.KeyOfEn, en.GetValStringByKey(mapattr.KeyOfEn), mapattr.IsSigan ? "sign" : "string");
            }

            ReplaceParams += firsts[fk_md] ? GenerateParamsJsonString(dictParams) : "[]";

            //生成json格式。
            ReplaceFields += GenerateFieldsJsonString(fields);

            if (item == null || string.IsNullOrEmpty(item.Tag1) ||
                item.Tag1.Length < 15)
            {
                ReplaceDtls   += "[]";
                ReplaceDtlNos += "[]";
                return;
            }

            var       replaceDtlNos = new List <string>();
            DataSet   ds            = new DataSet();
            DataTable table         = null;
            var       sql           = string.Empty;
            var       pk            = GetPK(fk_md);

            // 填充从表.
            foreach (MapDtl dtl in dtls)
            {
                replaceDtlNos.Add(dtl.No);

                if (!firsts[fk_md])
                {
                    continue;
                }

                sql             = "SELECT * FROM " + dtl.PTable + " WHERE RefPK='" + pk + "'";
                table           = BP.DA.DBAccess.RunSQLReturnTable(sql);
                table.TableName = dtl.No;
                ds.Tables.Add(table);
            }

            // 从表数据.
            ReplaceDtls   += firsts[fk_md] ? BP.DA.DataTableConvertJson.Dataset2Json(ds) : "[]";
            ReplaceDtlNos += GenerateFieldsJsonString(replaceDtlNos);
        }
Beispiel #2
0
 /// <summary>
 /// 转换键值集合为json字符串
 /// </summary>
 /// <param name="dictParams">键值集合</param>
 /// <returns></returns>
 private string GenerateParamsJsonString(ReplaceFieldList dictParams)
 {
     return("[" + dictParams.Aggregate(string.Empty, (curr, next) => curr + string.Format("{{\"key\":\"{0}\",\"value\":\"{1}\",\"type\":\"{2}\"}},", next.key, (next.value ?? "").Replace("\\", "\\\\").Replace("'", "\'"), next.type)).TrimEnd(',') + "]");
 }
Beispiel #3
0
        public void LoadFrmData(MapAttrs mattrs, Entity en)
        {
            var mes        = new MapExts(this.FK_MapData);
            var dictParams = new ReplaceFieldList();
            var fields     = new List <string>();

            dictParams.Add("No", WebUser.No, "string");
            dictParams.Add("Name", WebUser.Name, "string");
            dictParams.Add("FK_Dept", WebUser.FK_Dept, "string");
            dictParams.Add("FK_DeptName", WebUser.FK_DeptName, "string");

            if (mes.Count == 0)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
                ReplaceFields = "[]";
                ReplaceDtlNos = "[]";
                ReplaceDtls   = "[]";
                return;
            }

            MapExt item = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull) as MapExt;

            if (item == null)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
                ReplaceFields = "[]";
                ReplaceDtlNos = "[]";
                ReplaceDtls   = "[]";
                return;
            }

            DataTable dt    = null;
            MapAttr   mattr = null;
            string    sql   = item.Tag;

            if (string.IsNullOrEmpty(sql) == false)
            {
                /* 如果有填充主表的sql  */
                #region 处理sql变量
                sql = sql.Replace("@WebUser.No", WebUser.No);
                sql = sql.Replace("@WebUser.Name", WebUser.Name);
                sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                sql = sql.Replace("@WebUser.FK_DeptName", WebUser.FK_DeptName);

                foreach (MapAttr attr in mattrs)
                {
                    if (sql.Contains("@"))
                    {
                        sql = sql.Replace("@" + attr.KeyOfEn, en.GetValStrByKey(attr.KeyOfEn));
                    }
                    else
                    {
                        break;
                    }
                }
                #endregion 处理sql变量

                if (string.IsNullOrEmpty(sql) == false)
                {
                    if (sql.Contains("@"))
                    {
                        throw new Exception("设置的sql有错误可能有没有替换的变量:" + sql);
                    }
                    dt = DBAccess.RunSQLReturnTable(sql);
                    if (dt.Rows.Count == 1)
                    {
                        DataRow dr = dt.Rows[0];
                        foreach (DataColumn dc in dt.Columns)
                        {
                            en.SetValByKey(dc.ColumnName, dr[dc.ColumnName].ToString());

                            mattr = mattrs.GetEntityByKey(MapAttrAttr.KeyOfEn, dc.ColumnName) as MapAttr;

                            dictParams.Add(dc.ColumnName, dr[dc.ColumnName].ToString(), mattr != null && mattr.IsSigan ? "sign" : "string");
                            fields.Add(dc.ColumnName);
                        }
                    }
                }
            }

            if (IsFirst)
            {
                ReplaceParams = GenerateParamsJsonString(dictParams);
            }
            else
            {
                ReplaceParams = "[]";
            }

            ReplaceFields = GenerateFieldsJsonString(fields);

            if (string.IsNullOrEmpty(item.Tag1) ||
                item.Tag1.Length < 15)
            {
                ReplaceDtls   = "[]";
                ReplaceDtlNos = "[]";
                return;
            }

            ReplaceDtls   = "[";
            ReplaceDtlNos = "[";
            MapDtls dtls = new MapDtls(this.FK_MapData);
            // 填充从表.
            foreach (MapDtl dtl in dtls)
            {
                ReplaceDtlNos += "\"" + dtl.No + "\",";

                if (!IsFirst)
                {
                    continue;
                }

                string[] sqls = item.Tag1.Split('*');
                foreach (string mysql in sqls)
                {
                    if (string.IsNullOrEmpty(mysql))
                    {
                        continue;
                    }

                    if (mysql.Contains(dtl.No + "=") == false)
                    {
                        continue;
                    }

                    #region 处理sql.
                    sql = mysql;
                    sql = sql.Replace(dtl.No + "=", "");
                    sql = sql.Replace("@WebUser.No", WebUser.No);
                    sql = sql.Replace("@WebUser.Name", WebUser.Name);
                    sql = sql.Replace("@WebUser.FK_Dept", WebUser.FK_Dept);
                    sql = sql.Replace("@WebUser.FK_DeptName", WebUser.FK_DeptName);
                    foreach (MapAttr attr in mattrs)
                    {
                        if (sql.Contains("@"))
                        {
                            sql = sql.Replace("@" + attr.KeyOfEn, en.GetValStrByKey(attr.KeyOfEn));
                        }
                        else
                        {
                            break;
                        }
                    }
                    #endregion 处理sql.

                    if (string.IsNullOrEmpty(sql))
                    {
                        continue;
                    }

                    if (sql.Contains("@"))
                    {
                        throw new Exception("设置的sql有错误可能有没有替换的变量:" + sql);
                    }

                    GEDtls gedtls = new GEDtls(dtl.No);

                    try
                    {
                        gedtls.Delete(GEDtlAttr.RefPK, en.PKVal);
                    }
                    catch
                    {
                        gedtls.GetNewEntity.CheckPhysicsTable();
                    }

                    dt = DBAccess.RunSQLReturnTable(sql);
                    //dictDtls.Add(dtl.No, dt);
                    ReplaceDtls += "{\"dtlno\":\"" + dtl.No + "\",\"dtl\":[";
                    var idx = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        ReplaceDtls += "{\"rowid\":" + (idx++) + ",\"cells\":[";
                        GEDtl gedtl = gedtls.GetNewEntity as GEDtl;

                        foreach (DataColumn dc in dt.Columns)
                        {
                            gedtl.SetValByKey(dc.ColumnName, dr[dc.ColumnName].ToString());

                            mattr = dtl.MapAttrs.GetEntityByKey(MapAttrAttr.KeyOfEn, dc.ColumnName) as MapAttr;

                            ReplaceDtls += "{\"key\":\"" + dc.ColumnName + "\",\"value\":\"" + dr[dc.ColumnName] + "\",\"type\":\"" + (mattr != null && mattr.IsSigan ? "sign" : "string") + "\"},";
                        }

                        ReplaceDtls = ReplaceDtls.TrimEnd(',') + "]},";
                        gedtl.RefPK = en.PKVal.ToString();
                        gedtl.RDT   = DataType.CurrentDataTime;
                        gedtl.Rec   = WebUser.No;
                        gedtl.Insert();
                    }

                    ReplaceDtls = ReplaceDtls.TrimEnd(',') + "]}";
                }
            }

            ReplaceDtls   = ReplaceDtls.TrimEnd(',') + "]";
            ReplaceDtlNos = ReplaceDtlNos.TrimEnd(',') + "]";
        }