Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //WebUser.SignInOfGener(new BP.Port.Emp("fuhui"));

            UserName = WebUser.Name;
            if (string.IsNullOrEmpty(this.FK_MapData))
            {
                divMenu.InnerHtml = "<h1 style='color:red'>必须传入参数FK_Mapdata!<h1>";
                return;
            }

            fk_mapdatas = FK_MapData.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            //获得外部的标记。
            string type = Request["action"];

            if (string.IsNullOrEmpty(type))
            {
                /** 第一次进来,的时候,没有标记。
                 */
                //初始化它的解决方案.  add by stone. 2015-01-25. 增加权限控制方案,以在不同的节点实现不同的控制.
                IsEdit = string.IsNullOrWhiteSpace(Request.QueryString["IsEdit"])
                             ? true
                             : Request.QueryString["IsEdit"] == "1";
                IsPrint = string.IsNullOrWhiteSpace(Request.QueryString["IsPrint"])
                             ? true
                             : Request.QueryString["IsPrint"] == "1";

                GenerateToolbarSlns();
            }
            else
            {
                if (type.Equals("LoadFile"))
                {
                    LoadFile();
                    return;
                }

                if (type.Equals("SaveFile"))
                {
                    SaveFile(fk_mapdatas);
                    SaveFieldInfos(fk_mapdatas);
                    return;
                }

                throw new Exception("@没有处理的标记错误:" + type);
            }

            firsts = new Dictionary <string, bool>();
            GEEntityExcelFrm en        = null;
            FileInfo         tmpFile   = null;
            FileInfo         excelFile = null;
            FrmFields        frmFields = null;

            //检查数据文件是否存在?如果存在并打开不存在并copy模版。
            var root     = SystemConfig.PathOfDataUser + "\\FrmOfficeTemplate\\";
            var rootInfo = new DirectoryInfo(root);
            var isFirst  = false;

            if (!rootInfo.Exists)
            {
                rootInfo.Create();
            }

            ReplaceParams     = "[";
            ReplaceFields     = "[";
            ReplaceDtlNos     = "[";
            ReplaceDtls       = "[";
            IsFirsts          = "[";
            FK_MapDatas       = "[";
            ReplaceFieldCtrls = "[";

            //根据excel表单no来处理各自的信息
            var pk = 0;

            foreach (var fk_md in fk_mapdatas)
            {
                //创建excel数据实体.
                en = new GEEntityExcelFrm(fk_md);

                var files = rootInfo.GetFiles(fk_md + ".*");
                // 判断是否有这个数据文件.
                if (files.Length == 0)
                {
                    Response.Write("<h3>Excel表单模板文件不存在,请确认已经上传Excel表单模板,该模版的位于服务器:" + rootInfo.FullName + "</h3>");
                    Response.End();
                    return;
                }

                FK_MapDatas += "{\"Name\":\"" + en.ClassID + "\",\"Text\":\"" + en.EnDesc + "\"},";

                // 检查数据目录文件是否存在?
                var pathDir = SystemConfig.PathOfDataUser + @"\FrmOfficeFiles\" + fk_md;
                if (!Directory.Exists(pathDir))
                {
                    Directory.CreateDirectory(pathDir);
                }

                // 判断who is pk
                pk = GetPK(fk_md);
                if (pk == 0)
                {
                    return;
                }

                // 初始化数据文件.
                tmpFile   = files[0];
                excelFile = new FileInfo(pathDir + "\\" + pk + tmpFile.Extension);
                if (excelFile.Exists == false)
                {
                    /*如果不存在就copy 一个副本。*/
                    File.Copy(tmpFile.FullName, excelFile.FullName);
                    isFirst = true;
                }
                else
                {
                    //edited by liuxc,2015-3-25,此处增加判断,如果模板文件与生成的数据文件的最后修改时间是一致的,表明此数据文件还没有经过修改,也标识为第一次,加载填充数据信息
                    isFirst = excelFile.LastWriteTime.Equals(tmpFile.LastWriteTime);
                }

                firsts.Add(fk_md, isFirst);
                IsFirsts += "{\"" + fk_md + "\":" + isFirst.ToString().ToLower() + "},";

                //edited by liuxc,2015-1-30,如果在构造中使用传递OID的构造函数,则下面的Save时,第一次会插入不成功,此处是因为insert时判断OID不为0则认为是已经存在的记录,实际上此处还没有存在,所以使用下面的逻辑进行判断,如果没有该条记录,则插入新记录
                en.OID = pk;

                if (en.IsExits == false)
                {
                    en.InsertAsOID(pk);
                }
                else
                {
                    en.Retrieve();
                }

                //给实体赋值.
                en.FilePath   = excelFile.FullName;
                en.RDT        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                en.LastEditer = WebUser.Name;
                en.SetPara(FK_Node.ToString(), true);
                en.ResetDefaultVal();

                //接受外部参数数据。
                string[] paras = this.RequestParas.Split('&');
                foreach (string str in paras)
                {
                    if (string.IsNullOrEmpty(str) || str.Contains("=") == false)
                    {
                        continue;
                    }
                    string[] kvs = str.Split('=');
                    en.SetValByKey(kvs[0], kvs[1]);
                }

                en.Save(); //执行保存.

                //装载数据。
                ReplaceParams     += "{\"" + fk_md + "\":";
                ReplaceFields     += "{\"" + fk_md + "\":";
                ReplaceDtlNos     += "{\"" + fk_md + "\":";
                ReplaceDtls       += "{\"" + fk_md + "\":";
                ReplaceFieldCtrls += "{\"" + fk_md + "\":[";

                this.LoadFrmData(fk_md, en);

                //字段控制
                frmFields = new FrmFields(fk_md, FK_Node);
                foreach (FrmField frmField in frmFields)
                {
                    ReplaceFieldCtrls +=
                        string.Format("{{\"{0}\":{{\"Name\":\"{1}\",\"UIVisible\":{2},\"UIIsEnable\":{3},\"IsNotNull\":{4},\"OldValue\":\"{5}\"}}}},",
                                      frmField.KeyOfEn,
                                      frmField.Name,
                                      frmField.UIVisible.ToString().ToLower(),
                                      frmField.UIIsEnable.ToString().ToLower(),
                                      frmField.IsNotNull.ToString().ToLower(),
                                      frmField.UIIsEnable ? "" : en.GetValStringByKey(frmField.KeyOfEn, ""));
                }

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

            ReplaceParams     = ReplaceParams.TrimEnd(',') + "]";
            ReplaceFields     = ReplaceFields.TrimEnd(',') + "]";
            ReplaceDtlNos     = ReplaceDtlNos.TrimEnd(',') + "]";
            ReplaceDtls       = ReplaceDtls.TrimEnd(',') + "]";
            IsFirsts          = IsFirsts.TrimEnd(',') + "]";
            FK_MapDatas       = FK_MapDatas.TrimEnd(',') + "]";
            ReplaceFieldCtrls = ReplaceFieldCtrls.TrimEnd(',') + "]";

            //替换掉 word 里面的数据.
            fileName.Text = string.Format(@"\{0}\{1}{2}", fk_mapdatas[0], pk, excelFile.Extension);
            fileType.Text = excelFile.Extension.TrimStart('.');
        }
Exemple #2
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(',') + "]";
        }