Exemple #1
0
        public void SaveTable()
        {
            if (!IsTableOpened)
            {
                return;
            }

            DataTable rows = EditingTable.GetChanges();

            if (rows == null)
            {
                return;
            }
            BdatMember[] members = CurrentTable.Members;

            foreach (DataRow row in rows.Rows.Cast <DataRow>())
            {
                int itemId = int.Parse((string)row.ItemArray[0]);
                for (int m = 0; m < members.Length; m++)
                {
                    if (members[m].Type != BdatMemberType.Scalar)
                    {
                        continue;
                    }
                    string value = (string)row.ItemArray[m + 1];
                    try
                    {
                        CurrentTable.WriteValue(itemId, members[m].Name, value);
                    }
                    catch (Exception ex)
                    {
                        string caption = null;
                        if (ex is ArgumentOutOfRangeException)
                        {
                            caption = "Replacement string was too large to fit in the original space.";
                        }

                        if (ex is FormatException || ex is OverflowException)
                        {
                            caption = $"Error parsing \"{value}\" as a {members[m].ValType} " +
                                      $"from Item \"{itemId}\" Column \"{members[m].Name}\".";
                        }

                        if (caption == null)
                        {
                            throw;
                        }

                        MessageBox.Show(caption, "Format Error");
                    }
                }
            }

            File.WriteAllBytes(Filename, BdatTables.FileData);

            EditingTable.AcceptChanges();
        }