E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un...

123
358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS, COMPONENTE Y PRODUCTOS using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; using System.Data.OleDb; using System.IO; namespace MRProgram_00 { public partial class Form4 : Form { Functions.Operatives F = new Operatives(); bool Expanded = false; public bool Edition = false; string Image_path = ""; //VARIABLES PARA EL ARBOL DE PRODUCTOS public bool Show_Tree_button = false; TreeNode Node; ArrayList Images_Names = new ArrayList(); ImageList imageList1 = new ImageList(); Dictionary<string, string> MP_req = new Dictionary<string,string>(); Dictionary<string, int> Img_list_n_Indx = new Dictionary<string, int>(); bool Its_possible = true; //VARIABLES PARA EDITAR LOS VALORES public string Indx_on_table = ""; public string Nombre = ""; public string Referencia = ""; public string Imagen; public string Inventario_inicial = ""; public string Unidad = "";

Transcript of E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un...

Page 1: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE

MATERIAS PRIMAS, COMPONENTE Y PRODUCTOS

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; using System.Data.OleDb; using System.IO; namespace MRProgram_00 { public partial class Form4 : Form { Functions.Operatives F = new Operatives(); bool Expanded = false; public bool Edition = false; string Image_path = ""; //VARIABLES PARA EL ARBOL DE PRODUCTOS public bool Show_Tree_button = false; TreeNode Node; ArrayList Images_Names = new ArrayList(); ImageList imageList1 = new ImageList(); Dictionary<string, string> MP_req = new Dictionary<string,string>(); Dictionary<string, int> Img_list_n_Indx = new Dictionary<string, int>(); bool Its_possible = true; //VARIABLES PARA EDITAR LOS VALORES public string Indx_on_table = ""; public string Nombre = ""; public string Referencia = ""; public string Imagen; public string Inventario_inicial = ""; public string Unidad = "";

Page 2: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 359

public string Lead_time = ""; public string Costo_pedir = ""; public string Costo_almacenar = ""; public string Demand_anual = ""; public string Taman_predet_lote = ""; //public string Security_stock = ""; public string Batch_policy = ""; //MANEJADOR DE EVENTOS PARA ENVIAR A OTRO FORM EL EVENTO DE CIERRE public delegate void UpdateHandler3(object sender, UpdateEventArgs3 e); public event UpdateHandler3 IdentityUpdated3; //VARIABLES PARA EL FORM PARA CREAR Subensamble Form Create_Subassembly = new Form(); public TextBox Text1 = new TextBox(); Button Button_01 = new Button(); Button Button_02 = new Button(); private void Create_the_new_subassembly_form() { //CREA UN FORM PARA QUE EL USUARIO INTRODUZCA EL NOMBRE DEL SUBENSAMBLE try { Text1.Size = new Size(170, 20); Text1.Top = 10; Text1.Left = 10; Button_01.Size = new Size(60, 20); Button_01.Top = 35; Button_01.Left = 60; Button_01.Text = "Crear"; Button_01.Click += new System.EventHandler(this.Button_01_Click); Button_02.Size = new Size(60, 20); Button_02.Top = 35; Button_02.Left = 120; Button_02.Text = "Cancel"; Button_02.Click += new System.EventHandler(this.Button_02_Click); Create_Subassembly.Size = new Size(200, 90); Create_Subassembly.Text = "Nuevo Subensamble"; Create_Subassembly.FormBorderStyle = FormBorderStyle.FixedToolWindow;

Page 3: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

360 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

Create_Subassembly.StartPosition = FormStartPosition.CenterParent; Create_Subassembly.Controls.Add(Button_01); Create_Subassembly.Controls.Add(Button_02); Create_Subassembly.Controls.Add(Text1); Create_Subassembly.Disposed += new EventHandler(form_Disposed); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Create_the_new_collection_form"); } } void form_Disposed(object sender, EventArgs e) { // CIERRA EL FORM PARA CREAR UNA NUEVA UNIDAD try { Create_Subassembly = null; } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Boton cerrar"); } } private void Button_01_Click(object sender, EventArgs e) { // CREA UN NUEVO SUBENSAMBLE try { F.Identify_folders(); //CHECK THE FOLDERS FOR THE PROGRAM AND CREATE THE MISSING ONES. ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Subensambles"; string Nombre_Subensamble = Text1.Text; //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("Nombre_Subensamble"); Values.Clear();

Page 4: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 361

Values.Add(Nombre_Subensamble); bool Exist_on_Subensambles = F.Exist_row_on_Access_Table(Form1.Current_MRP, "Subensambles", Columns, Values); //MessageBox.Show(Exist_on_Subensambles.ToString()); Columns.Clear(); Columns.Add("Index"); Columns.Add(Table_name); Columns.Add("Arboles_subensambles"); Values.Clear(); Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name).ToString()); //Obtiene el numero de productos en la tabla //MessageBox.Show(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name).ToString()); Values.Add(Nombre_Subensamble); //CREATE AT LEAST THE MAIN NODE IF DOESN´T EXIST TREE INFO if (Show_Tree_button == true) { //F.Save_tree_to_file(treeView1, F.Functions_folder + "\\" + "Tree_info_00.txt"); Values.Add("oledb object"); } if (Exist_on_Subensambles == false) { //FIRST SAVE THE SUBENSAMBLE TREE INFO if (Show_Tree_button == true) { F.Save_tree_to_file(treeView2, F.Functions_folder + "\\" + "Tree_info_01.txt"); } int Success = F.AddDataToTable_sub(Form1.Current_MRP, Table_name, Columns, Values); if (Success == 1) { MessageBox.Show("Subensamble guardado satisfactoriamente"); Fill_MP_list(); Create_Subassembly.Hide(); } else {

Page 5: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

362 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

MessageBox.Show("No se guardo el subensamble"); } } else { if (Edition == true) //Si esta en modo de edicion { F.DeleteDataToAccessTable(Form1.Current_MRP, Table_name, Indx_on_table); //FIRST SAVE THE PRODUCT TREE INFO if (Show_Tree_button == true) { F.Save_tree_to_file(treeView2, F.Functions_folder + "\\" + "Tree_info_01.txt"); } int Success = F.AddDataToTable_sub(Form1.Current_MRP, Table_name, Columns, Values); if (Success == 1) { MessageBox.Show("Subensamble guardado satisfactoriamente"); Fill_MP_list(); Create_Subassembly.Hide(); } else { MessageBox.Show("No se guardo el subensamble"); } //F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Indx_on_table); //EDITA LOS DATOS DE LA MP O PRODUCTO } else // Si no esta en modo de edicion { string Message = "Ya existe "; if (Exist_on_Subensambles == true) { Message = Message + "un Subensamble, "; } Message = Message + "con el mismo nombre o referencia. Cambie de nombre o referencia. "; MessageBox.Show(Message); } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando un SUBENSAMBLE"); }

Page 6: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 363

} private void Button_02_Click(object sender, EventArgs e) { // CIERRA EL FORM PARA CREAR UNA NUEVA UNIDAD try { Create_Subassembly.Hide(); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando un SUBENSAMBLE -> Boton cancelar"); } } public Form4() { F.Identify_folders(); InitializeComponent(); } private void Fill_units_list() { try { DataTable Table = F.Get_table_from_Access_File(Form1.Current_MRP, "Unidades"); //ArrayList Categorias = new ArrayList(); ArrayList Unidades = new ArrayList(); for (int i = 0; i < Table.Rows.Count; i++) { //string Categoria = Table.Rows[i][1].ToString(); string Unidad = Table.Rows[i][2].ToString(); if (!Unidades.Contains(Unidad)) { Unidades.Add(Unidad); //Obtiene la lista de las diferentes categorias para las Unidades } } comboBox1.Items.Clear(); foreach (string Unit in Unidades) { comboBox1.Items.Add(Unit); //LLENA EL COMBOBOX1 CON LA LISTA DE TODAS LAS UNIDADES UNIDADES } } catch (Exception Error)

Page 7: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

364 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ F.Show_Error_Message(Error.ToString(), "Fill_units_list"); } } private void Fill_images_list_from_table(string Table_name) { try { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int count = table.Rows.Count; for (int i = 0; i < count; i++) { //MessageBox.Show(table.Rows[i][1].ToString()); int Indx = Convert.ToInt32(table.Rows[i][0].ToString()); string key_name = table.Rows[i][1].ToString(); Img_list_n_Indx.Add(key_name, Indx); Images_Names.Add(table.Rows[i][1].ToString()); imageList1.Images.Add(F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", Indx)); } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Llenando lista de imagenes"); } } private void Form4_Load(object sender, EventArgs e) { try { //Crear el form usado para introducir el nombre de un subensamble Create_the_new_subassembly_form(); this.Size = new Size(265, 526); //HIDE MISSING DATA INDICATORS pictureBox2.Hide(); pictureBox3.Hide(); pictureBox4.Hide(); pictureBox5.Hide();

Page 8: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 365

pictureBox6.Hide(); pictureBox7.Hide(); pictureBox8.Hide(); pictureBox9.Hide(); if (Show_Tree_button == false) { toolStripButton3.Visible = false; this.Text = "Nuevo Material (MP/PP)"; } else { toolStripButton3.Visible = true; this.Text = "Nuevo Producto"; } //Seleccionar politica de lote comboBox2.SelectedIndex = 0; Fill_units_list(); if (Edition == true) // Llenar los campos de datos si se trata de editar datos { textBox1.Text = Nombre; textBox2.Text = Referencia; pictureBox1.Image = Image.FromFile(Imagen); Image_path = F.Functions_folder + "\\" + "Temp_image.png"; //MessageBox.Show(Imagen); //SELECCIONA EL INDEX DE LA UNIDAD REQUERIDA int Indx = comboBox1.Items.IndexOf(Unidad); comboBox1.SelectedIndex = Indx; textBox3.Text = Inventario_inicial; textBox4.Text = Lead_time; textBox5.Text = Costo_pedir; textBox6.Text = Costo_almacenar; textBox9.Text = Demand_anual; textBox10.Text = Taman_predet_lote; //textBox12.Text = Security_stock; comboBox2.SelectedIndex = comboBox2.Items.IndexOf(Batch_policy); textBox1.ReadOnly = true; textBox2.ReadOnly = true; if(Show_Tree_button == true) { Images_Names.Clear(); Img_list_n_Indx.Clear(); Fill_images_list_from_table("MP"); Fill_images_list_from_table("Productos");

Page 9: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

366 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

F.Get_file_from_database(Form1.Current_MRP, "Productos", "Arbol_de_producto", "Index", Indx_on_table); treeView1.ImageList = imageList1; foreach (TreeNode node in F.Load_tree_from_file(F.Functions_folder + "\\" + "Tree_info_00.txt")) { //MessageBox.Show(Node.Text.ToString()); string node_name = node.Text; node.ImageIndex = Images_Names.IndexOf(node_name); TreeView tree = treeView1; tree.Nodes.Add(node); } //HACE UN RECORRIDO A TRAVES DEL TREEVIEW2 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView1, false); //CALCULAR REQUERIMIENTOS DE COMPONENTES MP_req.Clear(); Calculate_quantity_requierements(); treeView1.ExpandAll(); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Cargando la informacion al Iniciar la ventana de MP"); } } private void ButtonClicked(object sender, UpdateEventArgs e) { try { //MessageBox.Show(e.Image_path); this.BringToFront(); pictureBox1.Image = Image.FromFile(e.Image_path); Image_path = e.Image_path; //textBox1.Text = e.mFirstName + " _ " + e.mMiddleName; } catch (Exception Error) {

Page 10: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 367

F.Show_Error_Message(Error.Message, "ButtonClicked"); } } private void Fill_MP_list() { // LLENA EL LISTVIEW1 CON LAS IMAGENES EN MINIATURA QUE ESTAN EN LA COLECCION SELECCIONADA EN EL LISTBOX1 try { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, "MP"); listBox1.Items.Clear(); for (int i = 0; i < table.Rows.Count; i++) { string file = table.Rows[i][1].ToString(); listBox1.Items.Add(file.ToString()); } table = F.Get_table_from_Access_File(Form1.Current_MRP, "Subensambles"); listBox2.Items.Clear(); for (int i = 0; i < table.Rows.Count; i++) { string file = table.Rows[i][1].ToString(); listBox2.Items.Add(file.ToString()); //MessageBox.Show(file.ToString()); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Show_selected_collection_images"); } } private void Add_main_Node() { try { // GET IMAGE Image Prev_01 = pictureBox1.Image; int Index = this.Images_Names.IndexOf(textBox1.Text); if (Index < 0) { this.imageList1.Images.Add(Prev_01); this.Images_Names.Add(textBox1.Text); }

Page 11: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

368 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

Index = this.Images_Names.IndexOf(textBox1.Text); treeView1.ImageList = imageList1; if (Edition == false) //SI NO SE ESTAN CARGANDO OTROS NODOS AÑADIR UN NODO PRIMARIO { Node = new TreeNode(textBox1.Text, Index, Index); treeView1.Nodes.Add(Node); treeView1.SelectedNode = Node; treeView1.SelectedNode.Expand(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Add_main_Node"); } } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX3 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox3"); } } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX4 try {

Page 12: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 369

if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox4.Text) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox4"); } } private void textBox5_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX1 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox5.Text) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox5"); } } private void textBox6_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX6 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox6.Text) == true) { e.Handled = true; } }

Page 13: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

370 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox6"); } } private void ButtonClicked2(object sender, UpdateEventArgs2 e) { try { this.BringToFront(); Fill_units_list(); textBox3.Text = e.Value; int indx = comboBox1.Items.IndexOf(e.Unit_to_send); comboBox1.SelectedIndex = indx; } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "ButtonClicked2"); } } private void Calculate_requierements(TreeNode treeNode) { try { //MessageBox.Show("¬: " + treeNode.Text+" Factor:-> "+Read_cant(treeNode.Text)); foreach (TreeNode tn in treeNode.Nodes) { string node_name = F.Read_name(tn.Text); if (MP_req.ContainsKey(node_name) == true) { int Prev_qnty = Convert.ToInt32(MP_req[node_name].ToString()); int New_qnty = Prev_qnty + F.Calculate_Quantity(tn.FullPath.ToString()); MP_req[node_name] = New_qnty.ToString(); //MessageBox.Show(node_name + "->> " + New_qnty); } else { MP_req.Add(F.Read_name(tn.Text), F.Calculate_Quantity(tn.FullPath.ToString()).ToString());

Page 14: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 371

} //MessageBox.Show("¬: " + tn.Text + " Path:-> " + Calculate_Quantity(tn.FullPath.ToString())); //MessageBox.Show("¬: " + treeNode.Text + " Factor:-> " + Read_cant(treeNode.Text) +"||" + "node: " + tn.Text + " total:-> " + total); } foreach (TreeNode tn in treeNode.Nodes) { Calculate_requierements(tn); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Calculate_requierements"); } } private void Refresh_tree_images(TreeNode treeNode) { try { string node_name = F.Read_name(treeNode.Text); int Index = Images_Names.IndexOf(node_name); treeNode.ImageIndex = Index; treeNode.SelectedImageIndex = Index; foreach (TreeNode tn in treeNode.Nodes) { Refresh_tree_images(tn); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Refresh_tree_images"); } } private void Through_nodes(TreeView treeView, bool Calculate_quantity) // if is true: Calculate_quantity else: Refresh_tree_images { try { TreeNodeCollection nodes = treeView.Nodes;

Page 15: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

