コード例 #1
0
        private void btnBuild_Click(object sender, EventArgs e)
        {
            string          path     = Application.StartupPath + "\\工具配置文件\\TableConfig.xml";
            List <MyConfig> menuList = XmlHelper.XmlDeserializeFromFile <List <MyConfig> >(path, Encoding.UTF8);

            int rowIndex = 1;

            foreach (DataGridViewRow row in dg1.Rows)
            {
                DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)row.Cells["chkSel"];
                Boolean flag = Convert.ToBoolean(checkCell.Value);
                if (flag)
                {
                    string dlcFileName = row.Cells["DlcFileName"].Value.ToString();
                    string dlcFilePath = row.Cells["DlcFilePath"].Value.ToString();
                    string tbName      = dlcFileName.Substring(0, dlcFileName.IndexOf("."));

                    string configFileName    = tbName + ".xml";
                    string configRawFileName = tbName.Substring(4, tbName.Length - 4) + ".xml";
                    string configFilepath    = Path.Combine(Application.StartupPath + "\\工具配置文件\\TableExplain", configFileName);
                    string configRawFilepath = Path.Combine(Application.StartupPath + "\\工具配置文件\\TableExplain", configRawFileName);

                    if (!File.Exists(configRawFilepath))
                    {
                        continue;
                    }


                    MyConfig mc = new MyConfig();
                    mc.TxtName          = dlcFileName;
                    mc.Classify         = "Dlc";
                    mc.Notes            = dlcFileName;
                    mc.HaveColumn       = "NO";
                    mc.IsCache          = "0";
                    mc.DtType           = "3";
                    mc.BasicCritical    = "";
                    mc.EffectCritical   = "";
                    mc.HaveHelperColumn = "";
                    mc.DetailDtName     = "";
                    mc.MainDtName       = tbName;
                    menuList.Add(mc);

                    List <TableExplain> configFileList = new List <TableExplain>();


                    int index = 0;
                    using (StreamReader sr = new StreamReader(dlcFilePath, Encoding.Default))
                    {
                        string names = string.Empty;
                        string ids   = string.Empty;
                        while (index < 2)
                        {
                            if (index == 0)
                            {
                                names = sr.ReadLine(); //读取一行数据
                            }
                            else
                            {
                                ids = sr.ReadLine();
                            }
                            index++;
                        }
                        string[] rowIds   = ids.Split('\t');
                        string[] rowNames = names.Split('\t');

                        List <TableExplain> teList = XmlHelper.XmlDeserializeFromFile <List <TableExplain> >(configRawFilepath, Encoding.UTF8);
                        for (int i = 0; i < rowIds.Length; i++)
                        {
                            TableExplain te = new TableExplain();
                            if (i < 3)
                            {
                                te.IsSelect = "1";
                            }
                            te.Column      = teList[i].Column;
                            te.Explain     = teList[i].Explain;
                            te.Text        = rowNames[i];
                            te.ToolsColumn = teList[i].ToolsColumn;
                            configFileList.Add(te);
                            rowIndex++;
                        }
                        rowIndex = rowIndex + 10;
                    }


                    XmlHelper.XmlSerializeToFile(configFileList, configFilepath, Encoding.UTF8);
                }
            }

            XmlHelper.XmlSerializeToFile(menuList, path, Encoding.UTF8);
            MessageBox.Show("修改成功!");
        }
コード例 #2
0
        private void tsmImportXML_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = true;
            fileDialog.Title       = "请选择文件";
            fileDialog.Filter      = "1.1MOD的注释文件|*.xml";

            DataTable dt = new DataTable();

            dt.Columns.Add("tablename");
            dt.Columns.Add("column");
            dt.Columns.Add("Value");

            Dictionary <string, string> dlcTbName = new Dictionary <string, string>();
            StringBuilder sb = new StringBuilder();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string      file = fileDialog.FileName;
                XmlDocument doc  = new XmlDocument();
                doc.Load(file);                                                    //加载Xml文件
                XmlElement  rootElem    = doc.DocumentElement;                     //获取根节点
                XmlNodeList personNodes = rootElem.GetElementsByTagName("Table1"); //获取person子节点集合
                foreach (XmlNode node in personNodes)
                {
                    XmlNodeList tablename = ((XmlElement)node).GetElementsByTagName("tablename");  //获取age子XmlElement集合
                    XmlNodeList column    = ((XmlElement)node).GetElementsByTagName("column");
                    XmlNodeList value     = ((XmlElement)node).GetElementsByTagName("Value");
                    string      tbName    = tablename[0].InnerText;
                    if (!dlcTbName.ContainsKey(tbName))
                    {
                        dlcTbName.Add(tbName, tbName);
                    }
                    DataRow dr = dt.NewRow();
                    dr["tablename"] = tbName;
                    dr["column"]    = column[0].InnerText;
                    dr["Value"]     = value[0].InnerText;
                    dt.Rows.Add(dr);
                }
            }
            ToolsHelper tl   = new ToolsHelper();
            string      path = Application.StartupPath + "\\工具配置文件\\TableExplain";

            foreach (KeyValuePair <string, string> dlc in dlcTbName)
            {
                List <TableExplain> list = new List <TableExplain>();
                DataRow[]           drs  = dt.Select("tablename='" + dlc.Key + "'");
                foreach (DataRow item in drs)
                {
                    TableExplain te = new TableExplain();
                    te.Column = item["column"].ToString();
                    string value = item["Value"].ToString();
                    if (StringUtils.GetCnLength(value) <= 8)
                    {
                        te.Text = value;
                    }
                    te.Explain = item["Value"].ToString();

                    list.Add(te);
                }
                XmlHelper.XmlSerializeToFile(list, Path.Combine(path, dlc.Key), Encoding.UTF8);
                MessageBox.Show("导入成功!");
            }
        }
