private void Button_import_Click(object sender, EventArgs e) { Helper.HelperResult res = Helper.ImportProperties(swApp, ((Form1)this.Owner).bindingSource_swSettings, path, comboBox_config.SelectedItem.ToString() ); this.Close(); }
private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (swApp != null) { dialog.InitialDirectory = swApp.GetCurrentWorkingDirectory(); } dialog.Filter = "Solidworks (*.sldprt;*.sldasm;*.slddrw)|*.sldprt;*.sldasm;*.slddrw|Parts (*.sldprt)|*.sldprt|Assemblies (*.sldasm)|*.sldasm|Drawings (*.slddrw)|*.slddrw|All files (*.*)|*.*"; dialog.Multiselect = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Helper.HelperResult err = Helper.HelperResult.UNKNOWN; string[] files = dialog.FileNames; if (files.Any()) { err = Helper.AddFiles(bindingSource_swFolder, files); } //if (!String.IsNullOrEmpty(file)) //err = Helper.AddFile(bindingSource_swFolder, file); switch (err) { case Helper.HelperResult.SUCCESS: break; case Helper.HelperResult.UNKNOWN: MessageBox.Show("Unknown error"); break; case Helper.HelperResult.NO_FILES: MessageBox.Show("No cad data"); break; default: MessageBox.Show("Unknown error"); break; } } }
//files table private void addFolderToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = false; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { string folder = dialog.SelectedPath; Helper.HelperResult err = Helper.AddFolder(bindingSource_swFolder, folder); if (err != Helper.HelperResult.SUCCESS) { MessageBox.Show("Wrong folder"); } } }
private void dataGridView_swFolder_DragDrop(object sender, DragEventArgs e) { // still check if the associated data from the file(s) can be used for this purpose if (e.Data.GetDataPresent(DataFormats.FileDrop)) { Helper.HelperResult err = Helper.HelperResult.UNKNOWN; // Fetch the file(s) names with full path here to be processed string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Any()) { err = Helper.AddFiles(bindingSource_swFolder, files); } //if (!String.IsNullOrEmpty(file)) //err = Helper.AddFile(bindingSource_swFolder, file); switch (err) { case Helper.HelperResult.SUCCESS: break; case Helper.HelperResult.UNKNOWN: MessageBox.Show("Unknown error"); break; case Helper.HelperResult.NO_FILES: MessageBox.Show("No cad data"); break; default: MessageBox.Show("Unknown error"); break; } // Your desired code goes here to process the file(s) being dropped } }
//settings table private void openPropertiesToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "XML|*.xml"; dialog.Multiselect = false; if (dialog.ShowDialog() != DialogResult.OK) { return; } Helper.HelperResult ret = Helper.OpenProperty(bindingSource_swSettings, dialog.FileName); if (ret != Helper.HelperResult.SUCCESS) { MessageBox.Show("Fail to open file, or file has wrong format."); } else { pathToSettings = dialog.FileName; } }
private async void importItem_main_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; if (dialog.ShowDialog() != DialogResult.OK) { return; } string path = dialog.FileName; if (!File.Exists(path)) { return; } if (swApp == null) { toolStripStatusLabel_status.Text = "Lunch SolidWorks. Please wait"; } this.Enabled = false; Form f = new LoadForm(); f.StartPosition = FormStartPosition.CenterParent; f.Show(this); int timeout = 10000; Task <SldWorks> task = SolidworksSingleton.GetSwAppAsync(); //swApp = await SolidworksSingleton.GetSwAppAsync(); if (await Task.WhenAny(task, Task.Delay(timeout)) == task) { swApp = await task; } else { f.Close(); this.Enabled = true; MessageBox.Show("Time out"); return; } Helper.HelperResult res = Helper.ImportProperties(swApp, bindingSource_swSettings, path); if (res != Helper.HelperResult.SUCCESS) { toolStripStatusLabel_status.Text = "Fail to import"; } else { toolStripStatusLabel_status.Text = "Ready!"; } f.Close(); this.Enabled = true; //throw new NotImplementedException(); }
//buttons private async void button_start_Click(object sender, EventArgs e) { setEnableUiTools(false); //check tables if (bindingSource_swSettings.Count == 0) { MessageBox.Show("Setting table is empty!\n Please add settings before you press start"); setEnableUiTools(true); return; } if (bindingSource_swFolder.Count == 0) { MessageBox.Show("File table is empty!\n Please add file before you press start"); setEnableUiTools(true); return; } BindingList <FileObj> fileList = (BindingList <FileObj>)bindingSource_swFolder.DataSource; if (fileList.Count == 0) { MessageBox.Show("Fail to read from table!"); return; } if (swApp == null) { toolStripStatusLabel_status.Text = "Lunch SolidWorks..."; } swApp = await SolidworksSingleton.GetSwAppAsync(); //swApp.Visible = false; if (swApp == null) { MessageBox.Show("Fail to start Solid Works"); } else { toolStripStatusLabel_status.Text = "SolidWorks started!"; } BindingList <PropertyObject> prop_list = (BindingList <PropertyObject>)bindingSource_swSettings.DataSource; if (prop_list.Count == 0) { MessageBox.Show("Fail to read from settings"); return; } toolStripProgressBar1.Maximum = fileList.Count; toolStripProgressBar1.Value = 0; //run process method try { cancelSource = new CancellationTokenSource(); foreach (FileObj file in fileList) { processModelAsyncTask = ProcessModelAsync(cancelSource.Token, file); Helper.HelperResult res = await processModelAsyncTask; Console.WriteLine("Res {0}", res); toolStripProgressBar1.Value += 1; toolStripStatusLabel_status.Text = file.Name; //if(res == Helper.HelperResult.CANCELED) //{ // toolStripStatusLabel_status.Text = "Canceled"; // break; //} } toolStripStatusLabel_status.Text = "Done"; } catch (Exception ex) { toolStripStatusLabel_status.Text = ex.Message; } processModelAsyncTask = null; setEnableUiTools(true); }
private void Form1_Load(object sender, EventArgs e) { bindingSource_swSettings.DataSource = new BindingList <PropertyObject>(); bindingSource_swFolder.DataSource = new BindingList <FileObj>(); //bindingSource_swSettings.AddingNew = new PropertyObject(); DataGridViewColumn column; // = new DataGridViewTextBoxColumn(); //dataGridView for folder dataGridView_swFolder.AutoGenerateColumns = false; dataGridView_swFolder.AutoSize = true; //dataGridView_swFolder.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; //column Name column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Name"; column.Name = "Name"; column.ReadOnly = true; column.ToolTipText = " File name"; column.Width = 200; //column.DefaultCellStyle.Format = "0.0"; dataGridView_swFolder.Columns.Add(column); //Column Note column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Note"; column.Name = "Note"; column.ReadOnly = true; column.ToolTipText = "Information about process"; dataGridView_swFolder.Columns.Add(column); //* //dataGrid for settings dataGridView_swSettings.AutoGenerateColumns = false; dataGridView_swSettings.AutoSize = false; //column propertiName column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "FieldName"; column.Name = "Property name"; column.ToolTipText = "Property for add to files"; column.MinimumWidth = 100; dataGridView_swSettings.Columns.Add(column); //column enum dataGridView_swSettings.Columns.Add(CreateComboBoxWithEnums()); //column value column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Value"; column.Name = "Value / Text expression"; column.ToolTipText = "Properti for add to files"; column.MinimumWidth = 150; dataGridView_swSettings.Columns.Add(column); //bindingSource_swSettings.Add(PropertyObjectsList); //bindingSource_swSettings.DataSource = list; //*/ setEnableUiTools(true); pathToSettings = Properties.Settings.Default.PathToLustProperties; if (File.Exists(pathToSettings)) { Helper.HelperResult ret = Helper.OpenProperty(bindingSource_swSettings, pathToSettings); if (ret != Helper.HelperResult.SUCCESS) { MessageBox.Show("Fail to open file" + pathToSettings); } } else { pathToSettings = ""; } toolStripButtonOpenProperties.Image = IconExtractor.Extract("shell32.dll", 279, true).ToBitmap(); toolStripButtonSaveProperties.Image = IconExtractor.Extract("shell32.dll", 258, true).ToBitmap(); toolStripButtonSavePropertiesAs.Image = IconExtractor.Extract("shell32.dll", 6, true).ToBitmap(); toolStripButtonClearProperties.Image = IconExtractor.Extract("shell32.dll", 31, true).ToBitmap(); toolStripButtonAddFile.Image = IconExtractor.Extract("shell32.dll", 279, true).ToBitmap(); toolStripButtonAddFolder.Image = IconExtractor.Extract("shell32.dll", 278, true).ToBitmap(); toolStripButtonClearFileTable.Image = IconExtractor.Extract("shell32.dll", 31, true).ToBitmap(); toolStripSplitButton_import.Image = IconExtractor.Extract("shell32.dll", 146, true).ToBitmap(); toolStripComboBox_addTo.Items.Add("All"); toolStripComboBox_addTo.Items.Add("Main"); toolStripComboBox_addTo.Items.Add("Config"); toolStripComboBox_addTo.SelectedIndex = Properties.Settings.Default.LustPropertiPreset; splitContainer1.SplitterDistance = splitContainer1.Size.Width / 2; }