372 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (Calculate_quantity == true) { foreach (TreeNode n in nodes) { Calculate_requierements(n); } } else { foreach (TreeNode n in nodes) { Refresh_tree_images(n); } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Through_nodes"); } } private void Calculate_quantity_requierements() { try { //HACE UN RECORRIDO A TRAVES DEL TREEVIEW PARA CALCULAR LOS REQUERIMIENTOS DE MP Through_nodes(treeView1, true); DataTable table = new DataTable(); table.Columns.Add("MP"); table.Columns.Add("CANTIDAD"); //LLENA EL DATAGRIDVIEW1 CON LOS DATOS DE REQUERIMIENTOS DE MP foreach (KeyValuePair<string, string> pair in MP_req) { DataRow row = table.NewRow(); row["MP"] = pair.Key.ToString(); row["CANTIDAD"] = pair.Value.ToString(); table.Rows.Add(row); //MessageBox.Show("Key_ " + pair.Key.ToString() + "val_" + pair.Value.ToString()); } dataGridView1.DataSource = table; } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Calculate_quantity_requierements"); } } private void Copiar_nodos(TreeNode Selected_node, TreeNode New_node) { try

Page 16: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 373

{ foreach (TreeNode Node in Selected_node.Nodes) { TreeNode Temp = new TreeNode(Node.Text); New_node.Nodes.Add(Temp); Copiar_nodos(Node, Temp); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Copiar_nodos"); } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { try { // CREATE REAL TREE NODES textBox7.Text = this.treeView1.SelectedNode.FullPath.ToString(); treeView2.Nodes.Clear(); TreeNode Selected_node = treeView1.SelectedNode; TreeNode New_node = new TreeNode(Selected_node.Text); //COPIAR LA RAMA SELECCIONADA DEL ARBOL DE PRODUCTO Copiar_nodos(Selected_node, New_node); //paste the node from the copied nodes treeView2.Nodes.Add(New_node); //treeView2.Nodes.Clear(); treeView2.ImageList = imageList1; ////HACE UN RECORRIDO A TRAVES DEL TREEVIEW2 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView2, false); treeView2.ExpandAll(); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Leyendo cantidad"); } }

Page 17: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

374 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

private void textBox8_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX8 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox2"); } } private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e) { try { Image Img = F.Get_image_from_database(Form1.Current_MRP, "MP", "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, "MP", listBox1.SelectedItem.ToString())); pictureBox10.Image = Img; bool Exist_on_Subensambles = false; //REVISAR SI EXISTE EL SUBENSAMBLE SELECCIONADO { string Nombre_Subensamble = listBox1.SelectedItem.ToString(); ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("Nombre_Subensamble"); Values.Clear(); Values.Add(Nombre_Subensamble);

Page 18: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 375

Exist_on_Subensambles = F.Exist_row_on_Access_Table(Form1.Current_MRP, "Subensambles", Columns, Values); } if (Exist_on_Subensambles) { int Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, "Subensambles", listBox1.SelectedItem.ToString()); F.Get_file_from_database(Form1.Current_MRP, "Subensambles", "Arboles_subensambles", "Index", Indx_on_table.ToString()); treeView1.ImageList = imageList1; treeView2.ImageList = imageList1; foreach (TreeNode node in F.Load_tree_from_file(F.Functions_folder + "\\" + "Tree_info_01.txt")) { //MessageBox.Show(Node.Text.ToString()); string node_name = node.Text; node.ImageIndex = Images_Names.IndexOf(node_name); TreeView tree = treeView2; tree.Nodes.Add(node); } //HACE UN RECORRIDO A TRAVES DEL TREEVIEW2 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView2, false); //CALCULAR REQUERIMIENTOS DE COMPONENTES MP_req.Clear(); Calculate_quantity_requierements(); treeView2.ExpandAll(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "listBox1_SelectedIndexChanged_1"); } } private void listBox2_SelectedIndexChanged_1(object sender, EventArgs e) {

Page 19: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

376 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

try { treeView3.Nodes.Clear(); string Table_name = "Subensambles"; //CARGA LA RAMA O SUBENSAMBLE Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, listBox2.SelectedItem.ToString()).ToString(); //MessageBox.Show(Indx_on_table); F.Get_file_from_database_sub(Form1.Current_MRP, Table_name, "Arboles_subensambles", "Index", Indx_on_table); treeView3.ImageList = imageList1; foreach (TreeNode node in F.Load_tree_from_file(F.Functions_folder + "\\" + "Tree_info_01.txt")) { string node_name = node.Text; node.ImageIndex = Images_Names.IndexOf(node_name); TreeView tree = treeView3; tree.Nodes.Add(node); } treeView3.ExpandAll(); //HACE UN RECORRIDO A TRAVES DEL TREEVIEW3 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView3, false); //CARGA LA IMAGEN DEL PRIMER NODO DE LA RAMA EN EL PREVIEW string First_node_name = F.Read_name(treeView3.Nodes[0].Text); // MessageBox.Show(First_node_name); //the image of the first node Image Img = F.Get_image_from_database(Form1.Current_MRP, "MP", "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, "MP", First_node_name)); pictureBox10.Image = Img; } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "listBox2_SelectedIndexChanged_1"); } } private void tabControl1_SelectedIndexChanged_1(object sender, EventArgs e)

Page 20: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 377

{ try { pictureBox10.Image = null; if (tabControl1.SelectedIndex == 0) { if (listBox1.SelectedIndex >= 0) { Image Img = F.Get_image_from_database(Form1.Current_MRP, "MP", "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, "MP", listBox1.SelectedItem.ToString())); pictureBox10.Image = Img; } toolStrip6.Visible = false; splitContainer1.SplitterDistance = 0; label17.Visible = false; treeView3.Visible = false; toolStrip5.Location = new Point(488, 225); } if (tabControl1.SelectedIndex == 1) { if (listBox2.SelectedIndex >= 0) { string First_node_name = F.Read_name(treeView3.Nodes[0].Text); // MessageBox.Show(First_node_name); //the image of the first node Image Img = F.Get_image_from_database(Form1.Current_MRP, "MP", "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, "MP", First_node_name)); pictureBox10.Image = Img; } toolStrip6.Visible = true; splitContainer1.SplitterDistance = 154; label17.Visible = true; treeView3.Visible = true; toolStrip5.Location = new Point(702, 125); } } catch (Exception Error) {

Page 21: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

378 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

F.Show_Error_Message(Error.ToString(), "tabControl1_SelectedIndexChanged_1"); } } private void toolStripButton1_Click(object sender, EventArgs e) { try { Form2 F2 = new Form2(); F2.IdentityUpdated += new Form2.UpdateHandler(ButtonClicked); F2.extended = true; F2.Show(); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton1_Click"); } } private void toolStripButton2_Click(object sender, EventArgs e) { try { Form5 F5 = new Form5(); F5.Show(); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton2_Click"); } } private void toolStripButton3_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox1.Text == "") { pictureBox2.Show(); } if (textBox2.Text == "") { pictureBox3.Show(); } if (pictureBox1.Image == null) { pictureBox4.Show(); } if (textBox3.Text == "") { pictureBox5.Show(); } if (comboBox1.SelectedIndex < 0) { pictureBox6.Show(); } if (textBox4.Text == "") { pictureBox7.Show(); } if (textBox5.Text == "") { pictureBox8.Show(); } if (textBox6.Text == "") { pictureBox9.Show(); }

Page 22: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 379

//HIDE MISSING DATA INDICATORS if (textBox1.Text != "") { pictureBox2.Hide(); } if (textBox2.Text != "") { pictureBox3.Hide(); } if (pictureBox1.Image != null) { pictureBox4.Hide(); } if (textBox3.Text != "") { pictureBox5.Hide(); } if (comboBox1.SelectedIndex > 0) { pictureBox6.Hide(); } if (textBox4.Text != "") { pictureBox7.Hide(); } if (textBox5.Text != "") { pictureBox8.Hide(); } if (textBox6.Text != "") { pictureBox9.Hide(); } if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || pictureBox1.Image == null || comboBox1.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { if (Expanded == false) { Expanded = true; this.Size = new Size(800, 526); Fill_MP_list(); //Fill_Products_list(); Add_main_Node(); } else { Expanded = false; this.Size = new Size(265, 526); } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton3_Click"); } } private void toolStripButton4_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox1.Text == "") { pictureBox2.Show(); } if (textBox2.Text == "") { pictureBox3.Show(); } if (pictureBox1.Image == null) { pictureBox4.Show(); }

Page 23: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

380 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (textBox3.Text == "") { pictureBox5.Show(); } if (comboBox1.SelectedIndex < 0) { pictureBox6.Show(); } if (textBox4.Text == "") { pictureBox7.Show(); } if (textBox5.Text == "") { pictureBox8.Show(); } if (textBox6.Text == "") { pictureBox9.Show(); } //HIDE MISSING DATA INDICATORS if (textBox1.Text != "") { pictureBox2.Hide(); } if (textBox2.Text != "") { pictureBox3.Hide(); } if (pictureBox1.Image != null) { pictureBox4.Hide(); } if (textBox3.Text != "") { pictureBox5.Hide(); } if (comboBox1.SelectedIndex > 0) { pictureBox6.Hide(); } if (textBox4.Text != "") { pictureBox7.Hide(); } if (textBox5.Text != "") { pictureBox8.Hide(); } if (textBox6.Text != "") { pictureBox9.Hide(); } if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || pictureBox1.Image == null || comboBox1.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { F.Identify_folders(); //CHECK THE FOLDERS FOR THE PROGRAM AND CREATE THE MISSING ONES. ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = ""; if (Show_Tree_button == false) { Table_name = "MP"; } else { Table_name = "Productos"; } //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("Producto"); Columns.Add("Referencia"); Values.Clear(); Values.Add(textBox1.Text.ToString()); Values.Add(textBox2.Text.ToString()); bool Exist_on_Products = F.Exist_row_on_Access_Table(Form1.Current_MRP, "Productos", Columns, Values);

Page 24: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 381

bool Exist_on_MP = F.Exist_row_on_Access_Table(Form1.Current_MRP, "MP", Columns, Values); //MessageBox.Show(Exist_on_Products.ToString() + " " + Exist_on_MP.ToString()); Columns.Clear(); Columns.Add("Index"); Columns.Add(Table_name); Columns.Add("Referencia"); Columns.Add("Imagen"); Columns.Add("Inventario_inicial"); Columns.Add("Unidad"); Columns.Add("Lead_Time"); Columns.Add("Costo_pedir"); Columns.Add("Costo_almacenar"); if (Show_Tree_button == true) { Columns.Add("Arbol_de_producto"); } Columns.Add("Demanda_anual"); Columns.Add("Tamaño_predeterminado_lote"); //Columns.Add("Stock_seguridad"); Columns.Add("Politica_dimensionamiento_lote"); Values.Clear(); if (Edition == true) { Values.Add(Indx_on_table); //Coloca el mismo index de la tabla por ser editado } else { Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name)); //Obtiene el numero de productos en la tabla } Values.Add(textBox1.Text.ToString()); Values.Add(textBox2.Text.ToString()); Values.Add(Image_path); // Imagen desde archivo Values.Add(textBox3.Text.ToString()); Values.Add(comboBox1.SelectedItem.ToString()); Values.Add(textBox4.Text.ToString()); Values.Add(textBox5.Text.ToString()); Values.Add(textBox6.Text.ToString()); //CREATE AT LEAST THE MAIN NODE IF DOESN´T EXIST TREE INFO

Page 25: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

382 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (treeView1.GetNodeCount(true) < 1) { Add_main_Node(); } if (Show_Tree_button == true) { //F.Save_tree_to_file(treeView1, F.Functions_folder + "\\" + "Tree_info_00.txt"); Values.Add("oledb object"); } Values.Add(textBox9.Text.ToString()); Values.Add(textBox10.Text.ToString()); Values.Add(comboBox2.SelectedIndex.ToString()); if (Exist_on_Products == false && Exist_on_MP == false) { //FIRST SAVE THE PRODUCT TREE INFO if (Show_Tree_button == true) { F.Save_tree_to_file(treeView1, F.Functions_folder + "\\" + "Tree_info_00.txt"); } int Success = F.AddDataToTable(Form1.Current_MRP, Table_name, Columns, Values); if (Success == 1) { MessageBox.Show("Datos agregados satisfactoriamente"); } else { MessageBox.Show("No se agregaron los datos"); } this.Close(); } else { if (Edition == true) //Si esta en modo de edicion { F.DeleteDataToAccessTable(Form1.Current_MRP, Table_name, Indx_on_table); //FIRST SAVE THE PRODUCT TREE INFO if (Show_Tree_button == true) { F.Save_tree_to_file(treeView1, F.Functions_folder + "\\" + "Tree_info_00.txt"); } int Success = F.AddDataToTable(Form1.Current_MRP, Table_name, Columns, Values); if (Success == 1) { MessageBox.Show("Datos agregados satisfactoriamente"); } else { MessageBox.Show("No se agregaron los datos"); } //F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Indx_on_table); //EDITA LOS DATOS DE LA MP O PRODUCTO this.Close();

Page 26: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 383

} else // Si no esta en modo de edicion { string Message = "Ya existe "; if (Exist_on_Products == true) { Message = Message + "un Producto, "; } if (Exist_on_MP == true) { Message = Message + "un Material (MP o PP), "; } Message = Message + "con el mismo nombre o referencia. Cambie de nombre o referencia. "; MessageBox.Show(Message); } } } //string path_of_image = F.Images_folder + "\\" + listBox1.SelectedItem + "\\" + listView1.SelectedItems[0].Text; UpdateEventArgs3 args = new UpdateEventArgs3(""); IdentityUpdated3(this, args); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton4_Click"); } } private void toolStripButton5_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox3.Text == "") { pictureBox5.Show(); } if (comboBox1.SelectedIndex < 0) { pictureBox6.Show(); } //HIDE MISSING DATA INDICATORS if (textBox3.Text != "") { pictureBox5.Hide(); } if (comboBox1.SelectedIndex > 0) { pictureBox6.Hide(); } if (textBox3.Text == "" || comboBox1.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { Form3 F3 = new Form3(); F3.IdentityUpdated2 += new Form3.UpdateHandler2(ButtonClicked2);

Page 27: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

384 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

F3.extended = false; F3.Initial_value = textBox3.Text; F3.Selected_unit = comboBox1.SelectedItem.ToString(); F3.Show(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton5_Click"); } } private bool Check_if_node_is_posible(TreeNode treeNode, bool is_OK) { try { //MessageBox.Show("OK" + is_OK); string node_name = F.Read_name(treeNode.Text); string Path_select = treeNode.FullPath; ArrayList Pieces_of_path = F.Separate_path_into_pieces(Path_select); ArrayList Pieces_of_path_only_names = new ArrayList(); foreach (string piece in Pieces_of_path) { Pieces_of_path_only_names.Add(F.Read_name(piece)); } //QUITAR EL ULTIMO NODO DEL ARBOL PUES ES EL QUE SE EVALUA int Count = Pieces_of_path_only_names.Count; Pieces_of_path_only_names.RemoveAt(Count - 1); //Revisar si el nodo añadido ya existe en la rama if (Pieces_of_path_only_names.Contains(F.Read_name(node_name))) { is_OK = false; } if (is_OK == false) { Its_possible = false; MessageBox.Show("Analizando el nodo:" + node_name + "\r\n" + Path_select + "\r\n" + "Se encontro que no puede formar parte de si mismo." + "\r\n" + "Resultado para añadir subensamble: " + is_OK);

Page 28: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 385

} foreach (TreeNode tn in treeNode.Nodes) { //MessageBox.Show("OK" + is_OK); Check_if_node_is_posible(tn, is_OK); // } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Check_if_node_is_posible"); } return is_OK; } private void Check_if_tree_is_posible(TreeView treeView) // if is true: Calculate_quantity else: Refresh_tree_images { try { TreeNodeCollection nodes = treeView.Nodes; foreach (TreeNode n in nodes) { Check_if_node_is_posible(n, true); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Check_if_tree_is_posible"); } } private void toolStripButton6_Click(object sender, EventArgs e) { try { // ADD NEW NODE TO TREE if (this.treeView1.SelectedNode == null) { F.Show_Advisory_Message("Debe seleccionar un punto en el arbol, en donde añadir la MP o Componenete", "Añadiendo Nodo"); } else { if (tabControl1.SelectedIndex == 0) { string Name_to_show = listBox1.SelectedItem.ToString() + " (" + this.textBox8.Text + ")";

Page 29: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

386 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//MessageBox.Show(Name_to_show); string Path_select = this.treeView1.SelectedNode.FullPath; ArrayList Pieces_of_path = F.Separate_path_into_pieces(Path_select); ArrayList Pieces_of_path_only_names = new ArrayList(); foreach (string piece in Pieces_of_path) { Pieces_of_path_only_names.Add(F.Read_name(piece)); } if (Pieces_of_path_only_names.Contains(F.Read_name(Name_to_show))) { F.Show_Advisory_Message("No se puede agregar. Pues, ningun componente puede formar parte de si mismo", "Agregando Nodo"); } else { // AÑADIR NODO Image Prev_01 = pictureBox10.Image; if (textBox8.Text != "0" || textBox8.Text != "") { string Node_name = listBox1.SelectedItem.ToString(); int Index = this.Images_Names.IndexOf(Node_name); if (Index < 0) { this.imageList1.Images.Add(Prev_01); this.Images_Names.Add(Node_name); } Index = this.Images_Names.IndexOf(Node_name); treeView1.ImageList = imageList1; TreeNode Node_00 = new TreeNode(Name_to_show, Index, Index); this.treeView1.SelectedNode.Nodes.Add(Node_00); this.treeView1.SelectedNode.Expand();

Page 30: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 387

//CALCULAR REQUERIMIENTOS DE COMPONENTES MP_req.Clear(); Calculate_quantity_requierements(); } } } if (tabControl1.SelectedIndex == 1) { if (listBox2.SelectedIndex < 0) { F.Show_Advisory_Message("Primero debe seleccionar un subensamble de la lista", "Agregando subensamble"); } else { //GUARDAR EL ARBOL ANTES DE MODIFICARLO TreeNode Select_node = treeView1.SelectedNode; // Nodo seleccionado por el usuario para añadir la rama treeView1.SelectedNode = treeView1.Nodes[0]; // Nodo raiz seleccionado por codigo TreeNode Selected_node = treeView1.SelectedNode; TreeNode Full_tree = new TreeNode(Selected_node.Text); //COPIAR EL ARBOL DE PRODUCTO Copiar_nodos(Selected_node, Full_tree); //Restaurar la seleccion del nodo treeView1.SelectedNode = Select_node; // CARGAR LOS DATOS DE LA RAMA QUE APARECEN EN EL TREEVIEW3 treeView3.SelectedNode = treeView3.Nodes[0]; Select_node = treeView3.SelectedNode; TreeNode Branch = new TreeNode(Select_node.Text); //copy all the child nodes Copiar_nodos(Select_node, Branch); this.treeView1.SelectedNode.Nodes.Add(Branch); this.treeView1.ExpandAll(); //HACE UN RECORRIDO A TRAVES DEL TREEVIEW1 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView1, false);

Page 31: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

388 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//VERIFICA SI ES CORRECTA LA ESTRUCTURA DEL ARBOL Its_possible = true; Check_if_tree_is_posible(treeView1); //MessageBox.Show(Its_possible.ToString()); //CARGA EL ARBOL ANTES DE SER MODIFICADO SI NO ES POSIBLE LA ESTRUCTURA DEL ARBOL if (Its_possible == false) { treeView1.Nodes.Clear(); treeView1.Nodes.Add(Full_tree); } treeView1.ExpandAll(); //HACE UN RECORRIDO A TRAVES DEL TREEVIEW1 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView1, false); //CALCULA LOS REQUERIMIENTOS Calculate_quantity_requierements(); } } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton6_Click"); } } private void toolStripButton7_Click(object sender, EventArgs e) { try { // REMOVE TREE NODE if (this.treeView1.SelectedNode == null) { F.Show_Advisory_Message("Debe seleccionar un punto en el arbol, para eliminar la MP o Componenete", "Eliminando Nodo"); } else { if (treeView1.SelectedNode.Text == textBox1.Text) { F.Show_Error_Message("Este nodo no se puede eliminar", "Eliminando Nodo"); } else

Page 32: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 389

{ this.treeView1.SelectedNode.Remove(); } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "toolStripButton7_Click"); } } private void textBox9_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX3 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox3"); } } private void textBox10_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX3 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox3"); }

Page 33: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

390 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} private void textBox12_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX3 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox3"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { try { //MessageBox.Show(e.KeyChar.ToString()); if (e.KeyChar == Convert.ToChar(" ")) { e.KeyChar = Convert.ToChar("_"); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "textBox1_KeyPress"); } } private void toolStripButton9_Click(object sender, EventArgs e) { try { if (this.treeView1.SelectedNode == null) { F.Show_Advisory_Message("Debe seleccionar un nodo en el arbol, para guardar esa rama del arbol como un Subensamble", "Añadiendo Nodo"); }

Page 34: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 391

else { // MUESTRA EL FORM PARA CREAR UNA NUEVA UNIDAD Text1.Text = F.Read_name(treeView1.SelectedNode.Text); Create_Subassembly.ShowDialog(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una subensamble"); } } private void Delete_Operation_Storage(int Kase) { try { if (listBox2.SelectedItems.Count > 0) //REVISA SI HAY UN ITEM SELECCIONADO PARA PODER ELIMINARLO { //Kase 0 = Demanda, Kase 1 = Pedidos_a_recibir, Kase 2 = Inventarios Pronosticados string Table_name = "Subensambles"; DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Focused_Index = listBox2.SelectedIndex; string Selected_item_name = listBox2.SelectedItem.ToString(); //MessageBox.Show(Focused_Index + "++" + Selected_item_name); for (int i = 0; i < table.Rows.Count; i++) { string Index_on_table = table.Rows[i][0].ToString(); string Name_on_table = table.Rows[i][1].ToString(); //MessageBox.Show(Name_on_table + "|" + Selected_item_name); if (Name_on_table == Selected_item_name) { F.DeleteDataToAccessTable(Form1.Current_MRP, Table_name, Index_on_table);

Page 35: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

392 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//MessageBox.Show(Index_on_table + "___________" + Name_on_table); } } } else { F.Show_Error_Message("Debe seleccionar un Subensamble.", "Eliminando subensamble"); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Borrando Subensamble"); } } private void toolStripButton8_Click(object sender, EventArgs e) { try { //BORRA LA OPERACION SELECCIONADA Delete_Operation_Storage(0); //REFRESCA LA LISTA DE ITEMS PARA LOS SUBENSAMBLES Y MP Fill_MP_list(); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Borrando Subensamble"); } } } public class UpdateEventArgs3 : System.EventArgs { public string Image_path; public UpdateEventArgs3(string Path_of_image) { } } }

Page 36: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 393

E-3. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE OPERACIONES Y ALMACENAMIENTOS

using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; namespace MRProgram_00 { public partial class Form9 : Form { Functions.Operatives F = new Operatives(); public bool For_operation = false; string Image_path = ""; public bool Edition = false; //VARIABLES PARA EDITAR LOS VALORES public string Indx_on_table = ""; public string Nombre = ""; public string Referencia = ""; public string Imagen; public string Capacidad_mano_obra = ""; public string Unidad_mano_obra = ""; public string Capacidad_maquinaria = ""; public string Unidad_maquinaria = ""; //MANEJADOR DE EVENTOS PARA ENVIAR A OTRO FORM EL EVENTO DE CIERRE public delegate void UpdateHandler4(object sender, UpdateEventArgs4 e); public event UpdateHandler4 IdentityUpdated4; public Form9() { InitializeComponent(); } private void Form9_Load(object sender, EventArgs e) { try {

Page 37: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

394 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

F.Identify_folders(); this.Size = new Size(265, 345); //HIDE MISSING DATA INDICATORS pictureBox2.Hide(); pictureBox3.Hide(); pictureBox4.Hide(); pictureBox5.Hide(); pictureBox6.Hide(); pictureBox7.Hide(); pictureBox8.Hide(); if (For_operation == false) { this.Text = "Nuevo Almacenamiento"; } else { this.Text = "Nueva Operacion"; } Fill_units_lists(); if (Edition == true) // Llenar los campos de datos si se trata de editar datos { textBox1.Text = Nombre; textBox2.Text = Referencia; pictureBox1.Image = Image.FromFile(Imagen); Image_path = Imagen; ////MessageBox.Show(Imagen); //SELECCIONA EL INDEX DE LA UNIDAD REQUERIDA int Indx = comboBox1.Items.IndexOf(Unidad_mano_obra); comboBox1.SelectedIndex = Indx; Indx = comboBox2.Items.IndexOf(Unidad_maquinaria); comboBox2.SelectedIndex = Indx; textBox3.Text = Capacidad_mano_obra; textBox4.Text = Capacidad_maquinaria; textBox1.ReadOnly = true; textBox2.ReadOnly = true; } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Abriendo Form 9"); } }

Page 38: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 395

private void ButtonClicked(object sender, UpdateEventArgs e) { try { //MessageBox.Show(e.Image_path); this.BringToFront(); pictureBox1.Image = Image.FromFile(e.Image_path); Image_path = e.Image_path; //textBox1.Text = e.mFirstName + " _ " + e.mMiddleName; } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "ButtonClicked"); } } private void ButtonClicked2(object sender, UpdateEventArgs2 e) { try { this.BringToFront(); textBox3.Text = e.Value; int indx = comboBox1.Items.IndexOf(e.Unit_to_send); comboBox1.SelectedIndex = indx; } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "ButtonClicked2"); } } private void Fill_units_lists() { try { DataTable Table = F.Get_table_from_Access_File(Form1.Current_MRP, "Unidades"); ArrayList Unidades = new ArrayList(); for (int i = 0; i < Table.Rows.Count; i++) { string Unidad = Table.Rows[i][2].ToString(); if (!Unidades.Contains(Unidad)) { Unidades.Add(Unidad); //Obtiene la lista de las diferentes categorias para las Unidades }

Page 39: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

396 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} comboBox1.Items.Clear(); comboBox2.Items.Clear(); foreach (string Unit in Unidades) { comboBox1.Items.Add(Unit); //LLENA EL COMBOBOX1 CON LA LISTA DE TODAS LAS UNIDADES UNIDADES comboBox2.Items.Add(Unit); } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Fill_units_lists"); } } private void ButtonClicked3(object sender, UpdateEventArgs2 e) { try { this.BringToFront(); textBox4.Text = e.Value; int indx = comboBox2.Items.IndexOf(e.Unit_to_send); comboBox2.SelectedIndex = indx; } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "ButtonClicked3"); } } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX3 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox3.Text) == true) { e.Handled = true; } }

Page 40: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 397

catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox3"); } } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX4 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox4.Text) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox4"); } } private void toolStripButton1_Click(object sender, EventArgs e) { Form2 F2 = new Form2(); F2.IdentityUpdated += new Form2.UpdateHandler(ButtonClicked); F2.extended = true; F2.Show(); } private void toolStripButton2_Click(object sender, EventArgs e) { Form5 F5 = new Form5(); F5.Show(); } private void toolStripButton5_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox3.Text == "") { pictureBox5.Show(); } if (comboBox1.SelectedIndex < 0) { pictureBox6.Show(); }

Page 41: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

398 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//HIDE MISSING DATA INDICATORS if (textBox3.Text != "") { pictureBox5.Hide(); } if (comboBox1.SelectedIndex > 0) { pictureBox6.Hide(); } if (textBox3.Text == "" || comboBox1.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { Form3 F3 = new Form3(); F3.IdentityUpdated2 += new Form3.UpdateHandler2(ButtonClicked2); F3.extended = false; F3.Initial_value = textBox3.Text; F3.Selected_unit = comboBox1.SelectedItem.ToString(); F3.Show(); } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "toolStripButton5_Click"); } } private void toolStripButton4_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox1.Text == "") { pictureBox2.Show(); } if (textBox2.Text == "") { pictureBox3.Show(); } if (pictureBox1.Image == null) { pictureBox4.Show(); } if (textBox3.Text == "") { pictureBox5.Show(); } if (comboBox1.SelectedIndex < 0) { pictureBox6.Show(); } if (textBox4.Text == "") { pictureBox7.Show(); } if (comboBox2.SelectedIndex < 0) { pictureBox8.Show(); } //HIDE MISSING DATA INDICATORS if (textBox1.Text != "") { pictureBox2.Hide(); } if (textBox2.Text != "") { pictureBox3.Hide(); } if (pictureBox1.Image != null) { pictureBox4.Hide(); } if (textBox3.Text != "") { pictureBox5.Hide(); } if (comboBox1.SelectedIndex > 0) { pictureBox6.Hide(); } if (textBox4.Text != "") { pictureBox7.Hide(); } if (comboBox2.SelectedIndex > 0) { pictureBox8.Hide(); }

Page 42: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 399

if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || pictureBox1.Image == null || comboBox1.SelectedIndex < 0 || comboBox2.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { F.Identify_folders(); //CHECK THE FOLDERS FOR THE PROGRAM AND CREATE THE MISSING ONES. ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = ""; if (For_operation == false) { Table_name = "Almacenamientos"; } else { Table_name = "Operaciones"; } //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("Producto"); Columns.Add("Referencia"); Values.Clear(); Values.Add(textBox1.Text.ToString()); Values.Add(textBox2.Text.ToString()); bool Exist_on_Storage = F.Exist_row_on_Access_Table(Form1.Current_MRP, "Almacenamientos", Columns, Values); bool Exist_on_Operations = F.Exist_row_on_Access_Table(Form1.Current_MRP, "Operaciones", Columns, Values); //MessageBox.Show(Exist_on_Products.ToString() + " " + Exist_on_MP.ToString()); Columns.Clear(); Columns.Add("Index"); Columns.Add(Table_name); Columns.Add("Referencia"); Columns.Add("Imagen"); Columns.Add("Capacidades_mano_de_obra"); Columns.Add("Unidad_mano_de_obra"); Columns.Add("Capacidades_maquinaria"); Columns.Add("Unidad_maquinaria");

Page 43: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

400 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

Values.Clear(); Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name)); //Obtiene el numero de productos en la tabla Values.Add(textBox1.Text.ToString()); Values.Add(textBox2.Text.ToString()); Values.Add(Image_path); //Values.Add(F.Functions_folder + "\\" + "Temp_image.png"); Values.Add(textBox3.Text.ToString()); Values.Add(comboBox1.SelectedItem.ToString()); Values.Add(textBox4.Text.ToString()); Values.Add(comboBox2.SelectedItem.ToString()); if (Exist_on_Storage == false && Exist_on_Operations == false) { F.AddDataToTable(Form1.Current_MRP, Table_name, Columns, Values); } else { if (Edition == true) //Si esta en modo de edicion { F.DeleteDataToAccessTable(Form1.Current_MRP, Table_name, Indx_on_table); F.AddDataToTable(Form1.Current_MRP, Table_name, Columns, Values); //F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Indx_on_table); //EDITA LOS DATOS DE LA MP O PRODUCTO } else // Si no esta en modo de edicion { string Message = "Ya existe "; if (Exist_on_Storage == true) { Message = Message + "un Almacenamiento, "; } if (Exist_on_Operations == true) { Message = Message + "una Operacion, "; } Message = Message + "con el mismo nombre o referencia. Cambie de nombre o referencia. "; MessageBox.Show(Message); } } }

Page 44: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 401

//string path_of_image = F.Images_folder + "\\" + listBox1.SelectedItem + "\\" + listView1.SelectedItems[0].Text; UpdateEventArgs4 args = new UpdateEventArgs4(""); IdentityUpdated4(this, args); } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "toolStripButton4_Click"); } } private void toolStripButton3_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (textBox4.Text == "") { pictureBox7.Show(); } if (comboBox2.SelectedIndex < 0) { pictureBox8.Show(); } //HIDE MISSING DATA INDICATORS if (textBox4.Text != "") { pictureBox7.Hide(); } if (comboBox2.SelectedIndex > 0) { pictureBox8.Hide(); } if (textBox4.Text == "" || comboBox2.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { Form3 F3 = new Form3(); F3.IdentityUpdated2 += new Form3.UpdateHandler2(ButtonClicked3); F3.extended = false; F3.Initial_value = textBox4.Text; F3.Selected_unit = comboBox2.SelectedItem.ToString(); F3.Show(); } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "toolStripButton4_Click"); } } } public class UpdateEventArgs4 : System.EventArgs

Page 45: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

402 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ public string Image_path; public UpdateEventArgs4(string Path_of_image) { } } }

Page 46: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 403

E-4. VENTANA CREACIÓN / EDICIÓN DE DEMANDA, PEDIDOS A RECIBIR E INVENTARIOS PRONOSTICADOS

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; namespace MRProgram_00 { public partial class Form10 : Form { Functions.Operatives F = new Operatives(); //public bool Is_order_to_receive = false; public int Kase = 0; List<string> Workstations_names_list = new List<string>(); //VARIABLES PARA EDITAR LOS VALORES public bool Edition = false; public int MP_or_PRODUCT = 0; public string Nombre_MP_or_PRODUCT = ""; public string Imagen = ""; public DataTable Received_info = new DataTable(); //MANEJADOR DE EVENTOS PARA ENVIAR A OTRO FORM EL EVENTO DE CIERRE public delegate void UpdateHandler5(object sender, UpdateEventArgs5 e); public event UpdateHandler5 IdentityUpdated5; public Form10() { InitializeComponent(); } private void Fill_list(ComboBox list, string Table_name) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name);

Page 47: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

404 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

try { if (table.Rows.Count > 0) { progressBar1.Minimum = 1; progressBar1.Maximum = table.Rows.Count; progressBar1.Value = 1; progressBar1.Step = 1; } for (int i = 0; i < table.Rows.Count; i++) { string name = table.Rows[i][1].ToString(); list.Items.Add(name.ToString()); progressBar1.PerformStep(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Show_selected_collection_images"); } } private void Form10_Load(object sender, EventArgs e) { try { F.Identify_folders(); Fill_list(comboBox1, "MP"); Fill_list(comboBox2, "Productos"); DataTable table = new DataTable(); if (Kase == 0) { this.Text = "Demanda"; table.Columns.Add("Periodo"); table.Columns.Add("Demanda"); } if (Kase == 1) { this.Text = "Pedidos a recibir"; label4.Visible = false; label5.Visible = false;

Page 48: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 405

label6.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; textBox4.Visible = false; textBox5.Visible = false; table.Columns.Add("Periodo"); table.Columns.Add("Cantidad"); } if (Kase == 2) { this.Text = "Stock final deseado"; label4.Visible = false; label5.Visible = false; label6.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; textBox4.Visible = false; textBox5.Visible = false; table.Columns.Add("Periodo"); table.Columns.Add("Cantidad"); } dataGridView1.DataSource = table; dataGridView1.AutoResizeColumns(); if (Edition == true) { tabControl1.SelectedIndex = MP_or_PRODUCT; if (MP_or_PRODUCT == 0) { int Indx = comboBox1.Items.IndexOf(Nombre_MP_or_PRODUCT); comboBox1.SelectedIndex = Indx; //MessageBox.Show("MP"); } if (MP_or_PRODUCT == 1) { int Indx = comboBox2.Items.IndexOf(Nombre_MP_or_PRODUCT); comboBox2.SelectedIndex = Indx;

Page 49: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

406 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//MessageBox.Show("Producto"); } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Form10_Load"); } } private List<string> Get_names_of_operations_n_storages(string Table_name) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); try { for (int i = 0; i < table.Rows.Count; i++) { string name = table.Rows[i][1].ToString(); Workstations_names_list.Add(name.ToString()); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Get_names_of_operations_n_storages"); } return Workstations_names_list; } private void Fill_datagrid_with_demand_info(string Selected_MP_Product) { try { string Table_name = "Demanda"; if (Kase == 0) { Table_name = "Demanda"; } if (Kase == 1) { Table_name = "Pedidos_a_recibir"; } if (Kase == 2)

Page 50: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 407

{ Table_name = "Stock_final_deseado"; } DataTable Demand_info = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Number_of_rows = Demand_info.Rows.Count; DataTable Table_with_the_info = new DataTable(); if (Kase == 0) { Table_with_the_info.Columns.Add("Periodo"); Table_with_the_info.Columns.Add("Demanda"); } if (Kase == 1) { Table_with_the_info.Columns.Add("Periodo"); Table_with_the_info.Columns.Add("Cantidad"); } if (Kase == 2) { Table_with_the_info.Columns.Add("Periodo"); Table_with_the_info.Columns.Add("Cantidad"); } //FILL THE DATAGRID WITH THE INFO ABOUT THE DEMAND FOR THE SELECTED PRODUCT for (int j = 0; j < Number_of_rows; j++) { if (Selected_MP_Product == Demand_info.Rows[j][1].ToString()) { DataRow row; row = Table_with_the_info.NewRow(); if (Kase == 0) { row["Periodo"] = Demand_info.Rows[j][2]; row["Demanda"] = Demand_info.Rows[j][3]; //row["Demanda_anual"] = Demand_info.Rows[j][4]; //row["Tamaño_predeterminado_de_lote"] = Demand_info.Rows[j][5]; } if (Kase == 1) { row["Periodo"] = Demand_info.Rows[j][2];

Page 51: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

408 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

row["Cantidad"] = Demand_info.Rows[j][3]; } if (Kase == 2) { row["Periodo"] = Demand_info.Rows[j][2]; row["Cantidad"] = Demand_info.Rows[j][3]; } Table_with_the_info.Rows.Add(row); } } //if (Kase == 0 || Kase == 1) { dataGridView1.DataSource = Table_with_the_info; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Fill_datagrid_with_demand_info"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { string Table_name = "MP"; string Item_name = comboBox1.SelectedItem.ToString(); pictureBox1.Image = F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name)); Fill_datagrid_with_demand_info(comboBox1.SelectedItem.ToString()); //OBTENER LOS DATOS DE DEMANDA ANUAL Y TAMAÑO PREDETERMINADO DE LOTE DataTable table_MP = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name); textBox4.Text = table_MP.Rows[Indx_on_table][9].ToString(); //OBTIENE EL DATO DE LA DEMANDA ANUAL

Page 52: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 409

textBox5.Text = table_MP.Rows[Indx_on_table][10].ToString(); //OBTIENE EL DATO DE EL TAMAÑO DE LOTE PREDETERMINADO } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "comboBox1_SelectedIndexChanged"); } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { try { string Table_name = "Productos"; string Item_name = comboBox2.SelectedItem.ToString(); pictureBox1.Image = F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name)); Fill_datagrid_with_demand_info(comboBox2.SelectedItem.ToString()); //OBTENER LOS DATOS DE DEMANDA ANUAL Y TAMAÑO PREDETERMINADO DE LOTE DataTable table_Products = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name); textBox4.Text = table_Products.Rows[Indx_on_table][10].ToString(); //OBTIENE EL DATO DE LA DEMANDA ANUAL textBox5.Text = table_Products.Rows[Indx_on_table][11].ToString(); //OBTIENE EL DATO DE EL TAMAÑO DE LOTE PREDETERMINADO } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "comboBox2_SelectedIndexChanged"); } } int Right_data_format_on_datagridView(DataGridView Datagrd) {

Page 53: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

410 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//CHECK IF ALL DATA ARE POSITIVE INTEGERS, RETURNS 1 IF OK, -1 IF ERROR int Data = 0; var table = Datagrd.DataSource as DataTable; int Number_of_colums = table.Columns.Count; int Number_of_rows = table.Rows.Count; try { for (int i = 0; i < Number_of_rows; i++) { for (int j = 0; j < Number_of_colums; j++) { if (table.Rows[i][j].ToString() == "") { table.Rows[i][j] = 0; } Data = Convert.ToInt32(table.Rows[i][j]); //MessageBox.Show(Data.ToString()); if (Data < 0) { F.Show_Error_Message("Existen valores negativos. Los valores deben ser positivos", "Revisando formato de datos"); return Data = -1; } else { Data = 1; } } } } catch (Exception Error) { F.Show_Error_Message("Existen valores con errores de formato." + "\r\n" + Error.Message, "Revisando formato de datos"); return Data = -1; } return Data; } private void Delete_rows() { try { //GET THE INDEXES OF ROWS IN THE DATAGRID TO DELETE

Page 54: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 411

int Count_selected_cells = dataGridView1.GetCellCount(DataGridViewElementStates.Selected); ArrayList Indexes_of_rows_selected = new ArrayList(); if (Count_selected_cells > 0) { for (int i = 0; i < Count_selected_cells; i++) { if (!Indexes_of_rows_selected.Contains(dataGridView1.SelectedCells[i].RowIndex)) { Indexes_of_rows_selected.Add(dataGridView1.SelectedCells[i].RowIndex); //MessageBox.Show(dataGridView1.SelectedCells[i].RowIndex.ToString()); } } } //FILL THE DATA var table = dataGridView1.DataSource as DataTable; ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Demanda"; if (Kase == 0) { Table_name = "Demanda"; } if (Kase == 1) { Table_name = "Pedidos_a_recibir"; } if (Kase == 2) { Table_name = "Stock_final_deseado"; } for (int i = 0; i < Indexes_of_rows_selected.Count; i++) { int indx = Convert.ToInt32(Indexes_of_rows_selected[i].ToString()); DialogResult result = MessageBox.Show("Esta seguro de que desea borrar la fila " + indx.ToString() + "?", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes)

Page 55: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

412 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ Columns.Clear(); if (Kase == 0) { Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Demanda"); //Columns.Add("Demanda_anual"); //Columns.Add("Tamaño_predeterminado_de_lote"); } if (Kase == 1) { Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } if (Kase == 2) { Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } Values.Clear(); if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox1.SelectedItem.ToString()); } else { Values.Add(comboBox2.SelectedItem.ToString()); } if (Kase == 0) { Values.Add(table.Rows[indx][0]); Values.Add(table.Rows[indx][1]); } if (Kase == 1) { Values.Add(table.Rows[indx][0]);

Page 56: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 413

Values.Add(table.Rows[indx][1]); } if (Kase == 2) { Values.Add(table.Rows[indx][0]); Values.Add(table.Rows[indx][1]); } //CHECK IF EXIST A ROW WITH THE SAME NAME AND PERIOD int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); Columns.Clear(); if (Kase == 0) { Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Demanda"); } if (Kase == 1) { Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } if (Kase == 2) { Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } Values.Clear(); Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name)); //Obtiene el numero de productos en la tabla //MessageBox.Show(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name).ToString());

Page 57: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

414 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox1.SelectedItem.ToString()); } else { Values.Add(comboBox2.SelectedItem.ToString()); } if (Kase == 0) { Values.Add(table.Rows[indx][0]); Values.Add(table.Rows[indx][1]); } if (Kase == 1) { Values.Add(table.Rows[indx][0]); Values.Add(table.Rows[indx][1]); } if (Kase == 2) { Values.Add(table.Rows[indx][0]); Values.Add(table.Rows[indx][1]); } if (F.DeleteDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Index_on_access_table.ToString()) > 0) { dataGridView1.Rows.RemoveAt(indx); } } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Borrando Filas"); } } private void toolStripButton1_Click(object sender, EventArgs e) { Delete_rows(); }

Page 58: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 415

private void toolStripButton2_Click(object sender, EventArgs e) { try { var table = dataGridView1.DataSource as DataTable; int Number_of_colums = table.Columns.Count; int Number_of_rows = table.Rows.Count; object[,] Matrix_01 = new object[Number_of_rows, Number_of_colums]; ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Demanda"; if (Kase == 0) { Table_name = "Demanda"; } if (Kase == 1) { Table_name = "Pedidos_a_recibir"; } if (Kase == 2) { Table_name = "Stock_final_deseado"; } //SHOW MISSING DATA INDICATORS if (comboBox1.SelectedIndex < 0 && comboBox2.SelectedIndex < 0) { pictureBox5.Show(); } //HIDE MISSING DATA INDICATORS if (comboBox1.SelectedIndex < 0 && comboBox2.SelectedIndex < 0) { pictureBox5.Hide(); } //CHECK IF THE DATA FORMAT IS OK int Format_OK = Right_data_format_on_datagridView(dataGridView1); //CHECK IF THE REQUIERED FILD ARE FILLED if (comboBox1.SelectedIndex < 0 && comboBox2.SelectedIndex < 0) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); }

Page 59: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

416 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

else { F.Identify_folders(); //CHECK THE FOLDERS FOR THE PROGRAM AND CREATE THE MISSING ONES. if (Format_OK == 1) { int times = 0; int times_success = 0; for (int i = 0; i < Number_of_rows; i++) { bool Exist_on_Demand = false; //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Values.Clear(); if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox1.SelectedItem.ToString()); } else { Values.Add(comboBox2.SelectedItem.ToString()); } Values.Add(table.Rows[i][0]); //CHECK IF EXIST A ROW WITH THE SAME NAME AND PERIOD Exist_on_Demand = F.Exist_a_row_with_this_info_of_different_columns_on_Access_Table(Form1.Current_MRP, Table_name, Columns, Values); int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); //FILL THE INFO Columns.Clear(); if (Kase == 0) { Columns.Add("Index"); Columns.Add("MP_Productos");

Page 60: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 417

Columns.Add("Periodo"); Columns.Add("Demanda"); //Columns.Add("Demanda_anual"); //Columns.Add("Tamaño_predeterminado_de_lote"); } if (Kase == 1) { Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } if (Kase == 2) { Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Periodo"); Columns.Add("Cantidad"); } Values.Clear(); Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name)); //Obtiene el numero de productos en la tabla //MessageBox.Show(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name).ToString()); if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox1.SelectedItem.ToString()); } else { Values.Add(comboBox2.SelectedItem.ToString()); } if (Kase == 0) { Values.Add(table.Rows[i][0]); Values.Add(table.Rows[i][1]); } if (Kase == 1)

Page 61: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

418 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ Values.Add(table.Rows[i][0]); Values.Add(table.Rows[i][1]); } if (Kase == 2) { Values.Add(table.Rows[i][0]); Values.Add(table.Rows[i][1]); } times++; if (Exist_on_Demand == false) { //IF DOESNT EXIST ADD IT int Success = F.AddDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values); if (Success == 1) { times_success++; } //this.Close(); } else { //string Message = "Ya existe " + "una demanda en el periodo " + table.Rows[i][0].ToString() + ", para este Item, " + " desea remplazar los datos?"; //DialogResult result = MessageBox.Show(Message, "Advertensia", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //if (result == DialogResult.Yes) //{ //MessageBox.Show(Index.ToString()); //MessageBox.Show(Columns.Count.ToString() + "°°" + Values.Count.ToString()); int Success = F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Index_on_access_table.ToString()); if (Success == 1) { times_success++; } //this.Close(); //} } }

Page 62: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 419

//GUARDA LA DEMANDA ANUAL Y EL TAMAÑO PREDETERMINADO DE LOTE EN LA TABLA DE MP O PRODUCTOS SEGUN SEA EL CASO if (Kase == 0) { Columns.Clear(); Values.Clear(); Columns.Add("Index"); Columns.Add("Demanda_anual"); Columns.Add("Tamaño_predeterminado_lote"); string Item_name = ""; int Indx_on_table = -1; if (tabControl1.SelectedIndex == 0) { Table_name = "MP"; Item_name = comboBox1.SelectedItem.ToString(); Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name); } else { Table_name = "Productos"; Item_name = comboBox2.SelectedItem.ToString(); Indx_on_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Item_name); } Values.Add(Indx_on_table); Values.Add(textBox4.Text); Values.Add(textBox5.Text); //MessageBox.Show(Columns.Count.ToString() + "|" + Values.Count.ToString()); times++; int Success = F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Indx_on_table.ToString()); if (Success == 1) { times_success++; } //this.Close(); }

Page 63: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

420 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (times == times_success) { MessageBox.Show("Todos los datos se enviaron a la base de datos"); } else { MessageBox.Show("No todos los datos se enviaron a la base de datos"); } } } //string path_of_image = F.Images_folder + "\\" + listBox1.SelectedItem + "\\" + listView1.SelectedItems[0].Text; UpdateEventArgs5 args = new UpdateEventArgs5(""); IdentityUpdated5(this, args); this.Close(); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "toolStripButton2_Click"); } } private void Form10_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Delete) { DialogResult result = MessageBox.Show("Esta seguro de que desea borrar las filas seleccionadas. Borrar esta informacion podria inhabilitar la utilizacion de los datos de este MRP." + "\r\n" + "¿Desea continuar? ", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Delete_rows(); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Form10_KeyDown"); } } } public class UpdateEventArgs5 : System.EventArgs { public string Image_path; public UpdateEventArgs5(string Path_of_image) {

Page 64: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 421

} } }

Page 65: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

E-5. VENTANA CREACIÓN / EDICIÓN DE CAPACIDADES REQUERIDAS

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; namespace MRProgram_00 { public partial class Form11 : Form { Functions.Operatives F = new Operatives(); public bool Edition = false; //VARIABLES PARA EDITAR LOS VALORES public string Indx_on_table = ""; public string Nombre_MP = ""; public int MP_or_Product = 0; public int Operation_or_Storage = 0; public string Selected_Operation_Storage; //MANEJADOR DE EVENTOS PARA ENVIAR A OTRO FORM EL EVENTO DE CIERRE public delegate void UpdateHandler6(object sender, UpdateEventArgs6 e); public event UpdateHandler6 IdentityUpdated6; public Form11() { InitializeComponent(); } private void Fill_list(ComboBox list, string Table_name) {

Page 66: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

424 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); try { if (table.Rows.Count > 0) { progressBar1.Minimum = 1; progressBar1.Maximum = table.Rows.Count; progressBar1.Value = 1; progressBar1.Step = 1; } list.Items.Clear(); ArrayList Items_list = new ArrayList(); for (int i = 0; i < table.Rows.Count; i++) { string name = table.Rows[i][1].ToString(); if (!Items_list.Contains(name)) { list.Items.Add(name.ToString()); Items_list.Add(name); } progressBar1.PerformStep(); } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Show_selected_collection_images"); } } private void Form11_Load(object sender, EventArgs e) { try { F.Identify_folders(); Fill_list(comboBox1, "MP"); Fill_list(comboBox2, "Operaciones"); Fill_list(comboBox3, "Almacenamientos"); Fill_list(comboBox5, "Productos"); //HIDE MISSING DATA INDICATORS pictureBox3.Hide();

Page 67: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 425

pictureBox4.Hide(); pictureBox5.Hide(); pictureBox6.Hide(); //LLENAR LA INFORMACION CUANDO SE ESTA EDITANTO if (Edition == true) { int Indx = comboBox1.Items.IndexOf(Nombre_MP); comboBox1.SelectedIndex = Indx; Indx = comboBox1.Items.IndexOf(Nombre_MP); comboBox1.SelectedIndex = Indx; tabControl1.SelectedIndex = Operation_or_Storage; tabControl2.SelectedIndex = MP_or_Product; if (MP_or_Product == 0) { Indx = comboBox1.Items.IndexOf(Nombre_MP); comboBox1.SelectedIndex = Indx; } if (MP_or_Product == 1) { Indx = comboBox5.Items.IndexOf(Nombre_MP); comboBox5.SelectedIndex = Indx; } if (Operation_or_Storage == 0) { Indx = comboBox2.Items.IndexOf(Selected_Operation_Storage); comboBox2.SelectedIndex = Indx; } if (Operation_or_Storage == 1) { Indx = comboBox3.Items.IndexOf(Selected_Operation_Storage); comboBox3.SelectedIndex = Indx; } } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Form11_Load"); } }

Page 68: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

426 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

private void Show_Image(string Table_name, ComboBox Combox, PictureBox PictBox) { try { PictBox.Image = F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Combox.SelectedItem.ToString())); } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Show_Image"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { //LLENA LA INFORMACION AL SELECCINAR UNA MATERIA PRIMA Show_Image("MP", comboBox1, pictureBox1); tabControl1.Enabled = true; ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); }

Page 69: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 427

if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox2.Text.ToString()); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); } int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); textBox1.Text = table.Rows[Index_on_access_table][4].ToString(); textBox2.Text = table.Rows[Index_on_access_table][5].ToString(); } else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Llenando Informacion de MP del Combobox11"); } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { try { //LLENA LA INFORMACION AL SELECCIONAR UNA OPERACION Show_Image("Operaciones", comboBox2, pictureBox2); ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas";

Page 70: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

428 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } Values.Add(comboBox2.Text.ToString()); int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Index_on_data_table = -1; //GET REAL INDEX for (int i = 0; i < table.Rows.Count; i++) { int Readed_indx = Convert.ToInt32(table.Rows[i][0].ToString()); if (Index_on_access_table == Readed_indx) { Index_on_data_table = i; } } textBox1.Text = table.Rows[Index_on_data_table][4].ToString(); textBox2.Text = table.Rows[Index_on_data_table][5].ToString(); }

Page 71: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 429

else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Llenando informacion de Operaciones del Combobox12"); } } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { try { //LLENA LA INFORMACION AL SELECCIONAR UN ALMACENAMIENTO Show_Image("Almacenamientos", comboBox3, pictureBox2); ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } Values.Add(comboBox3.Text.ToString());

Page 72: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

430 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int Index_on_data_table = -1; //GET REAL INDEX for (int i = 0; i < table.Rows.Count; i++) { int Readed_indx = Convert.ToInt32(table.Rows[i][0].ToString()); if (Index_on_access_table == Readed_indx) { Index_on_data_table = i; } } textBox1.Text = table.Rows[Index_on_data_table][4].ToString(); textBox2.Text = table.Rows[Index_on_data_table][5].ToString(); } else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Llenando informacion de almacenamientos del Combobox13"); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { try { if (tabControl1.SelectedIndex == 0) { if (comboBox2.SelectedIndex < 0) {

Page 73: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 431

pictureBox2.Image = null; } else { Show_Image("Operaciones", comboBox2, pictureBox2); } } if (tabControl1.SelectedIndex == 1) { if (comboBox3.SelectedIndex < 0) { pictureBox2.Image = null; } else { Show_Image("Almacenamientos", comboBox3, pictureBox2); } } ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } if (tabControl1.SelectedIndex == 0)

Page 74: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

432 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ Values.Add(comboBox2.Text.ToString()); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); } int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); textBox1.Text = table.Rows[Index_on_access_table][4].ToString(); textBox2.Text = table.Rows[Index_on_access_table][5].ToString(); } else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "tabControl1_SelectedIndexChanged"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX2 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox1.Text) == true) { e.Handled = true; }

Page 75: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 433

} catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Filtrando teclas en el teclado para TextBox2"); } } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX2 try { if (F.this_char_is_a_number_point_or_backspace(e.KeyChar, textBox2.Text) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Filtrando teclas en el teclado para TextBox2"); } } private void toolStripButton4_Click(object sender, EventArgs e) { try { //SHOW MISSING DATA INDICATORS if (comboBox1.SelectedIndex < 0 && comboBox2.SelectedIndex < 0) { pictureBox3.Show(); } if (pictureBox2.Image == null) { pictureBox4.Show(); } if (textBox1.Text == "") { pictureBox5.Show(); } if (textBox2.Text == "") { pictureBox6.Show(); } //HIDE MISSING DATA INDICATORS if (comboBox1.SelectedIndex >= 0 || comboBox2.SelectedIndex >= 0) { pictureBox3.Hide(); } if (pictureBox2.Image != null) { pictureBox4.Hide(); } if (textBox1.Text != "") { pictureBox5.Hide(); } if (textBox2.Text != "") { pictureBox6.Hide(); }

Page 76: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

434 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (textBox1.Text == "" || textBox2.Text == "" || pictureBox2.Image == null || pictureBox1.Image == null) { F.Show_Advisory_Message("Debe llenar los datos en los campos indicados", "Advertencia"); } else { F.Identify_folders(); //CHECK THE FOLDERS FOR THE PROGRAM AND CREATE THE MISSING ONES. ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //FILL THE COLUMS AND VALUES FOR CHECK IF EXIST A PRODUCT OR MP WITH THE SAME NAME Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox2.Text.ToString()); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); } bool Exist_on_Capacity = F.Exist_a_row_with_this_info_of_different_columns_on_Access_Table(Form1.Current_MRP, Table_name, Columns, Values);

Page 77: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 435

int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); //MessageBox.Show(Exist_on_Products.ToString() + " " + Exist_on_MP.ToString()); Columns.Clear(); Columns.Add("Index"); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Columns.Add("Tipo"); Columns.Add("Capacidad_requerida_Mano_de_obra"); Columns.Add("Capacidad_requerida_Maquinaria"); Values.Clear(); Values.Add(F.Get_right_index_to_add_Data_on_Access_Table(Form1.Current_MRP, Table_name)); //Obtiene el numero de productos en la tabla if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox2.Text.ToString()); Values.Add("Operaciones"); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); Values.Add("Almacenamientos"); } Values.Add(textBox1.Text.ToString()); Values.Add(textBox2.Text.ToString()); if (Exist_on_Capacity == false) { //IF DOESNT EXIST ADD IT

Page 78: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

436 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

F.AddDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values); } else { F.UpdateDataToAccessTable(Form1.Current_MRP, Table_name, Columns, Values, Index_on_access_table.ToString()); } } UpdateEventArgs6 args = new UpdateEventArgs6(""); IdentityUpdated6(this, args); this.Close(); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "toolStripButton4_Click"); } } private void comboBox5_SelectedIndexChanged(object sender, EventArgs e) { try { //LLENA LA INFORMACION AL SELECCINAR UNA MATERIA PRIMA Show_Image("Productos", comboBox5, pictureBox1); tabControl1.Enabled = true; ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); }

Page 79: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 437

if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); } if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox2.Text.ToString()); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); } int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); textBox1.Text = table.Rows[Index_on_access_table][4].ToString(); textBox2.Text = table.Rows[Index_on_access_table][5].ToString(); } else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Advisory_Message(Error.Message, "Llenando Informacion de MP del Combobox11"); } } private void tabControl2_SelectedIndexChanged(object sender, EventArgs e) { try

Page 80: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

438 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ if (tabControl2.SelectedIndex == 0) { if (comboBox1.SelectedIndex < 0) { pictureBox1.Image = null; } else { Show_Image("MP", comboBox1, pictureBox1); } } if (tabControl2.SelectedIndex == 1) { if (comboBox5.SelectedIndex < 0) { pictureBox1.Image = null; } else { Show_Image("Productos", comboBox5, pictureBox1); } } ArrayList Columns = new ArrayList(); ArrayList Values = new ArrayList(); string Table_name = "Capacidades_requeridas"; //LLENA LAS COLUMNAS Y VALORES PARA REVISAR SI EXISTE UN PRODUCTO O MP CON EL MISMO NOMBRE Columns.Clear(); Columns.Add("MP_Productos"); Columns.Add("Puesto_de_trabajo"); Values.Clear(); if (tabControl2.SelectedIndex == 0) { Values.Add(comboBox1.Text.ToString()); } if (tabControl2.SelectedIndex == 1) { Values.Add(comboBox5.Text.ToString()); }

Page 81: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 439

if (tabControl1.SelectedIndex == 0) { Values.Add(comboBox2.Text.ToString()); } if (tabControl1.SelectedIndex == 1) { Values.Add(comboBox3.Text.ToString()); } int Index_on_access_table = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Columns, Values); if (Index_on_access_table >= 0) { DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); textBox1.Text = table.Rows[Index_on_access_table][4].ToString(); textBox2.Text = table.Rows[Index_on_access_table][5].ToString(); } else { textBox1.Text = "0"; textBox2.Text = "0"; } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "tabControl2_SelectedIndexChanged"); } } } public class UpdateEventArgs6 : System.EventArgs { public string Image_path; public UpdateEventArgs6(string Path_of_image) { } } }

Page 82: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

440 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

E-6. VENTANA RESULTADOS MRP

using System; //using Microsoft.Office.Interop.Excel; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Functions; //using System.Reflection; //using Excel = Microsoft.Office.Interop.Excel; namespace MRProgram_00 { public partial class Form12 : Form { Functions.Operatives F = new Operatives(); //VARIABLES PARA LA TABLA DEL MRP DataTable MRP_Table = new DataTable(); DataTable Req_Table = new DataTable(); ArrayList Node_PrevNode = new ArrayList(); ArrayList MP_ordered_list = new ArrayList(); int Indx_to_change_batch_policy = 0; int Numero_periodos = 0; //DATATABLES DataTable Products_table = new DataTable(); DataTable MP_table = new DataTable(); DataTable Demand_table = new DataTable(); DataTable Inventary_forecast_table = new DataTable(); DataTable Orders_2_receiv_table = new DataTable(); DataTable Requiered_capacity = new DataTable(); DataTable Operations_table = new DataTable(); DataTable Storage_table = new DataTable(); DataTable Capacity_table = new DataTable(); DataTable Capacity_table_use_percent = new DataTable(); DataTable WorkStations_download = new DataTable(); //VARIABLES PARA EL TREEVIEW ArrayList Images_Names = new ArrayList(); ImageList imageList1 = new ImageList(); Dictionary<string, string> MP_req = new Dictionary<string, string>();

Page 83: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 441

//VARIABLES PARA LOS CALCULOS DE CAPACIDADES ArrayList Work_centers_capacity_MO = new ArrayList(); ArrayList Work_centers_capacity_MQ = new ArrayList(); ArrayList Cells_MO_capacity_out = new ArrayList(); ArrayList Cells_MQ_capacity_out = new ArrayList(); //VARIABLES PARA EXPORTAR DATOS int Clicked_datagridview = 0; int Selected_row_index = 0; public Form12() { InitializeComponent(); } private void Form12_Load(object sender, EventArgs e) { try { //LOAD DATATABLES Products_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Productos"); MP_table = F.Get_table_from_Access_File(Form1.Current_MRP, "MP"); Demand_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Demanda"); Inventary_forecast_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Stock_final_deseado"); Orders_2_receiv_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Pedidos_a_recibir"); Requiered_capacity = F.Get_table_from_Access_File(Form1.Current_MRP, "Capacidades_requeridas"); Operations_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Operaciones"); Storage_table = F.Get_table_from_Access_File(Form1.Current_MRP, "Almacenamientos"); //LLENAR LISTA DE PRODUCTOS Fill_Names_to_combobox("Productos", comboBox1, true); Fill_Names_to_combobox("MP", comboBox4, true); Fill_Names_to_combobox("Productos", comboBox5, true); //LLENAR LISTA PUESTOS DE TRABAJO (ITEMS -> operaciones y almacenamientos)

Page 84: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

442 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