コード例 #3
0
ファイル: Almighty.cs プロジェクト: xuqingxin001/xkqz_mod
        private void Almighty_Load(object sender, EventArgs e)
        {
            if (DateTime.Now.Second % 2 == 0)
            {
                lblTag.Text = "点击序号,选中整行后,在不使用查询的情况下,可以使用方向键↑ ↓调整数据的顺序";
            }
            else
            {
                lblTag.Text = "如果当前表格不小心修改错了,可以通过点击顶部菜单【重新加载】按钮重新加载文件!";
            }

            if (DataHelper.ReadError.ToString() != "")
            {
                timer1.Start();
                gbError.Visible = true;
                txtError.Text   = DataHelper.ReadError.ToString();
            }

            dg1.AllowUserToAddRows = false;
            try
            {
                string    path = string.Empty;
                DataTable dt;

                string haveHelperColumn = string.Empty;
                if (DataHelper.FormConfig.ContainsKey(_tbName))
                {
                    _myConfig = DataHelper.FormConfig[_tbName];
                    _editForm = _myConfig.EditFormName;

                    if (_editForm != "" && _editForm != "0")
                    {
                        btnAdd.Visible     = true;
                        btnCopyAdd.Visible = true;
                    }
                }

                //绑定数据源
                if (_fileType == "other")
                {
                    BulidSn(DataHelper.XkfyData.Tables[_tbName]);
                    dt = DataHelper.XkfyData.Tables[_tbName];
                }
                else
                {
                    BulidSn(DataHelper.MapData.Tables[_tbName]);
                    dt = DataHelper.MapData.Tables[_tbName];
                }
                dg1.DataSource = dt.DefaultView;


                Dictionary <string, TableExplain> dlc = new Dictionary <string, TableExplain>();
                if (_fileType == "MapInfo")
                {
                    path = Path.Combine(ToolsHelper.ExplainPath, "MapInfo.xml");
                }
                else if (_fileType == "NpcProduct")
                {
                    path = Path.Combine(ToolsHelper.ExplainPath, "NpcProduct.xml");
                }
                else
                {
                    path = Path.Combine(ToolsHelper.ExplainPath, _tbName + ".xml");
                }

                if (File.Exists(path))
                {
                    int top         = 10;
                    int left        = 7;
                    int width       = 122;
                    int columnIndex = 0;

                    List <TableExplain> list = DataHelper.ReadXmlToList <TableExplain>(path);
                    foreach (TableExplain item in list)
                    {
                        if (!string.IsNullOrEmpty(item.Column))
                        {
                            dlc.Add(item.Column.Replace("#", "@"), item);
                        }
                        else
                        {
                            dlc.Add(item.ToolsColumn, item);
                        }
                        #region 生成查询控件
                        if (!string.IsNullOrEmpty(item.IsSelect) && item.IsSelect == "1")
                        {
                            if (columnIndex == 3)
                            {
                                top  = 40;
                                left = 7;
                            }
                            Label tips = new Label();
                            tips.Top   = top + 4;
                            tips.Left  = left;
                            tips.Width = width;
                            left      += tips.Width;

                            TextBox tb = new TextBox();
                            if (!string.IsNullOrEmpty(item.Column))
                            {
                                tb.Tag = item.Column;
                            }
                            else
                            {
                                tb.Tag = item.ToolsColumn;
                            }

                            tb.Top   = top;
                            tb.Left  = left;
                            tb.Width = width;

                            left += tb.Width + 15;
                            gbQueryCon.Controls.Add(tips);
                            gbQueryCon.Controls.Add(tb);


                            //把lable文字修改为中文显示
                            if (!string.IsNullOrEmpty(item.Text))
                            {
                                tips.Text = item.Text;
                            }
                            else if (!string.IsNullOrEmpty(item.Column))
                            {
                                tips.Text = item.Column;
                            }
                            else
                            {
                                tips.Text = item.ToolsColumn;
                            }
                            toolTip.SetToolTip(tips, item.Explain);
                            columnIndex++;
                        }
                        #endregion
                    }

                    CheckBox ck = new CheckBox();
                    ck.Tag   = "rowState";
                    ck.Top   = top;
                    ck.Left  = left;
                    ck.Width = width;
                    ck.Text  = "只显示我修改的";
                    gbQueryCon.Controls.Add(ck);
                }
                else
                {
                    MessageBox.Show("缺少列配置文件,文件路径" + path);
                }


                foreach (DataGridViewColumn dgvCol in dg1.Columns)
                {
                    if (dlc.ContainsKey(dgvCol.Name) && dlc[dgvCol.Name] != null)
                    {
                        TableExplain te = dlc[dgvCol.Name];
                        if (!string.IsNullOrEmpty(te.Text))
                        {
                            dgvCol.HeaderText = te.Text;
                        }
                        else if (!string.IsNullOrEmpty(te.Column))
                        {
                            dgvCol.HeaderText = te.Column;
                        }
                        else
                        {
                            dgvCol.HeaderText = te.ToolsColumn;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }