public void CreateNew(string modeName = "")
 {
     DataWorkingState = WorkingStateEnum.Creating;
     if (RegulationTables.Contains(this.TableName))
     {
         RegulationFrom rf = new RegulationFrom()
         {
             Text = this.TableName, TableName = this.TableName, EditEnable = true, CurrentFieldTable = DBHelper.GetDBHelper().GetTableFields(this.TableName)
         };
         if (rf.ShowDialog() == DialogResult.OK)
         {
             DataSource = DBHelper.GetDBHelper().GetDataFromTable(0, 0, this.TableName, "");
         }
         this.DataWorkingState = WorkingStateEnum.Search;
     }
     else
     {
         NewDataForm ndf = new NewDataForm()
         {
             TableModeName = modeName, TableName = this.TableName
         };
         if (ndf.CreateFromFieldTable(DBHelper.GetDBHelper().GetTableFields(this.TableName), WorkingStateEnum.Creating, false))
         {
             if (ndf.ShowDialog() == DialogResult.OK)
             {
                 this.DataSource = DBHelper.GetDBHelper().GetDataFromTable(0, 0, this.TableName, "");
             }
             ;
         }
         this.DataWorkingState = WorkingStateEnum.Search;
     }
 }
Exemple #2
0
        /// <summary>
        /// Creates a new World entity, opens an edit form and lets the user enter data.
        /// If ok is selected then the new data is inserted into the Mapinfo table.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewButton_Click(object sender, EventArgs e)
        {
            // Create a new World entity, when you create a new entity it will
            // have a rowid of 0 which means the entity is not inserted into a table.
            World newData = new World();

            //Show the edit form and pass in the new world object.
            NewDataForm form = new NewDataForm();

            NewDataForm.AddResult result = form.Show(newData);

            if (result != null)
            {
                try
                {
                    // Insert the new record into the world table.
                    worldTable.InsertRow(result.EditedData);
                }
                catch (MapinfoException mapinfoex)
                {
                    if (mapinfoex.MapinfoErrorCode == 1448)
                    {
                        ShowMessage(
                            @"Sorry something else is already editing this table.
                                      Check to see if crashed Mapinfo ar running in the background.");
                        return;
                    }
                    throw;
                }
            }
        }
        public void CreateFromField(IFieldTable table, DataGridViewRow row, WorkingStateEnum workingState, bool uploadFile)
        {
            var file = Directory.GetFiles("RDLC").Where(f => this.TemplateName.Equals(Path.GetFileNameWithoutExtension(f))).FirstOrDefault();

            if (workingState == WorkingStateEnum.View && file != null)
            {
                ViewDataForm ndf = new ViewDataForm(file);
                if (ndf.CreateFromFieldTable(table, WorkingStateEnum.View, false))
                {
                    ndf.TableName = table.TableName;
                    if (ndf.ShowDialog() == DialogResult.OK)
                    {
                        DataSource = DBHelper.GetDBHelper().GetDataFromTable(0, 0, TemplateName, "");
                    }
                }
            }

            else if (row != null && RegulationTables.Contains(this.TableName))
            {
                string fileName = "";
                foreach (DataGridViewColumn col in row.DataGridView.Columns)
                {
                    if (col.HeaderText.Contains("名称"))
                    {
                        fileName = row.Cells[col.Name].Value.ToString();
                    }
                }
                if (fileName == "")
                {
                    fileName = this.TableName + row.Cells["ID"].Value.ToString();
                }

                Byte[]         bytes  = DBHelper.GetDBHelper().GetDocFromTableRecordBytes(this.TableName, row.Cells["ID"].Value.ToString(), fileName);
                MemoryStream   stream = new MemoryStream(bytes);
                RegulationFrom rf     = new RegulationFrom()
                {
                    Text = this.TableName, TableName = this.TableName, EditEnable = false, RegulationFileStream = stream, CurrentFieldTable = table
                };
                rf.ShowDialog();
            }
            else
            {
                NewDataForm ndf = new NewDataForm()
                {
                    TableName = this.TableName, TableModeName = this.TableModeName
                };
                if (ndf.CreateFromFieldTable(table, workingState, uploadFile))
                {
                    ndf.TableName = table.TableName;
                    if (ndf.ShowDialog() == DialogResult.OK)
                    {
                        DataSource = DBHelper.GetDBHelper().GetDataFromTable(0, 0, TableName, "");
                    }
                }
            }
        }