Fill_Names_to_combobox("Almacenamientos", comboBox2, true); Fill_Names_to_combobox("Operaciones", comboBox2, false); if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Form12_Load"); } } #region Tab1_MP_Req private void Fill_Names_to_combobox(string Table_name, ComboBox Combox, bool Clear_combobox) { try { ArrayList List_of_Productos = new ArrayList(); DataTable table_Products = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); //CREATE AN ARRAYLIST WITH THE NAMES OF THE MP if (Clear_combobox) { Combox.Items.Clear(); } for (int i = 0; i < table_Products.Rows.Count; i++) { if (!List_of_Productos.Contains(table_Products.Rows[i][1].ToString())) { List_of_Productos.Add(table_Products.Rows[i][1].ToString()); Combox.Items.Add(table_Products.Rows[i][1].ToString()); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Fill_Names_to_combobox"); } } private void Fill_images_list_from_table(string Table_name) { try {

Page 85: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 443

DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); int count = table.Rows.Count; for (int i = 0; i < count; i++) { Images_Names.Add(table.Rows[i][1].ToString()); imageList1.Images.Add(F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", i)); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Fill_images_list_from_table"); } } private void Refresh_tree_images(TreeNode treeNode) { try { string node_name = F.Read_name(treeNode.Text); int Index = Images_Names.IndexOf(node_name); treeNode.ImageIndex = Index; treeNode.SelectedImageIndex = Index; foreach (TreeNode tn in treeNode.Nodes) { Refresh_tree_images(tn); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Refresh_tree_images"); } } private DataTable Calculate_quantity_requierements(int Factor) { DataTable table = new DataTable(); try {

Page 86: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

444 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

//HACE UN RECORRIDO A TRAVES DEL TREEVIEW PARA CALCULAR LOS REQUERIMIENTOS DE MP Through_nodes(treeView1, true); table.Columns.Add("MP"); table.Columns.Add("CANTIDAD"); //LLENA EL DATAGRIDVIEW1 CON LOS DATOS DE REQUERIMIENTOS DE MP foreach (KeyValuePair<string, string> pair in MP_req) { DataRow row = table.NewRow(); row["MP"] = pair.Key.ToString(); int Cant = Convert.ToInt32(pair.Value.ToString()); int Requiered_cant = Cant * Factor; row["CANTIDAD"] = Requiered_cant.ToString(); table.Rows.Add(row); //MessageBox.Show("Key_ " + pair.Key.ToString() + "val_" + pair.Value.ToString()); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_quantity_requierements"); } return table; } private void Calculate_requierements(TreeNode treeNode) { try { //MessageBox.Show("¬: " + treeNode.Text+" Factor:-> "+Read_cant(treeNode.Text)); foreach (TreeNode tn in treeNode.Nodes) { string node_name = F.Read_name(tn.Text); if (MP_req.ContainsKey(node_name) == true) { int Prev_qnty = Convert.ToInt32(MP_req[node_name].ToString());

Page 87: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 445

int New_qnty = Prev_qnty + F.Calculate_Quantity(tn.FullPath.ToString()); MP_req[node_name] = New_qnty.ToString(); //MessageBox.Show(node_name + "->> " + New_qnty); } else { MP_req.Add(F.Read_name(tn.Text), F.Calculate_Quantity(tn.FullPath.ToString()).ToString()); //MessageBox.Show(node_name + "->> " + F.Calculate_Quantity(tn.FullPath.ToString()).ToString()); } //MessageBox.Show("¬: " + tn.Text + " Path:-> " + Calculate_Quantity(tn.FullPath.ToString())); //MessageBox.Show("¬: " + treeNode.Text + " Factor:-> " + F.Read_cant(treeNode.Text) + "||" + "node: " + tn.Text + " total:-> " + total); } foreach (TreeNode tn in treeNode.Nodes) { Calculate_requierements(tn); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_requierements"); } } private DataTable Calculate_req_qntty_lead(TreeView treeView, int factor) { try { TreeNodeCollection nodes = treeView.Nodes; Req_Table.Clear(); //CALCULATE MRP LEAD & QNTY ALLOCATION if (Req_Table.Columns.Count <= 0) { Req_Table.Columns.Add("Item"); Req_Table.Columns.Add("Cantidad"); Req_Table.Columns.Add("Lead_Time"); Req_Table.Columns.Add("When is required"); Req_Table.Columns.Add("Previous Node");

Page 88: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

446 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} foreach (TreeNode n in nodes) { Calculate_requierements_WITH_LEAD_TIME(n); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_req_qntty_lead"); } return Req_Table; } private void Calculate_requierements_WITH_LEAD_TIME(TreeNode treeNode) { try { foreach (TreeNode tn in treeNode.Nodes) { //string node_name = F.Read_name(tn.Text); string node_name = tn.Text; //LEE EL FACTOR string value = textBox1.Text; if (value == "") { value = "0"; } int Factor = Convert.ToInt32(value); //CALCULA LA CANTIDAD NECESARIA //int Qnty = Factor * F.Calculate_Quantity(tn.FullPath.ToString()); int Qnty = F.Read_cant(node_name); //CALCULA EL LEAD TIME int Lead = F.Calculate_Lead(tn.FullPath.ToString(), Products_table, MP_table); int Lead_not_last = F.Calculate_Lead_NOT_INCLUDING_THE_LAST(tn.FullPath.ToString(), Products_table, MP_table); string Previous_node = F.Get_previous_node(tn.FullPath.ToString(), false); //AGREGA LOS RESULTADOS A LA TABLA DataRow row = Req_Table.NewRow(); row["Item"] = node_name; row["Cantidad"] = Qnty;

Page 89: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 447

row["Lead_Time"] = Lead; row["When is required"] = Lead_not_last; row["Previous Node"] = Previous_node; string Node_info = tn.Text + "|" + F.Get_previous_node(tn.FullPath.ToString(), false) + "|" + Qnty; if (!Node_PrevNode.Contains(Node_info)) { Node_PrevNode.Add(Node_info); } //MessageBox.Show(Node_info); Req_Table.Rows.Add(row); } foreach (TreeNode tn in treeNode.Nodes) { Calculate_requierements_WITH_LEAD_TIME(tn); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_requierements_WITH_LEAD_TIME"); } } private void Add_node_to_MP(TreeNode treeNode, ArrayList Products_list) { try { // HACE UN RECORRIDO NIVEL POR NIVEL EN EL ORDEN QUE SE ENCUENTRAN EN EL ARBOL DE PRODUCTO, PERO UNA MP PUEDE PERTENECER A VARIOS NIVELES foreach (TreeNode tn in treeNode.Nodes) { string node_name = tn.Text; string MP_name = F.Read_name(node_name); //AGREGA LOS RESULTADOS A LA LISTA if (!Products_list.Contains(MP_name)) { if (!MP_ordered_list.Contains(MP_name)) // SI NO ESTA EN LA LISTA LO AGREGA EN ULTIMO LUGAR { MP_ordered_list.Add(MP_name); }

Page 90: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

448 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

else { MP_ordered_list.Remove(MP_name); // SI YA ESTA EN LA LISTA LA BORRA (PERDIENDO EL LUGAR EN LA LISTA) MP_ordered_list.Add(MP_name); //Y LUEGO LA AGREGA AL FINAL, PARA GARANTIZAR QUE SE CALCULEN LOS REQUERIMIENTOS DE LOS OTROS ITEMS PRIMERO } } } foreach (TreeNode tn in treeNode.Nodes) { Add_node_to_MP(tn, Products_list); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Add_node_to_MP"); } } private ArrayList Get_MP_Ordered_list() { try { TreeNodeCollection nodes = treeView1.Nodes; ArrayList Products_list = new ArrayList(); MP_ordered_list.Clear(); for (int i = 0; i < Products_table.Rows.Count; i++) //LLENA LA LISTA DE PRODUCTOS { string Product_name = Products_table.Rows[i][1].ToString(); Products_list.Add(Product_name); } foreach (string producto in Products_list) { Select_a_Product_to_calculate_requirements(Products_table, "Productos", producto, true); foreach (TreeNode n in nodes) { Add_node_to_MP(n, Products_list); } } }

Page 91: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 449

catch (Exception Error) { F.Show_Error_Message(Error.Message, "Get_MP_Ordered_list"); } return MP_ordered_list; } private void Select_a_Product_to_calculate_requirements(DataTable table, string Table_name, string Name, bool inside) { try { if (inside == false) { textBox2.Text = Name; } int i = 0; while (table.Rows[i][1].ToString() != Name) { i++; } //Fill data if (inside == false) { textBox12.Text = table.Rows[i][2].ToString(); int Image_Index = F.Get_on_Access_Table_Index_of(Form1.Current_MRP, Table_name, Name); pictureBox18.Image = F.Get_image_from_database(Form1.Current_MRP, Table_name, "Imagen", "Index", Image_Index); Fill_images_list_from_table("MP"); Fill_images_list_from_table("Productos"); treeView1.ImageList = imageList1; } string Indx_on_table = table.Rows[i][0].ToString(); F.Get_file_from_database(Form1.Current_MRP, Table_name, "Arbol_de_producto", "Index", Indx_on_table); treeView1.Nodes.Clear();

Page 92: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

450 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

foreach (TreeNode node in F.Load_tree_from_file(F.Functions_folder + "\\" + "Tree_info_00.txt")) { //MessageBox.Show(Node.Text.ToString()); string node_name = node.Text; if (inside == false) { int Indx = Images_Names.IndexOf(node_name); node.ImageIndex = Indx; } TreeView tree = treeView1; tree.Nodes.Add(node); } if (inside == false) { //HACE UN RECORRIDO A TRAVES DEL TREEVIEW2 PARA MOSTRAR LAS IMAGENES ASOCIADAS A CADA NODO Through_nodes(treeView1, false); //CALCULAR REQUERIMIENTOS DE COMPONENTES MP_req.Clear(); dataGridView1.DataSource = Calculate_quantity_requierements(Convert.ToInt32(textBox1.Text)); dataGridView2.DataSource = Calculate_Capacity_requierements(); dataGridView4.DataSource = Calculate_req_qntty_lead(treeView1, Convert.ToInt32(textBox1.Text)); } treeView1.ExpandAll(); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Select_a_Product_to_calculate_requirements"); } } private void Through_nodes(TreeView treeView, bool Calculate_quantity) // if is true: Calculate_quantity else: Refresh_tree_images { try

Page 93: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 451

{ TreeNodeCollection nodes = treeView.Nodes; if (Calculate_quantity == true) { foreach (TreeNode n in nodes) { MP_req.Clear(); Calculate_requierements(n); } } else { foreach (TreeNode n in nodes) { Refresh_tree_images(n); } } dataGridView4.DataSource = Req_Table; } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Through_nodes"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Select_a_Product_to_calculate_requirements(Products_table, "Productos", comboBox1.SelectedItem.ToString(), false); //Select_a_Product_to_calculate_requirements("Productos", comboBox1.SelectedItem.ToString(), false); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { // SOLO PERMITE INTRODUCIR Y BORRAR DATOS NUMERICOS EN EL TEXTBOX2 try { if (F.this_char_is_a_number_or_backspace(e.KeyChar) == true) { e.Handled = true; } } catch (Exception Error) { F.Show_Error_Message(Error.ToString(), "Creando una nueva unidad -> Filtrando teclas en el teclado para TextBox2"); } } private DataTable Calculate_Capacity_requierements() {

Page 94: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

452 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

DataTable CPCTY_Req = new DataTable(); try { var tabl = dataGridView1.DataSource as DataTable; DataTable table = tabl.Copy(); DataTable Table_capacity = Requiered_capacity; //INSERT ON table THE PRODUCT DataRow new_row = table.NewRow(); new_row[0] = comboBox1.SelectedItem.ToString(); new_row[1] = textBox1.Text.ToString(); table.Rows.Add(new_row); ArrayList CPCTY_Req_Workstation = new ArrayList(); ArrayList CPCTY_Req_MO = new ArrayList(); ArrayList CPCTY_Req_MQ = new ArrayList(); for (int i = 0; i < table.Rows.Count; i++) { string MP_Name = table.Rows[i][0].ToString(); int Qnty = Convert.ToInt32(table.Rows[i][1].ToString()); for (int j = 0; j < Table_capacity.Rows.Count; j++) { string In_table_MP = Table_capacity.Rows[j][1].ToString(); //MessageBox.Show(In_table_MP); string Workstation = Table_capacity.Rows[j][2].ToString(); //MessageBox.Show(MP_Name + "--" + In_table_MP); if (MP_Name == In_table_MP) { if (CPCTY_Req_Workstation.Contains(Workstation)) { int Indx = CPCTY_Req_Workstation.IndexOf(Workstation); double MO = Convert.ToDouble(CPCTY_Req_MO[Indx].ToString()) + (Qnty * Convert.ToDouble(Table_capacity.Rows[j][4].ToString()));

Page 95: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 453

double MQ = Convert.ToDouble(CPCTY_Req_MQ[Indx].ToString()) + (Qnty * Convert.ToDouble(Table_capacity.Rows[j][5].ToString())); CPCTY_Req_MO[Indx] = MO; CPCTY_Req_MQ[Indx] = MQ; } else { CPCTY_Req_Workstation.Add(Workstation); CPCTY_Req_MO.Add(Qnty * Convert.ToDouble(Table_capacity.Rows[j][4].ToString())); CPCTY_Req_MQ.Add(Qnty * Convert.ToDouble(Table_capacity.Rows[j][5].ToString())); } //MessageBox.Show(MP_Name + "--" + In_table_MP); //MessageBox.Show(MP_Name + "--" + Workstation + "-> MO: " + Table_capacity.Rows[j][4].ToString() + " ->MQ: " + Table_capacity.Rows[j][5].ToString()); } } } //SHOW THE INFO CPCTY_Req.Columns.Add("Puesto_de_trabajo"); CPCTY_Req.Columns.Add("Requerimiento_Mano_de_Obra"); CPCTY_Req.Columns.Add("Requerimiento_Maquinaria"); for (int k = 0; k < CPCTY_Req_Workstation.Count; k++) { DataRow row; row = CPCTY_Req.NewRow(); row["Puesto_de_trabajo"] = CPCTY_Req_Workstation[k].ToString(); row["Requerimiento_Mano_de_Obra"] = CPCTY_Req_MO[k].ToString(); row["Requerimiento_Maquinaria"] = CPCTY_Req_MQ[k].ToString(); CPCTY_Req.Rows.Add(row); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_Capacity_requierements");

Page 96: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

454 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} return CPCTY_Req; } private void button1_Click(object sender, EventArgs e) { } #endregion; #region Solve_MRP private int Get_the_number_of_periods() { //READ THE INFO ABOUT FORECAST AND DEMAND OF ALL PRODUCTS AND MP, TO GET THE HIGEST PERIOD NUMBER int Number_of_periods = 0; try { ArrayList tables_to_check = new ArrayList(); tables_to_check.Add("Demanda"); tables_to_check.Add("Pedidos_a_recibir"); tables_to_check.Add("Stock_final_deseado"); foreach (string Table_name in tables_to_check) { DataTable table = new DataTable(); if (Table_name == "Demanda") { table = Demand_table; } if (Table_name == "Pedidos_a_recibir") { table = Orders_2_receiv_table; } if (Table_name == "Stock_final_deseado") { table = Inventary_forecast_table; } for (int i = 0; i < table.Rows.Count; i++) { int Period = Convert.ToInt32(table.Rows[i][2].ToString()); if (Period > Number_of_periods) { Number_of_periods = Period; } //MessageBox.Show(Number_of_periods + "|" + table.Rows[i][2].ToString()); } }

Page 97: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 455

Numero_periodos = Number_of_periods + 1; //AÑADE UNA COLUMNA EXTRA PARA LOS TOTALES DE LAS SUMAS HORIZONTALES } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Obteniendo el numero de periodos"); } return Number_of_periods; } private void Create_colums_for_MRP(int Number_of_periods) { //CREA LAS COLUMNAS EN LA TABLA DEL MRP try { MRP_Table.Clear(); MRP_Table.Columns.Clear(); for (int i = 0; i < Number_of_periods + 2; i++) { MRP_Table.Columns.Add(i.ToString()); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Creando columnas en la tabla del MRP"); } } private void Add_Tittle_row(string Tittle) { //AGREGA EL TITULO A CADA SECCION DEL MRP try { DataRow row = MRP_Table.NewRow(); row[0] = Tittle; MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Agregando titulo al MRP"); } }

Page 98: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

456 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

private void Add_Dat_row_to_table(DataTable Demand_table, string MP_Product_name, string Row_name) { try { DataRow row = MRP_Table.NewRow(); row[0] = Row_name; for (int j = 0; j < Demand_table.Rows.Count; j++) { if (MP_Product_name == Demand_table.Rows[j][1].ToString()) { int Period = Convert.ToInt32(Demand_table.Rows[j][2].ToString()); int Demanda = Convert.ToInt32(Demand_table.Rows[j][3].ToString()); //MessageBox.Show(MP_Product_name + "|" + Period + "|" + Demanda); row[Period] = Demanda; } } MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Add_Dat_row_to_table"); } } private void Add_Zero_row_to_table(string Row_name) { try { DataRow row = MRP_Table.NewRow(); row[0] = Row_name; for (int j = 1; j < Numero_periodos; j++) { int Period = j; int Demanda = 0; row[Period] = Demanda; }

Page 99: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 457

MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Add_Zero_row_to_table"); } } private void Summatory_of_rows(string Row_name) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; for (int j = 1; j < Numero_periodos; j++) { string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); string B = MRP_Table.Rows[Actual_row - 2][j].ToString(); if (A == "") { A = "0"; } if (B == "") { B = "0"; } double First_value = Convert.ToDouble(A); double Second_value = Convert.ToDouble(B); double Result = First_value + Second_value; //MessageBox.Show(First_value.ToString() +" + "+Second_value.ToString() + "= "+Result.ToString()); row[j] = Result; } MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Summatory_of_rows"); } }

Page 100: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

458 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

private void Add_Initial_inventory(DataTable table, string MP_Product_name, string Row_name) { try { //DataTable table = F.Get_table_from_Access_File(Form1.Current_MRP, Table_name); DataRow row = MRP_Table.NewRow(); row[0] = Row_name; for (int j = 0; j < table.Rows.Count; j++) { if (MP_Product_name == table.Rows[j][1].ToString()) { int Period = 1; int Demanda = Convert.ToInt32(table.Rows[j][4].ToString()); //MessageBox.Show(MP_Product_name + "|" + Period + "|" + Demanda); row[Period] = Demanda; } } MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Add_Initial_inventory"); } } private void Substract_of_rows_NO_INV(string Row_name) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; //MessageBox.Show(MRP_Table.Rows[Actual_row - 1][0].ToString() + "-" + MRP_Table.Rows[Actual_row - 4][0].ToString()); for (int j = 1; j < Numero_periodos; j++) {

Page 101: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 459

string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); string B = MRP_Table.Rows[Actual_row - 4][j].ToString(); if (A == "") { A = "0"; } if (B == "") { B = "0"; } int First_value = Convert.ToInt32(A); int Second_value = Convert.ToInt32(B); int Result = First_value - Second_value; //MessageBox.Show(A + "-" + B + "=" + Result); if (Result > 0) { int Result_02 = 0; row[j] = Result_02.ToString(); } else { int ABS = Math.Abs(Result); row[j] = ABS.ToString(); } } MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Substract_of_rows_NO_INV"); } } private void Substract_of_rows(string Row_name) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; MRP_Table.Rows.Add(row); //MessageBox.Show(MRP_Table.Rows[Actual_row - 1][0].ToString() + "-" + MRP_Table.Rows[Actual_row - 4][0].ToString()); for (int j = 1; j < Numero_periodos; j++) {

Page 102: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

460 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); string B = MRP_Table.Rows[Actual_row - 4][j].ToString(); if (A == "") { A = "0"; } if (B == "") { B = "0"; } int First_value = Convert.ToInt32(A); int Second_value = Convert.ToInt32(B); int Result = First_value - Second_value; if (Result > 0) { if (j + 1 < Numero_periodos) { A = MRP_Table.Rows[Actual_row - 1][j + 1].ToString(); if (A == "") { A = "0"; } First_value = Convert.ToInt32(A); Second_value = Result; int Result_02 = First_value + Second_value; MRP_Table.Rows[Actual_row - 2][j + 1] = Result.ToString(); MRP_Table.Rows[Actual_row - 1][j + 1] = Result_02.ToString(); } else { A = MRP_Table.Rows[Actual_row - 1][j].ToString(); First_value = Convert.ToInt32(A); Second_value = Result; int Result_02 = First_value + Second_value; //MessageBox.Show(MRP_Table.Rows[Actual_row - 1][j + 1] + "->" + Result_02.ToString()); MRP_Table.Rows[Actual_row - 1][j] = Result_02.ToString(); } } else { int ABS = Math.Abs(Result); MRP_Table.Rows[Actual_row][j] = ABS; } }

Page 103: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 461

} catch (Exception Error) { F.Show_Error_Message(Error.Message, "Substract_of_rows"); } } private void Locate_requeriments(string Row_name, int Lead_time, int TPL) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; MRP_Table.Rows.Add(row); //MessageBox.Show(Numero_periodos.ToString()); for (int j = 1; j < Numero_periodos; j++) { int Location = j - Lead_time; if (Location <= 1) { Location = 1; string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); if (A == "") { A = "0"; } int First_Value = Convert.ToInt32(A); string B = MRP_Table.Rows[Actual_row][1].ToString(); ; if (B == "") { B = "0"; } int Second_Value = Convert.ToInt32(B); int Result = First_Value + Second_Value; if (Result > 0 && Result < TPL) { Result = TPL; } MRP_Table.Rows[Actual_row][Location] = Result.ToString(); //MessageBox.Show(""); }

Page 104: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

462 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

else { string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); if (A == "") { A = "0"; } int First_Value = Convert.ToInt32(A); if (First_Value > 0 && First_Value < TPL) { First_Value = TPL; } MRP_Table.Rows[Actual_row][Location] = First_Value.ToString(); //MessageBox.Show(); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Locate_requeriments"); } } private void Locate_requeriments(string Row_name, int Lead_time) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; MRP_Table.Rows.Add(row); //MessageBox.Show(Numero_periodos.ToString()); for (int j = 1; j < Numero_periodos; j++) { int Location = j - Lead_time; if (Location <= 1) { Location = 1; string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); if (A == "") { A = "0"; } int First_Value = Convert.ToInt32(A);

Page 105: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 463

string B = MRP_Table.Rows[Actual_row][1].ToString(); ; if (B == "") { B = "0"; } int Second_Value = Convert.ToInt32(B); int Result = First_Value + Second_Value; MRP_Table.Rows[Actual_row][Location] = Result.ToString(); //MessageBox.Show(""); } else { string A = MRP_Table.Rows[Actual_row - 1][j].ToString(); if (A == "") { A = "0"; } MRP_Table.Rows[Actual_row][Location] = A.ToString(); //MessageBox.Show(); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Locate_requeriments"); } } private ArrayList Get_list_of_products(DataTable Products_table) { ArrayList the_list = new ArrayList(); try { //GET THE LIST OF PRODUCTS for (int j = 0; j < Products_table.Rows.Count; j++) { string Product_name = Products_table.Rows[j][1].ToString(); the_list.Add(Product_name); } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Creando lista de Productos");

Page 106: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

464 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} return the_list; } private ArrayList Get_list_of_prev_nodes(DataTable MP_Capacity_Req, string MP_name) { ArrayList the_list = new ArrayList(); try { //GET THE LIST OF PREVIOUS NODES for (int j = 0; j < MP_Capacity_Req.Rows.Count; j++) { string Node_name = MP_Capacity_Req.Rows[j][0].ToString(); string Prev_node_name = MP_Capacity_Req.Rows[j][4].ToString(); if (MP_name == Node_name) { the_list.Add(Prev_node_name); //MessageBox.Show(" MP: " + MP_name + " -> PrvNode: " + Prev_node_name); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Creando lista de Productos"); } return the_list; } private ArrayList Get_the_list_of_Nodes_PrevNodes(DataTable Products_table, ArrayList Products_list, string MP_Product_name) { ArrayList the_list = new ArrayList(); try { DataTable MP_Capacity_Req = new DataTable(); //LIMPIA LA LISTA DE NODES Y PREVNODES Node_PrevNode.Clear();

Page 107: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 465

foreach (string product in Products_list) { //CARGA EL ARBOL DE PRODUCTO CON EL PRODUCTO INDICADO Select_a_Product_to_calculate_requirements(Products_table, "Productos", product, true); //Select_a_Product_to_calculate_requirements("Productos", Reading_Product_name, true); // CALCULA LOS REQUERIMIENTOS DE MATERIALES PARA PRODUCIR UNA UNIDAD DEL PRODUCTO INDICADO MP_Capacity_Req = Calculate_req_qntty_lead(treeView1, 1); } foreach (string node in Node_PrevNode) { ArrayList parts = new ArrayList(); string[] Pieces = node.Split('|'); // PARTE EL PATH EN PEDAZOS foreach (string piece in Pieces) { parts.Add(piece); } string node_name = parts[0].ToString(); string only_node_name = F.Read_name(parts[0].ToString()); string prev_node_name = parts[1].ToString(); string only_prev_node_name = F.Read_name(parts[1].ToString()); string Factor = parts[2].ToString(); if (only_node_name == MP_Product_name) { the_list.Add(only_prev_node_name + " (" + Factor + ")"); //MessageBox.Show(MP_Product_name + "->" + only_prev_node_name + " (" + Factor + ")"); } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Listing Previous Nodes"); } return the_list; }

Page 108: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

466 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

private void Add_MP_Dat_row_to_table(DataTable Products_table, DataTable MP_table, string MP_Product_name, string Row_name) { try { ArrayList Products_list = Get_list_of_products(Products_table); DataTable MP_Capacity_Req = new DataTable(); //PARA ACUMULAR LA CANTIDAD REQUERIDA DE LA MATERIALES EN UN PERIODO <MP, PERIODO, CANTIDAD> ArrayList MP_item = new ArrayList(); ArrayList Period = new ArrayList(); ArrayList Quantity = new ArrayList(); ArrayList List_of_PrevNodes = Get_the_list_of_Nodes_PrevNodes(Products_table, Products_list, MP_Product_name);//obtiene una Tabla y calcula la informacion de requerimientos de capacidad para el ITEM especificado ArrayList PrevNodes_names = new ArrayList(); ArrayList PrevNodes_Qnty = new ArrayList(); // OBTIENE LA LISTA DE LOS NODOS PREVIOS PARA LOS MATERIALES PARA OBTENER EL FACTOR PARA CALCULAR LOS REQUERIMIENTOS TOTALES DE CANTIDAD foreach (string node in List_of_PrevNodes) { string name = F.Read_name(node); int qnty = F.Read_cant(node); PrevNodes_names.Add(name); PrevNodes_Qnty.Add(qnty); } //GET THE LIST OF ROWS IN THE MRP TABLE for (int l = 0; l < MRP_Table.Rows.Count; l++) { string Reading_Product_name = MRP_Table.Rows[l][0].ToString(); //SELECCIONA UN PRODUCTO O MATERIAL EN LA TABLA DEL MRP PARA OBTENER LA INFORMACION PARA REALIZAR LOS CALCULOS if (PrevNodes_names.Contains(Reading_Product_name))//revisa si el material (MP PP) esta en la tabla de requerimientos para el item que se analiza { //RECORRE LA TABLA DEL MRP DE MANERA HORIZONTAL PERIODO A PERIODO

Page 109: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 467

for (int _i = 1; _i < Numero_periodos; _i++) //READ THE PRODUCT QUANTITY REQUIEREMENT FOR EACH PERIOD { //FILL THE ROW WITH 0 TO AVOID ERRORS Period.Add(_i); Quantity.Add(0); string value = MRP_Table.Rows[l + 10][_i].ToString(); if (value == "") { value = "0"; } int Readed_value = Convert.ToInt32(value); //VALOR NECESARIO DEL PRODUCTO O MP EN UN PERIODO _i SEGUN LA COLOCACION DE REQUERIMIENTOS int Fact_Indx = PrevNodes_names.IndexOf(Reading_Product_name); int Factor = Convert.ToInt32(PrevNodes_Qnty[Fact_Indx].ToString()); //VALOR MULTIPLICANTE DE LA CANTIDAD DE REQUERIMIENTOS OBTENIDO DESDE EL ARBOL DE PRODUCTO int Total = Readed_value * Factor; // EL TOTAL REQUERIDO PARA EL PERIODO _i if (!Period.Contains(_i)) //CALCULA EL PERIODO ADECUADO PARA COLOCAR EL REQUERIMIENTO { Period.Add(_i); Quantity.Add(Total);//agrega el periodo y la cantidad si no existe en la coleccion } else { int indx = Period.IndexOf(_i); int Current = Convert.ToInt32(Quantity[indx].ToString()); int New = Current + (Total); //suma la cantidad al perido si existe en la coleccion Quantity[indx] = New; } } } } //AÑADE LOS RESULTADOS A LA TABLA DEL MRP DataRow row = MRP_Table.NewRow(); row[0] = Row_name; for (int k = 1; k < Numero_periodos; k++)

Page 110: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

468 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

{ int Indx = Period.IndexOf(k); if (Indx >= 0) { row[k] = Quantity[Indx].ToString(); } else { row[k] = "0"; } } MRP_Table.Rows.Add(row); } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Add_MP_Dat_row_to_table"); } } private void Calculate_POQ(DataTable MP_Products_table, DataTable Demand_table, string MP_Product_name, bool Is_product, string Row_name) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; int Numero_periodos_al_año = Convert.ToInt32(textBox6.Text); float Sum = 0; float a = 0; double average = 0; //OBTENER EL COSTO DE PEDIR U ORDENAR string Table_name = ""; if (Is_product == true) { Table_name = "Productos"; } else { Table_name = "MP"; } int Index_on_table = 0; for (int l = 0; l < MP_Products_table.Rows.Count; l++) {

Page 111: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 469

string Name_on_table = MP_Products_table.Rows[l][1].ToString(); if (Name_on_table == MP_Product_name) { Index_on_table = l; } } double Costo_de_pedir = 0; double Costo_de_almacenar = 0; double Demanda_anual = 0; double Tamaño_predeterminado_lote = 0; int Lead_time = 1; if (Is_product == true) { Costo_de_pedir = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][7].ToString()); Costo_de_almacenar = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][8].ToString()); Demanda_anual = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][10].ToString()); Tamaño_predeterminado_lote = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][11].ToString()); Lead_time = Convert.ToInt32(MP_Products_table.Rows[Index_on_table][6].ToString()); } else { Costo_de_pedir = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][7].ToString()); Costo_de_almacenar = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][8].ToString()); Demanda_anual = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][9].ToString()); Tamaño_predeterminado_lote = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][10].ToString()); Lead_time = Convert.ToInt32(MP_Products_table.Rows[Index_on_table][6].ToString()); } //MessageBox.Show("Indx" + Index_on_table + "|" + MP_Product_name + " Costo Pedir: " + Costo_de_pedir + " Costo Almacenar: " + Costo_de_almacenar + "Demanda anual" + Demanda_anual.ToString() + "Tamaño pred. lote" + Tamaño_predeterminado_lote.ToString()); for (int _i = 1; _i < Numero_periodos; _i++) {

