/// <summary> /// Check if the droped files are products and load them if they are /// </summary> void CommandForm_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string s in files) { try { filesystem.FileFormat_t file = new filesystem.FileFormat_t(); file = filesystem.getDataFromFile(s); if (cbxOutletSide.SelectedIndex != 0 && cbxOutletSide.SelectedIndex != 1) { cbxOutletSide.SelectedIndex = 0; } file.packet.message.parameter = (ushort)cbxOutletSide.SelectedIndex; if (!file.id.Contains("product_")) { file.id = "product_" + file.id; } filesystem.saveToFile(file.packet, file.name, file.id); nmbrOfCustomButtons++; ParamButton dpb = new ParamButton(new ProductParameter_t(file.packet), OnButtonClick, file.name, file.id); dpb.parameter = file.packet.message.parameter; flowProductButtons.Controls.Add(dpb); } catch { } } } }
/// <summary> /// Completes missing data bytes with the default bytes for this product type and saves the file. /// </summary> private filesystem.FileFormat_t CompleteDataOfFile(filesystem.FileFormat_t file) { if (file.packet.data.Length < 30) { if (file.packet.data.Length >= 1) { int oldLength = file.packet.data.Length; byte[] defaultData = defaultProductParams[file.packet.data[0]].ToArrayApi(); Array.Resize(ref file.packet.data, defaultData.Length); Array.Copy(defaultData, oldLength, file.packet.data, oldLength, defaultData.Length - oldLength); file.packet.dataLength = (ushort)file.packet.data.Length; } else { file.packet.data = defaultProductParams[0].ToArrayApi(); file.packet.dataLength = (ushort)file.packet.data.Length; } filesystem.saveToFile(file.packet, file.name, file.id); } return(file); }
/// <summary> /// Create a new product button and saves it /// </summary> private void btnCreate_Click(object sender, EventArgs e) { ParamButton button = new ParamButton(new ProductParameter_t(), OnButtonClick, "", ""); filesystem.FileFormat_t file = new filesystem.FileFormat_t(); foreach (ParamButton pb in flowProductButtons.Controls) { // when the save name is the same as the name of the selected button overwrite it // usevisualstylebackcolor is used as an indicator of the clicked state if (pb.ProductParams.prodName == txtSaveName.Text && pb.UseVisualStyleBackColor == false) { button = pb; flowProductButtons.Controls.Remove(pb); } } controlsToParams(); if (button.id == "") { if (txtSaveName.Text != "") { file.name = txtSaveName.Text; } else { file.name = "Custom " + nmbrOfCustomButtons; } file.id = "custom" + nmbrOfCustomButtons; controlsToParams(); file.packet = new SerialComm.Packet_t(); file.packet.data = ProductParams.ToArrayApi(); file.packet.dataLength = (ushort)file.packet.data.Length; nmbrOfCustomButtons++; } else { file.id = button.id; file.name = txtSaveName.Text; file.packet.data = ProductParams.ToArrayApi(); file.packet.dataLength = (ushort)file.packet.data.Length; } if (cbxOutletSide.SelectedIndex != 0 && cbxOutletSide.SelectedIndex != 1) { cbxOutletSide.SelectedIndex = 0; } file.packet.message.parameter = (ushort)cbxOutletSide.SelectedIndex; if (!file.id.Contains("product_")) { file.id = "product_" + file.id; } filesystem.saveToFile(file.packet, file.name, file.id); ParamButton dpb = new ParamButton(new ProductParameter_t(file.packet), OnButtonClick, file.name, file.id); flowProductButtons.Controls.Add(dpb); }