Пример #1
0
        /// <summary>
        /// 获取列表配置信息
        /// </summary>
        /// <param name="strVT_CardNum">单据编号</param>
        /// <param name="strFilePath">配置文件地址</param>
        /// <returns></returns>
        public static ListTemplateConfiguration GetListTemplateConfig(string strVT_CardNum, string strFilePath = "Config\\KHYFM_VoucherTemplate.xml")
        {
            ListTemplateConfiguration vgvListConfig = new ListTemplateConfiguration();

            DataTable dtColumns = TemplateInitTool.GetListTemplate();
            //读取IO文件配置
            //Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(strFileName);
            string strBinFile = System.IO.Directory.GetCurrentDirectory() + "\\";

            if (File.Exists(strBinFile + strFilePath))
            {
                FileStream stream = null;
                try
                {
                    using (stream = new FileStream(strBinFile + strFilePath, FileMode.Open))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(stream);
                        XmlNode node = doc.SelectSingleNode(String.Format("xml/voucher[@VT_CardNum='{0}']", strVT_CardNum));
                        if (node != null)
                        {
                            XmlElement element = node as XmlElement;
                            vgvListConfig.VT_CardNum = strVT_CardNum;
                            vgvListConfig.VT_Name    = element.GetAttribute("VT_Name");

                            XmlNodeList nodelist = node.SelectNodes(string.Format("list//item"));
                            for (int i = 0; i < nodelist.Count; i++)
                            {
                                XmlElement elementItem = nodelist[i] as XmlElement;
                                DataRow    dNewRow     = dtColumns.NewRow();

                                dNewRow["cFieldName"] = elementItem.GetAttribute("cFieldName");
                                dNewRow["cCaption"]   = elementItem.GetAttribute("cCaption");

                                dNewRow["iWidth"] = elementItem.GetAttribute("iWidth") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iWidth"));

                                dNewRow["bVisible"] = elementItem.GetAttribute("bVisible") == "" ? false : XmlConvert.ToBoolean(elementItem.GetAttribute("bVisible"));

                                dNewRow["bSum"]   = elementItem.GetAttribute("bSum") == "" ? false : XmlConvert.ToBoolean(elementItem.GetAttribute("bSum"));
                                dNewRow["iOrder"] = elementItem.GetAttribute("iOrder") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iOrder"));;

                                dNewRow["cFormat"] = elementItem.GetAttribute("cFormat");

                                dNewRow["iAlignment"] = elementItem.GetAttribute("iAlignment") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iAlignment"));;

                                dtColumns.Rows.Add(dNewRow);
                            }
                            vgvListConfig.dtColumns = dtColumns;
                        }
                        else
                        {
                            throw new Exception("未查找到相关配置信息,请联系管理员");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }
            }
            else
            {
                throw new Exception("本地配置文件已经不存在,请联系管理员");
            }

            return(vgvListConfig);
        }
Пример #2
0
        /// <summary>
        /// 获取单据配置信息
        /// </summary>
        /// <param name="strVT_CardNum">单据编号</param>
        /// <param name="strVT_Code">模板编号</param>
        /// <param name="strFilePath">配置文件地址</param>
        /// <returns></returns>
        public static VoucherTemplateConfiguration GetVoucherTemplateConfig(string strVT_CardNum, string strVT_Code, string strFilePath = "Config\\KHYFM_VoucherTemplate.xml")
        {
            VoucherTemplateConfiguration vgvVoucherConfig = new VoucherTemplateConfiguration();

            DataTable dtColumns = TemplateInitTool.GetVoucherTemplate();

            //读取IO文件配置
            //Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(strFileName);
            string strBinFile = System.IO.Directory.GetCurrentDirectory() + "\\";

            if (File.Exists(strBinFile + strFilePath))
            {
                FileStream stream = null;
                try
                {
                    using (stream = new FileStream(strBinFile + strFilePath, FileMode.Open))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(stream);
                        XmlNode node = doc.SelectSingleNode(String.Format("xml/voucher[@VT_CardNum='{0}']//vouchertemplates[@VT_Code='{1}']", strVT_CardNum, strVT_Code));
                        if (node != null)
                        {
                            XmlElement element = node as XmlElement;
                            vgvVoucherConfig.VT_CardNum = strVT_CardNum;
                            vgvVoucherConfig.VT_Title   = element.GetAttribute("VT_Title");
                            vgvVoucherConfig.VT_Code    = strVT_Code;
                            vgvVoucherConfig.VT_Mode    = XmlConvert.ToInt32(element.GetAttribute("VT_Mode"));

                            XmlNodeList nodelist = node.ChildNodes;

                            for (int i = 0; i < nodelist.Count; i++)
                            {
                                XmlElement elementItem = nodelist[i] as XmlElement;
                                DataRow    dNewRow     = dtColumns.NewRow();
                                dNewRow["cFieldName"]    = elementItem.GetAttribute("cFieldName");
                                dNewRow["iFieldType"]    = XmlConvert.ToInt32(elementItem.GetAttribute("iFieldType"));
                                dNewRow["cCardItemName"] = elementItem.GetAttribute("cCardItemName");
                                dNewRow["cCaption"]      = elementItem.GetAttribute("cCaption") == "" ? elementItem.GetAttribute("cCardItemName") : elementItem.GetAttribute("cCaption");

                                dNewRow["cColType"] = elementItem.GetAttribute("cColType") == "" ? "txt" : elementItem.GetAttribute("cColType");

                                dNewRow["iWidth"] = elementItem.GetAttribute("iWidth") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iWidth"));

                                dNewRow["iHeigth"] = elementItem.GetAttribute("iHeigth") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iHeigth"));

                                dNewRow["cCardSection"] = elementItem.GetAttribute("cCardSection");
                                dNewRow["iCOX"]         = elementItem.GetAttribute("iCOX") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iCOX"));
                                dNewRow["iCOY"]         = elementItem.GetAttribute("iCOY") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iCOY"));

                                dNewRow["bVisible"] = elementItem.GetAttribute("bVisible") == "" ? true : XmlConvert.ToBoolean(elementItem.GetAttribute("bVisible"));

                                dNewRow["bReadOnly"] = elementItem.GetAttribute("bReadOnly") == "" ? true : XmlConvert.ToBoolean(elementItem.GetAttribute("bReadOnly"));

                                dNewRow["bMain"] = elementItem.GetAttribute("bMain") == "" ? false : XmlConvert.ToBoolean(elementItem.GetAttribute("bMain"));

                                dNewRow["bNeedSum"] = elementItem.GetAttribute("bNeedSum") == "" ? true : XmlConvert.ToBoolean(elementItem.GetAttribute("bNeedSum"));

                                dNewRow["cDefaultValue"] = elementItem.GetAttribute("cDefaultValue");
                                dNewRow["cDataRule"]     = elementItem.GetAttribute("cDataRule");

                                dNewRow["bIsNull"] = elementItem.GetAttribute("bIsNull") == "" ? false : XmlConvert.ToBoolean(elementItem.GetAttribute("bIsNull"));

                                dNewRow["iOrder"] = elementItem.GetAttribute("iOrder") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iOrder"));

                                dNewRow["cFormat"] = elementItem.GetAttribute("cFormat");

                                dNewRow["iAlignment"] = elementItem.GetAttribute("iAlignment") == "" ? 0 : XmlConvert.ToInt32(elementItem.GetAttribute("iAlignment"));

                                dNewRow["refObject"] = elementItem.GetAttribute("refObject");
                                dtColumns.Rows.Add(dNewRow);
                            }
                            vgvVoucherConfig.dtColumns = dtColumns;
                        }
                        else
                        {
                            throw new Exception("未查找到相关配置信息,请联系管理员");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }
            }
            else
            {
                throw new Exception("本地配置文件已经不存在,请联系管理员");
            }
            return(vgvVoucherConfig);
        }