Page 112: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

470 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

string value = MRP_Table.Rows[Actual_row - 1][_i].ToString(); if (value == "") { value = "0"; } Sum = Sum + Convert.ToInt32(value); //MessageBox.Show(value); } average = Sum / (Numero_periodos - 1); if (Demanda_anual == 0) { //average = Sum / (Numero_periodos - 1); a = (Sum / (Numero_periodos - 1)) * Numero_periodos_al_año; Demanda_anual = Convert.ToInt32(a); } double EOQ = 0; int EOQ_int = 0; if (Costo_de_almacenar == 0 ^ Numero_periodos_al_año == 0) { EOQ = 0; } else { //EOQ = Math.Sqrt((2 * Demanda_anual * Costo_de_pedir) / (Costo_de_almacenar * Numero_periodos_al_año)); EOQ = Math.Sqrt((2 * Demanda_anual * Costo_de_pedir) / (Costo_de_almacenar)); EOQ_int = Convert.ToInt32(EOQ); } double POQ = 0; int POQ_int = 0; //MessageBox.Show("Indx" + Index_on_table + "|" + MP_Product_name + " Costo Pedir: " + Costo_de_pedir + " Costo Almacenar: " + Costo_de_almacenar + "Demanda anual" + Demanda_anual.ToString() + "Tamaño pred. lote" + Tamaño_predeterminado_lote.ToString()); if (Costo_de_almacenar == 0 ^ Numero_periodos_al_año == 0) { EOQ = 0; POQ = 0; } else

Page 113: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 471

