Beispiel #1
0
        private void SaveFile()
        {
            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                if (files.Count > 0)
                {
                    //检查文件扩展名字
                    HttpPostedFile postedFile = files[0];
                    var            fileName   = Path.GetFileName(Request.QueryString["filename"]);
                    var            path       = SystemConfig.PathOfDataUser + @"\FrmOfficeFiles\" + this.FK_MapData;

                    if (fileName != "")
                    {
                        postedFile.SaveAs(path + "\\" + fileName);

                        var en = new GEEntityWordFrm(this.FK_MapData);
                        en.RetrieveFromDBSources();

                        en.LastEditer = WebUser.Name;
                        en.RDT        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        en.Update();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 保存从word中提取的数据
        /// </summary>
        private void SaveFieldInfos()
        {
            var mes = new MapExts(this.FK_MapData);

            if (mes.Count == 0)
            {
                return;
            }

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

            if (item == null)
            {
                return;
            }

            var fieldCount = 0;

            foreach (var key in Request.Form.AllKeys)
            {
                var idx = 0;
                if (key.StartsWith("field") && key.Length > 5 && int.TryParse(key.Substring(5), out idx))
                {
                    fieldCount++;
                }
            }

            var fieldsJson = string.Empty;

            for (var i = 0; i < fieldCount; i++)
            {
                fieldsJson += Request["field" + i];
            }

            var fields = LitJson.JsonMapper.ToObject <List <ReplaceField> >(fieldsJson);

            //更新主表数据
            var en = new GEEntityWordFrm(this.FK_MapData);

            en.OID = this.OID;

            if (en.RetrieveFromDBSources() == 0)
            {
                throw new Exception("OID=" + this.OID + "的数据在" + this.FK_MapData + "中不存在,请检查!");
            }

            //此处因为weboffice在上传的接口中,只有上传成功与失败的返回值,没有具体的返回信息参数,所以未做异常处理
            foreach (var field in fields)
            {
                en.SetValByKey(field.key, field.value);
            }

            en.LastEditer = WebUser.Name;
            en.RDT        = DataType.CurrentDataTime;
            en.Update();

            //todo:更新明细表数据,此处逻辑可能还有待商榷
            var mdtls = new MapDtls(this.FK_MapData);

            if (mdtls.Count == 0)
            {
                return;
            }

            var dtlsCount = 0;

            foreach (var key in Request.Form.AllKeys)
            {
                var idx = 0;
                if (key.StartsWith("dtls") && key.Length > 4 && int.TryParse(key.Substring(4), out idx))
                {
                    dtlsCount++;
                }
            }

            var dtlsJson = string.Empty;

            for (var i = 0; i < dtlsCount; i++)
            {
                dtlsJson += Request["dtls" + i];
            }

            //var dtlsJson = Request["dtls"];
            var             dtls   = LitJson.JsonMapper.ToObject <List <ReplaceDtlTable> >(dtlsJson);
            GEDtls          gedtls = null;
            GEDtl           gedtl  = null;
            ReplaceDtlTable wdtl   = null;

            foreach (MapDtl mdtl in mdtls)
            {
                wdtl = dtls.FirstOrDefault(o => o.dtlno == mdtl.No);

                if (wdtl == null || wdtl.dtl.Count == 0)
                {
                    continue;
                }

                //此处不是真正意义上的更新,因为不知道明细表的主键,只能将原明细表中的数据删除掉,然后再重新插入新的数据
                gedtls = new GEDtls(mdtl.No);
                gedtls.Delete(GEDtlAttr.RefPK, en.PKVal);

                foreach (var d in wdtl.dtl)
                {
                    gedtl = gedtls.GetNewEntity as GEDtl;

                    foreach (var cell in d.cells)
                    {
                        gedtl.SetValByKey(cell.key, cell.value);
                    }

                    gedtl.RefPK = en.PKVal.ToString();
                    gedtl.RDT   = DataType.CurrentDataTime;
                    gedtl.Rec   = WebUser.No;
                    gedtl.Insert();
                }
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserName = WebUser.Name;

            if (string.IsNullOrEmpty(FK_MapData))
            {
                divMenu.InnerHtml = "<h1 style='color:red'>传入参数错误!<h1>";
                return;
            }

            var md = new MapData(this.FK_MapData);

            string type = Request["action"];

            if (string.IsNullOrEmpty(type))
            {
                /*这里是什么?怎么没有注释?*/
                InitOffice(true, md);
            }
            else
            {
                if (type.Equals("LoadFile"))
                {
                    LoadFile();
                    return;
                }

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

                InitOffice(false, md);
            }

            //打开数据文件.
            GEEntityWordFrm en = new GEEntityWordFrm(this.FK_MapData, this.OID);


            en.CheckPhysicsTable();
            en.OID = this.OID;

            var root     = SystemConfig.PathOfDataUser + "\\FrmOfficeTemplate\\";
            var rootInfo = new DirectoryInfo(root);

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

            var      files    = rootInfo.GetFiles(en.FK_MapData + ".*");
            FileInfo tmpFile  = null;
            FileInfo wordFile = null;

            var pathDir = SystemConfig.PathOfDataUser + @"\FrmOfficeFiles\" + this.FK_MapData;

            if (!Directory.Exists(pathDir))
            {
                Directory.CreateDirectory(pathDir);
            }

            // 判断是否有这个数据文件.
            if (files.Length == 0)
            {
                Response.Write("<h3>Word表单模板文件不存在,请确认已经上传Word表单模板</h3>");
                Response.End();
                return;
            }

            tmpFile  = files[0];
            wordFile = new FileInfo(pathDir + "\\" + this.OID + tmpFile.Extension);

            if (wordFile.Exists == false)
            {
                IsFirst = true;
                File.Copy(tmpFile.FullName, wordFile.FullName);
            }
            else
            {
                IsFirst = false;
            }

            if (en.RetrieveFromDBSources() == 0)
            {
                en.FilePath   = wordFile.FullName;
                en.RDT        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                en.LastEditer = WebUser.Name;
                en.Insert(); // 执行插入。
            }

            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]);
            }

            //装载数据.
            this.LoadFrmData(new MapAttrs(this.FK_MapData), en);

            //替换掉 word 里面的数据.
            fileName.Text = string.Format(@"\{0}\{1}{2}", en.FK_MapData, this.OID, wordFile.Extension);
            fileType.Text = wordFile.Extension.TrimStart('.');
        }