Exemple #1
0
        private void XmlTableEditor_Load(object sender, EventArgs e)
        {
            string command = Environment.CommandLine;//获取进程命令行参数

            string[] para = command.Split('\"');
            if (para.Length > 3)
            {
                string pathC = para[3];
                OpenXml(pathC);
            }
            mainTable = this;
        }
Exemple #2
0
        private void XmlTableEditor_Load(object sender, EventArgs e)
        {
            var infos = Environment.GetCommandLineArgs();

            mainTable = this;
            if (infos.Length > 1)
            {
                string pathC = infos[1];
                OpenXml(pathC);
            }
            if (infos.Length > 2)
            {
                var findStr = infos[2];
                FindAndSelect(findStr);
            }
            gridView.RowsDefaultCellStyle.BackColor            = Color.WhiteSmoke;
            gridView.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
        }
Exemple #3
0
        public XmlNode UpdateChange()
        {
            var root = xml.LastChild;

            List <XmlNode> removeList = new List <XmlNode>();

            for (int row = 0; row < data.Rows.Count; row++)
            {
                var rowNode = root.ChildNodes[row];

                if (rowNode == null)
                {
                    if (root.FirstChild != null)
                    {
                        rowNode = xmlDoc.CreateElement(root.FirstChild.Name);
                        root.AppendChild(rowNode);
                    }
                }

                if (XmlTableEditor.IsXml(root.FirstChild.InnerXml))
                {
                    for (int col = 0; col < data.Columns.Count; col++)
                    {
                        var cell = data.GetRow(XmlTableEditor.mainTable.gridView.GetRowIndex(row))[col].ToString();

                        var name = data.Columns[col].ColumnName;
                        if (name == DataTableExtend.IndexCol)
                        {
                            continue;
                        }
                        var cellNode = rowNode.SelectSingleNode(name);
                        if (cellNode != null)
                        {
                            cellNode.InnerXml = cell;
                        }
                        else
                        {
                            var node = xmlDoc.CreateElement(data.Columns[col].ColumnName);
                            node.InnerXml = cell;

                            rowNode.AppendChild(node);
                        }
                        if (string.IsNullOrEmpty(cell) && cellNode != null)
                        {
                            rowNode.RemoveChild(cellNode);
                        }
                    }
                }
                else
                {
                    //  MessageBox.Show(gridType.ToString());

                    if (gridType == GridType.row && data.Columns.Count > 2)
                    {
                        gridType = GridType.col;
                    }
                    if (gridType == GridType.row)
                    {
                        rowNode.InnerXml = data.Rows[row][0].ToString();
                    }
                    else if (gridType == GridType.col)
                    {
                        for (int col = 0; col < data.Columns.Count; col++)
                        {
                            var cell = data.GetRow(XmlTableEditor.mainTable.gridView.GetRowIndex(row))[col].ToString();
                            if (string.IsNullOrEmpty(cell))
                            {
                                continue;
                            }
                            var name = data.Columns[col].ColumnName;
                            if (name == DataTableExtend.IndexCol)
                            {
                                continue;
                            }
                            var cellNode = root.SelectSingleNode(name);
                            if (cellNode != null)
                            {
                                cellNode.InnerXml = cell;
                            }
                            else
                            {
                                var node = xmlDoc.CreateElement(data.Columns[col].ColumnName);
                                node.InnerXml = cell;

                                root.AppendChild(node);
                            }
                        }
                    }
                    // var info = data.Rows[row][0].ToString();
                }
                if (string.IsNullOrWhiteSpace(rowNode.InnerText))
                {
                    removeList.Add(rowNode);
                }
            }
            foreach (var node in removeList)
            {
                root.RemoveChild(node);
            }
            return(root);
        }
Exemple #4
0
        public static void Pause(string copyData, DataGridView tableView)
        {
            CopyData data = null;

            try
            {
                data = FileManager.Deserialize <CopyData>(copyData);
            }
            catch (Exception)
            {
                return;
            }
            var cells = tableView.SelectedCells;
            List <DataGridViewCell> ignoreList = new List <DataGridViewCell>();

            for (int i = cells.Count - 1; i >= 0; i--)
            {
                var cell = cells[i];
                if (ignoreList.Contains(cell))
                {
                    continue;
                }

                foreach (var cellData in data.cellList)
                {
                    //tableView[cell.RowIndex + cellData.row, cell.ColumnIndex + cellData.col];
                    try
                    {
                        DataGridViewCell offsetCell = tableView[cell.ColumnIndex + cellData.col, cell.RowIndex + cellData.row];
                        if (offsetCell.OwningColumn.Name == DataTableExtend.IndexCol)
                        {
                            continue;
                        }
                        if (offsetCell.RowIndex >= tableView.Rows.Count - 1)
                        {
                            continue;
                        }
                        var intValue = 0;
                        if (string.IsNullOrWhiteSpace(cellData.value))
                        {
                            offsetCell.Value = DBNull.Value;
                        }
                        else
                        {
                            if (offsetCell.ValueType == typeof(int))
                            {
                                if (int.TryParse(cellData.value, out intValue))
                                {
                                    offsetCell.Value = intValue;
                                }
                                //else
                                //{
                                //    try
                                //    {
                                //        offsetCell.Value = cellData.value;
                                //    }
                                //    catch (Exception)
                                //    {
                                //    }

                                //}
                            }
                            else
                            {
                                offsetCell.Value = cellData.value;
                            }
                        }

                        ignoreList.Add(offsetCell);
                        offsetCell.ReadOnly = XmlTableEditor.IsXml(offsetCell.Value.ToString());
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
        }