{ EOQ = Math.Sqrt((2 * Demanda_anual * Costo_de_pedir) / (Costo_de_almacenar)); EOQ = Math.Round(EOQ, 4); if (EOQ == 0) { POQ = 0; } else { POQ = EOQ / average; POQ = Math.Round(POQ, 4); } //MessageBox.Show(EOQ.ToString() + "|" + POQ.ToString()); POQ_int = Convert.ToInt32(POQ); if (POQ < 1) { POQ_int = 1; } } string Named_POQ = "POQ = " + POQ.ToString() + " = "; string Named_POQ_int = "POQ = " + POQ_int.ToString(); string Named_Lead_time = "Lead Time = " + Lead_time.ToString(); MRP_Table.Rows[Actual_row - 6][1] = Named_POQ; MRP_Table.Rows[Actual_row - 6][2] = Named_POQ_int; MRP_Table.Rows[Actual_row - 6][3] = Named_Lead_time; } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculate_POQ"); } } private int Calculate_EOQ(DataTable MP_Products_table, DataTable Demand_table, string MP_Product_name, bool Is_product, string Row_name, bool Use_TLP) { int EOQ_int = 0; try { DataRow row = MRP_Table.NewRow();

Page 114: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

472 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

int Actual_row = MRP_Table.Rows.Count; row[0] = Row_name; int Numero_periodos_al_año = Convert.ToInt32(textBox6.Text); float Sum = 0; float a = 0; //OBTENER EL COSTO DE PEDIR U ORDENAR string Table_name = ""; if (Is_product == true) { Table_name = "Productos"; } else { Table_name = "MP"; } int Index_on_table = 0; for (int l = 0; l < MP_Products_table.Rows.Count; l++) { string Name_on_table = MP_Products_table.Rows[l][1].ToString(); if (Name_on_table == MP_Product_name) { Index_on_table = l; } } double Costo_de_pedir = 0; double Costo_de_almacenar = 0; double Demanda_anual = 0; double Tamaño_predeterminado_lote = 0; if (Is_product == true) { Costo_de_pedir = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][7].ToString()); Costo_de_almacenar = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][8].ToString()); Demanda_anual = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][10].ToString()); Tamaño_predeterminado_lote = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][11].ToString());

Page 115: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 473

} else { Costo_de_pedir = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][7].ToString()); Costo_de_almacenar = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][8].ToString()); Demanda_anual = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][9].ToString()); Tamaño_predeterminado_lote = Convert.ToDouble(MP_Products_table.Rows[Index_on_table][10].ToString()); } //MessageBox.Show("Indx" + Index_on_table + "|" + MP_Product_name + " Costo Pedir: " + Costo_de_pedir + " Costo Almacenar: " + Costo_de_almacenar + "Demanda anual" + Demanda_anual.ToString() + "Tamaño pred. lote" + Tamaño_predeterminado_lote.ToString()); if (Demanda_anual == 0) { for (int _i = 1; _i < Numero_periodos; _i++) { string value = MRP_Table.Rows[Actual_row - 1][_i].ToString(); Sum = Sum + Convert.ToInt32(value); //MessageBox.Show(value); } a = (Sum / (Numero_periodos - 1)) * Numero_periodos_al_año; Demanda_anual = Convert.ToInt32(a); } double EOQ = 0; if (Costo_de_almacenar == 0 ^ Numero_periodos_al_año == 0) { EOQ = 0; } else { //EOQ = Math.Sqrt((2 * Demanda_anual * Costo_de_pedir) / (Costo_de_almacenar * Numero_periodos_al_año)); EOQ = Math.Sqrt((2 * Demanda_anual * Costo_de_pedir) / (Costo_de_almacenar)); EOQ_int = Convert.ToInt32(EOQ); //MessageBox.Show(message);

Page 116: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

474 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

} string Named_EOQ = "EOQ = " + EOQ.ToString(); string Named_EOQ_int = "EOQ = " + EOQ_int.ToString(); if (Use_TLP == true) { if (Tamaño_predeterminado_lote != 0) { Named_EOQ = "TLP = " + Tamaño_predeterminado_lote.ToString(); Named_EOQ_int = "TLP = " + Convert.ToInt32(Tamaño_predeterminado_lote); EOQ_int = Convert.ToInt32(Tamaño_predeterminado_lote); // MessageBox.Show(Readed_value_02); } } MRP_Table.Rows[Actual_row - 6][1] = Named_EOQ; MRP_Table.Rows[Actual_row - 6][2] = Named_EOQ_int; } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Calculando EOQ"); } return EOQ_int; } private void Adecuate_to_TML(int TLP, int Lead_time) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; for (int j = 1; j < MRP_Table.Columns.Count - 1; j++) { string data = ""; // OBTIENE EL INVENTARIO INICIAL DE LA COLUMNA string Inv_inic = MRP_Table.Rows[Actual_row - 3][j].ToString(); if (Inv_inic == "") { Inv_inic = "0"; }

Page 117: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 475

//MessageBox.Show(MRP_Table.Rows[Actual_row - 3][0].ToString() + ": " + Inv_inic + "\r\n"); int Inventario_inicial = Convert.ToInt32(Inv_inic); data = data + "Inventario Inicial: " + Inventario_inicial + "\r\n"; // OBTIENE LOS RECURSOS PROGRAMADOS DE LA COLUMNA string Rec_prog = MRP_Table.Rows[Actual_row - 4][j].ToString(); if (Rec_prog == "") { Rec_prog = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 4][0].ToString() + ": " + Rec_prog + "\r\n"); int Recursos_programados = Convert.ToInt32(Rec_prog); data = data + "Recursos_programados: " + Recursos_programados + "\r\n"; // OBTIENE LOS RECURSOS PROGRAMADOS NETOS int Recursos_prog_netos = Recursos_programados + Inventario_inicial; // MessageBox.Show(MRP_Table.Rows[Actual_row - 2][0].ToString()); MRP_Table.Rows[Actual_row - 2][j] = Recursos_prog_netos; data = data + "RPN: " + Recursos_prog_netos + "\r\n"; // OBTIENE LOS REQUERIMIENTOS NETOS string Req_net = MRP_Table.Rows[Actual_row - 5][j].ToString(); if (Req_net == "") { Req_net = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 5][0].ToString() + ": " + Req_net + "\r\n"); int Requerimientos_netos = Convert.ToInt32(Req_net); data = data + "Requerimientos_netos: " + Requerimientos_netos + "\r\n"; // CALCULA INVENTARIO END INICIAL int Inv_Final = Recursos_prog_netos - Requerimientos_netos; //MessageBox.Show("Prod_req_ini = " + Produccion_requerida_inicial); int Next_Inventario_inicial = 0; data = data + "Next_Inventario_inicial: " + Next_Inventario_inicial + "\r\n"; // OBTIENE LA PRODUCCION REQUERIDA int Produccion_requerida_inicial = Recursos_prog_netos - Requerimientos_netos; data = data + "Produccion_requerida_inicial: " + Produccion_requerida_inicial + "\r\n"; //MessageBox.Show("Periodo: " + j + "\r\n" + data);

Page 118: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

476 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

if (Produccion_requerida_inicial >= 0) { MRP_Table.Rows[Actual_row - 1][j] = 0; MRP_Table.Rows[Actual_row - 6][j] = Inv_Final; Next_Inventario_inicial = Inv_Final; MRP_Table.Rows[Actual_row - 3][j + 1] = Next_Inventario_inicial; //MessageBox.Show(j + ">=0: " + " Inv Final / Next Init-> " + Inv_Final); } if (Produccion_requerida_inicial < 0) { if (Math.Abs(Produccion_requerida_inicial) < TLP) { MRP_Table.Rows[Actual_row - 1][j] = Math.Abs(Produccion_requerida_inicial); Inv_Final = TLP + Recursos_prog_netos - Requerimientos_netos; MRP_Table.Rows[Actual_row - 6][j] = Inv_Final; Next_Inventario_inicial = Inv_Final; MRP_Table.Rows[Actual_row - 3][j + 1] = Next_Inventario_inicial; } else { MRP_Table.Rows[Actual_row - 1][j] = Math.Abs(Produccion_requerida_inicial); Inv_Final = Math.Abs(Produccion_requerida_inicial) + Recursos_prog_netos - Requerimientos_netos; MRP_Table.Rows[Actual_row - 6][j] = Inv_Final; Next_Inventario_inicial = Inv_Final; MRP_Table.Rows[Actual_row - 3][j + 1] = Next_Inventario_inicial; } } } }

Page 119: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 477

catch (Exception Error) { F.Show_Error_Message(Error.Message, "Adecuate_to_TML"); } } private void Adecuate_to_TLP(int TLP, int Lead_time) { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; for (int j = 1; j < MRP_Table.Columns.Count - 1; j++) { // OBTIENE EL INVENTARIO INICIAL DE LA COLUMNA string Inv_inic = MRP_Table.Rows[Actual_row - 3][j].ToString(); if (Inv_inic == "") { Inv_inic = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 3][0].ToString() + ": " + Inv_inic + "\r\n"); int Inventario_inicial = Convert.ToInt32(Inv_inic); // OBTIENE LOS RECURSOS PROGRAMADOS DE LA COLUMNA string Rec_prog = MRP_Table.Rows[Actual_row - 4][j].ToString(); if (Rec_prog == "") { Rec_prog = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 4][0].ToString() + ": " + Rec_prog + "\r\n"); int Recursos_programados = Convert.ToInt32(Rec_prog); // OBTIENE LOS RECURSOS PROGRAMADOS NETOS int Recursos_prog_netos = Recursos_programados + Inventario_inicial; // MessageBox.Show(MRP_Table.Rows[Actual_row - 2][0].ToString()); MRP_Table.Rows[Actual_row - 2][j] = Recursos_prog_netos; // OBTIENE LOS REQUERIMIENTOS NETOS string Req_net = MRP_Table.Rows[Actual_row - 5][j].ToString(); if (Req_net == "") { Req_net = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 5][0].ToString() + ": " + Req_net + "\r\n"); int Requerimientos_netos = Convert.ToInt32(Req_net); // CALCULA LA PRODUCCION REQUERIDA INICIAL

Page 120: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

478 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

int Produccion_requerida_inicial = Recursos_prog_netos - Requerimientos_netos; //MessageBox.Show("Prod_req_ini = " + Produccion_requerida_inicial); int Next_Inventario_inicial = 0; if (Produccion_requerida_inicial < 0) { Produccion_requerida_inicial = TLP; MRP_Table.Rows[Actual_row - 1][j] = Produccion_requerida_inicial; Next_Inventario_inicial = Produccion_requerida_inicial - Requerimientos_netos + Recursos_prog_netos; } else { Produccion_requerida_inicial = 0; MRP_Table.Rows[Actual_row - 1][j] = Produccion_requerida_inicial; Next_Inventario_inicial = Recursos_prog_netos - Requerimientos_netos; //MRP_Table.Rows[Actual_row - 1][j] = "0"; //MessageBox.Show("Produccion_requerida_inicial = (" + Recursos_programados + " + " + Inventario_inicial + ") - " + Requerimientos_netos); } if (j < MRP_Table.Columns.Count - 1) { MRP_Table.Rows[Actual_row - 6][j] = Next_Inventario_inicial.ToString(); //COLOCA EL INVENTARIO FINAL EN EL ACTUAL PERIODO } if (j < MRP_Table.Columns.Count - 2) //EVITA AÑADIR EL INVENTARIO INICIAL A LA COLUMNA DE RESULTADOS HORIZONTALES { MRP_Table.Rows[Actual_row - 3][j + 1] = Next_Inventario_inicial.ToString(); //COLOCA EL NUEVO INVENTARIO INICIAL EN EL SIGUIENTE PERIODO } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Adecuate_to_TLP");

Page 121: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 479

} } private void Adecuate_to_EOQ() { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; int EOQ = 0; for (int i = 1; i < MRP_Table.Columns.Count; i++)//OBTENER EL EOQ { string K = MRP_Table.Rows[Actual_row - 10][i].ToString(); ; if (K == "") { K = "0"; } if (i == 2) { //MessageBox.Show(K); ArrayList Parts = new ArrayList(); string[] pieces = K.Split(Convert.ToChar("=")); foreach (string piece in pieces) { Parts.Add(piece); } int Count_max = Parts.Count - 1; if (Parts[Count_max].ToString() == "") { Parts.RemoveAt(Count_max); } EOQ = Convert.ToInt32(Parts[1].ToString()); } } for (int j = 1; j < MRP_Table.Columns.Count - 1; j++) { // OBTIENE EL INVENTARIO INICIAL DE LA COLUMNA string Inv_inic = MRP_Table.Rows[Actual_row - 3][j].ToString(); if (Inv_inic == "") { Inv_inic = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 3][0].ToString() + ": " + Inv_inic + "\r\n"); int Inventario_inicial = Convert.ToInt32(Inv_inic); // OBTIENE LOS RECURSOS PROGRAMADOS DE LA COLUMNA

Page 122: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

480 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP

string Rec_prog = MRP_Table.Rows[Actual_row - 4][j].ToString(); if (Rec_prog == "") { Rec_prog = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 4][0].ToString() + ": " + Rec_prog + "\r\n"); int Recursos_programados = Convert.ToInt32(Rec_prog); // OBTIENE LOS RECURSOS PROGRAMADOS NETOS int Recursos_prog_netos = Recursos_programados + Inventario_inicial; // MessageBox.Show(MRP_Table.Rows[Actual_row - 2][0].ToString()); MRP_Table.Rows[Actual_row - 2][j] = Recursos_prog_netos; // OBTIENE LOS REQUERIMIENTOS NETOS string Req_net = MRP_Table.Rows[Actual_row - 5][j].ToString(); if (Req_net == "") { Req_net = "0"; } //MessageBox.Show(MRP_Table.Rows[Actual_row - 5][0].ToString() + ": " + Req_net + "\r\n"); int Requerimientos_netos = Convert.ToInt32(Req_net); // CALCULA LA PRODUCCION REQUERIDA INICIAL int Produccion_requerida_inicial = Recursos_prog_netos - Requerimientos_netos; //MessageBox.Show("Prod_req_ini = " + Produccion_requerida_inicial); int Next_Inventario_inicial = 0; if (Produccion_requerida_inicial < 0) { Produccion_requerida_inicial = EOQ; MRP_Table.Rows[Actual_row - 1][j] = Produccion_requerida_inicial; Next_Inventario_inicial = Produccion_requerida_inicial - Requerimientos_netos + Recursos_prog_netos; } else { Produccion_requerida_inicial = 0; MRP_Table.Rows[Actual_row - 1][j] = Produccion_requerida_inicial; Next_Inventario_inicial = Recursos_prog_netos - Requerimientos_netos; //MRP_Table.Rows[Actual_row - 1][j] = "0"; //MessageBox.Show("Produccion_requerida_inicial = (" +

Page 123: E-2. CÓDIGO VENTANA DE CREACIÓN / EDICIÓN DE MATERIAS PRIMAS ... · 358 Desarrollo de un prototipo informático de soporte al enfoque de programación de la producción MRP E-2.

Anexo 481

Recursos_programados + " + " + Inventario_inicial + ") - " + Requerimientos_netos); } if (j < MRP_Table.Columns.Count - 1) { MRP_Table.Rows[Actual_row - 6][j] = Next_Inventario_inicial.ToString(); //COLOCA EL INVENTARIO FINAL EN EL ACTUAL PERIODO } if (j < MRP_Table.Columns.Count - 2) //EVITA AÑADIR EL INVENTARIO INICIAL A LA COLUMNA DE RESULTADOS HORIZONTALES { MRP_Table.Rows[Actual_row - 3][j + 1] = Next_Inventario_inicial.ToString(); //COLOCA EL NUEVO INVENTARIO INICIAL EN EL SIGUIENTE PERIODO } } } catch (Exception Error) { F.Show_Error_Message(Error.Message, "Adecuate_to_EOQ"); } } private void Adecuate_to_POQ() { try { DataRow row = MRP_Table.NewRow(); int Actual_row = MRP_Table.Rows.Count; int POQ = 0; int Lead_time = 1; for (int i = 1; i < MRP_Table.Columns.Count; i++)//OBTENER EL EOQ { string K = MRP_Table.Rows[Actual_row - 10][i].ToString(); ; if (K == "") { K = "0"; } if (i == 2 || i == 3) // OBTENER EL VALOR DE POQ { //MessageBox.Show(K); ArrayList Parts = new ArrayList(); string[] pieces = K.Split(Convert.ToChar("="));