Exemple #1
0
 public void Create(Refaction refaction)
 {
     try
     {
         Database.Connect();
         command = new OdbcCommand
         {
             Connection  = Database.GetConn(),
             CommandType = CommandType.StoredProcedure,
             CommandText = "{call csg.Refaction_Create(?,?,?,?,?)}"
         };
         command.Parameters.Add("Code", OdbcType.VarChar, 50).Value        = refaction.Refaction_code;
         command.Parameters.Add("Description", OdbcType.VarChar, 50).Value = refaction.Refaction_description;
         command.Parameters.Add("UnitPrice", OdbcType.VarChar, 14).Value   = refaction.Refaction_unit_price;
         command.Parameters.Add("CreateBy", OdbcType.VarChar, 50).Value    = UserCache.UserCode;
         command.Parameters.Add("CreateDate", OdbcType.DateTime).Value     = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
         if (command.ExecuteNonQuery() > 0)
         {
             MessageBox.Show("Repuesto creado exitosamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("No se ha creado el repuesto", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Excepción controlada en RefactionDAO->Create: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Database.Disconnect();
     }
 }
        private void IbtnAddRefaction_Click(object sender, EventArgs e)
        {
            string text = txtRefactionCode.Text;

            string[] words = text.Split(' ');
            if (refactionLog.Read_once_exist(words[0]))
            {
                Refaction refaction = refactionLog.Read_once(words[0]);
                //Validar que no exista codigo en la tabla
                //if (SearchDtCode(dtr, words[0]))
                //{
                if (SearchDtCode(dtr, words[0]))
                {
                    row    = dtr.NewRow();
                    row[0] = refaction.Refaction_code;
                    row[1] = refaction.Refaction_description;
                    row[2] = Convert.ToInt32(NupQR.Value);
                    dtr.Rows.Add(row);
                }
                else
                {
                    MessageBox.Show("El repuesto ya se agregó al equipo");
                }
            }
            txtRefactionCode.Clear();
            txtRefactionCode.Focus();
        }
Exemple #3
0
        public List <Refaction> Read_all()
        {
            List <Refaction> refactions = new List <Refaction>();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Refaction_ReadAll}"
                };
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Refaction refaction = new Refaction
                    {
                        Refaction_code        = dataReader.GetString(0),
                        Refaction_description = dataReader.GetString(1),
                        Refaction_unit_price  = dataReader.GetString(2)
                    };
                    refactions.Add(refaction);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en RefactionDAO->Read_all: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(refactions);
        }
Exemple #4
0
 private void TxtCode_Leave(object sender, EventArgs e)
 {
     if (!txtCode.Text.Equals(""))
     {
         bool response = refactionLog.Read_once_exist(txtCode.Text);
         if (response)
         {
             DialogResult dr = MessageBox.Show("El repuesto que intenta crear ya existe. ¿Desea cargar la información en el formulario?", "Mensaje",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dr == DialogResult.Yes)
             {
                 //Consultamos el cliente con el Id como parametro.
                 Refaction refaction = refactionLog.Read_once(txtCode.Text);
                 //Desactivamos los campos ineditables.
                 txtCode.Enabled = false;
                 //Cambiamos el tipo de accion del boton
                 IbtnCreate.Text = "Guardar";
                 IbtnNew.Enabled = true;
                 //Llenamos los campos.
                 txtCode.Text      = refaction.Refaction_code;
                 txtDesc.Text      = refaction.Refaction_description;
                 txtUnitPrice.Text = refaction.Refaction_unit_price.ToString();
                 txtObs.Text       = "";
             }
             else
             {
                 txtCode.Clear();
                 txtCode.Focus();
             }
         }
     }
 }
Exemple #5
0
        //private void CreateHeaders()
        //{
        //    DgvRefaction.Columns[0].HeaderText = "Código";
        //    DgvRefaction.Columns[1].HeaderText = "Descripción";
        //    DgvRefaction.Columns[2].HeaderText = "Precio Unitario";
        //}

        private void IbtnCreate_Click(object sender, EventArgs e)
        {
            if (IbtnCreate.Text.Equals("Crear"))
            {
                if (ValidateFields())
                {
                    Refaction refaction = new Refaction(txtCode.Text, txtDesc.Text, txtUnitPrice.Text);
                    CleanFields();
                    refactionLog.Create(refaction);
                    IbtnRefresh_Click(null, e);
                    IbtnNew.Enabled = false;
                }
            }
            else if (IbtnCreate.Text.Equals("Guardar"))
            {
                if (ValidateFields())
                {
                    //Guardamos
                    Refaction refaction = new Refaction(txtCode.Text, txtDesc.Text, txtUnitPrice.Text);
                    CleanFields();
                    refactionLog.Update(refaction);
                    IbtnRefresh_Click(null, e);
                    //cambiamos botones
                    txtCode.Enabled = true;
                    txtCode.Focus();
                    IbtnCreate.Text = "Crear";
                    IbtnNew.Enabled = false;
                }
            }
        }
        private void AddRefactions()
        {
            List <Cotization_refactionFK> cotization_RefactionFKs = cotizationRefactionLog.Read_RefactionsOfCotization(txtCotizationId.Text);

            foreach (var cr in cotization_RefactionFKs)
            {
                Refaction refaction = refactionLog.Read_once(cr.Refaction_code);
                //Console.WriteLine("Code: {0} | Descripción: {1}", refaction.Refaction_code, refaction.Refaction_description);
                row    = dtsr.NewRow();
                row[0] = "Refacción";
                row[1] = refaction.Refaction_code;
                row[2] = refaction.Refaction_description;
                row[3] = cr.Refaction_quantity;
                row[4] = decimal.Parse(refaction.Refaction_unit_price, culture).ToString("C2");
                row[5] = decimal.Parse(cr.Refaction_amount, culture).ToString("C2");
                dtsr.Rows.Add(row);
            }
        }
Exemple #7
0
        public Refaction Read_once(string code)
        {
            Refaction refaction = new Refaction();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Refaction_ReadOnce(?)}"
                };
                command.Parameters.Add("Code", OdbcType.VarChar, 50).Value = code;
                dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    refaction = new Refaction
                    {
                        Refaction_code        = dataReader.GetString(0),
                        Refaction_description = dataReader.GetString(1),
                        Refaction_unit_price  = dataReader.GetString(2)
                    };
                }
                else
                {
                    refaction = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en RefactionDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(refaction);
        }
Exemple #8
0
        private void BtnRun_Click(object sender, EventArgs e)
        {
            //Qué entidad vamos a afectar
            MessageBox.Show("Crear en: " + cboSheet.SelectedItem.ToString());
            string entity = cboSheet.SelectedItem.ToString();

            if (entity.Equals("ARTICULOS"))
            {
                //creamos la lista de Articulos
                List <Article> articles = new List <Article>();
                //recorremos el DataGridView y agregamos cada fila a la lista
                int rows = DgvVisor.RowCount;
                MessageBox.Show("Cantidad de filas: " + rows);
                for (int i = 0; i < rows; i++)
                {
                    Article a = new Article
                    {
                        Article_code        = DgvVisor.Rows[i].Cells[0].Value.ToString(),
                        Article_description = DgvVisor.Rows[i].Cells[1].Value.ToString(),
                        //Article_model = DgvVisor.Rows[i].Cells[2].Value.ToString(),
                        //Article_serial = DgvVisor.Rows[i].Cells[3].Value.ToString(),
                        Article_warranty = int.Parse(DgvVisor.Rows[i].Cells[4].Value.ToString()),
                        Create_by        = "Bulkload",
                        Create_date      = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                    };
                    articles.Add(a);
                }
                //Enviamos a la logica para que haga cada uno de los insert
                txtResult.Text = bulkLoadLog.BulkLoadArticle(articles);
            }
            else if (entity.Equals("CLIENTES"))
            {
                //creamos la lista de Clientes
                List <Client> clients = new List <Client>();
                //recorremos el DataGridView y agregamos cada fila a la lista
                int rows = DgvVisor.RowCount;
                MessageBox.Show("Cantidad de filas: " + rows);
                for (int i = 0; i < rows; i++)
                {
                    Client c = new Client
                    {
                        Client_id         = DgvVisor.Rows[i].Cells[0].Value.ToString(),
                        Client_name       = DgvVisor.Rows[i].Cells[1].Value.ToString(),
                        Client_address    = DgvVisor.Rows[i].Cells[2].Value.ToString(),
                        Client_location   = DgvVisor.Rows[i].Cells[3].Value.ToString(),
                        Client_city       = DgvVisor.Rows[i].Cells[4].Value.ToString(),
                        Client_department = DgvVisor.Rows[i].Cells[5].Value.ToString(),
                        Client_tel1       = DgvVisor.Rows[i].Cells[6].Value.ToString(),
                        Client_tel2       = DgvVisor.Rows[i].Cells[7].Value.ToString(),
                        Client_email      = DgvVisor.Rows[i].Cells[8].Value.ToString(),
                    };
                    clients.Add(c);
                }
                //Enviamos a la logica para que haga cada uno de los insert
                txtResult.Text = bulkLoadLog.BulkLoadClient(clients);
            }
            else if (entity.Equals("REFACCIONES"))
            {
                //creamos la lista de Refactions
                List <Refaction> refactions = new List <Refaction>();
                //recorremos el DataGridView y agregamos cada fila a la lista
                int rows = DgvVisor.RowCount;
                MessageBox.Show("Cantidad de filas: " + rows);
                for (int i = 0; i < rows; i++)
                {
                    Refaction r = new Refaction
                    {
                        Refaction_code        = DgvVisor.Rows[i].Cells[0].Value.ToString(),
                        Refaction_description = DgvVisor.Rows[i].Cells[1].Value.ToString(),
                        Refaction_unit_price  = DgvVisor.Rows[i].Cells[2].Value.ToString()
                    };
                    refactions.Add(r);
                }
                //Enviamos a la logica para que haga cada uno de los insert
                txtResult.Text = bulkLoadLog.BulkLoadRefaction(refactions);
            }
            else if (entity.Equals("SERVICIOS"))
            {
                //creamos la lista de Services
                List <Service> services = new List <Service>();
                //recorremos el DataGridView y agregamos cada fila a la lista
                int rows = DgvVisor.RowCount;
                MessageBox.Show("Cantidad de filas: " + rows);
                for (int i = 0; i < rows; i++)
                {
                    Service s = new Service
                    {
                        Service_code     = DgvVisor.Rows[i].Cells[0].Value.ToString(),
                        Service_activity = DgvVisor.Rows[i].Cells[1].Value.ToString(),
                        Service_duration = DgvVisor.Rows[i].Cells[2].Value.ToString(),
                        Service_cost     = decimal.Round(decimal.Parse(DgvVisor.Rows[i].Cells[3].Value.ToString()), 2).ToString().Replace(',', '.'),
                        Service_type     = char.Parse(DgvVisor.Rows[i].Cells[4].Value.ToString())
                    };
                    services.Add(s);
                    Console.WriteLine(
                        //"Codigo: " + "(" + s.Service_code.Length + ")" + s.Service_code +
                        //"  | Activity: " + "(" + s.Service_activity.Length + ")" + s.Service_activity +
                        //" | Duration: " + s.Service_duration + "(" + s.Service_duration.Length + ")" +
                        " | Cost: " + "(" + s.Service_cost.Length + ")" + s.Service_cost +
                        " | Type: " + "(" + s.Service_type.ToString().Length + ")" + s.Service_type);
                }
                //Enviamos a la logica para que haga cada uno de los insert
                txtResult.Text = bulkLoadLog.BulkLoadService(services);
            }
            else if (entity.Equals("TECNICOS"))
            {
                //creamos la lista de Technicians
                List <Technician> technicians = new List <Technician>();
                //recorremos el DataGridView y agregamos cada fila a la lista
                int rows = DgvVisor.RowCount;
                MessageBox.Show("Cantidad de filas: " + rows);
                for (int i = 0; i < rows; i++)
                {
                    Technician t = new Technician
                    {
                        Technician_id        = DgvVisor.Rows[i].Cells[0].Value.ToString(),
                        Technician_name      = DgvVisor.Rows[i].Cells[1].Value.ToString(),
                        Technician_contact   = DgvVisor.Rows[i].Cells[2].Value.ToString(),
                        Technician_alias     = DgvVisor.Rows[i].Cells[3].Value.ToString(),
                        Technician_telephone = DgvVisor.Rows[i].Cells[4].Value.ToString(),
                        Technician_position  = DgvVisor.Rows[i].Cells[5].Value.ToString(),
                        Create_by            = "Bulkload",
                        Create_date          = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                    };
                    technicians.Add(t);
                }
                //Enviamos a la logica para que haga cada uno de los insert
                txtResult.Text = bulkLoadLog.BulkLoadTechnician(technicians);
            }
        }
        private void IbtnUpdate_Click(object sender, EventArgs e)
        {
            CultureInfo culture = new CultureInfo("en-US");

            if (ValidateData())
            {
                DateTime   localDate  = DateTime.Now;
                Cotization cotization = new Cotization();
                cotization.Cotization_id = order.Cotization.Cotization_id;
                cotization.Cotization_generation_date = DateTime.Parse(localDate.ToString("yyyy-MM-dd HH:mm:ss"));
                //Calculamos la cantidad de servicios y repuestos
                byte quantity = 0;
                quantity = Convert.ToByte(dts.Rows.Count + dtr.Rows.Count);
                cotization.Cotization_quantity = quantity;
                //Capturamos los comentarios técnicos
                cotization.Cotization_comentarys = txtComentarys.Text;
                //Calculamos el subtotal
                Decimal Dsubtotal = 0m;
                //Obtenemos la suma de los servicios
                for (int i = 0; i < dts.Rows.Count; i++)
                {
                    Service service = serviceLog.Read_once(dts.Rows[i][0].ToString());
                    //Creamos cotization_service (DETALLES)
                    Cotization_serviceFK cotization_ServiceFK = new Cotization_serviceFK
                    {
                        Cotization_id    = order.Cotization.Cotization_id,
                        Service_code     = service.Service_code,
                        Actionof         = txtArticleCode.Text,
                        Service_quantity = Convert.ToByte(dts.Rows[i][2].ToString()),
                    };
                    //Capturamos el costo en string
                    string strCost = service.Service_cost;
                    //Lo convertimos a decimal
                    decimal decCost = decimal.Parse(strCost, culture);
                    //Lo multiplicamos por la cantidad
                    decimal decAmount = decCost * cotization_ServiceFK.Service_quantity;
                    //Lo agregamos al objeto en formato string
                    cotization_ServiceFK.Service_amount = decAmount.ToString().Replace(',', '.');
                    //Lo sumamos en el subtotal
                    Dsubtotal += decAmount;
                    //Creamos el objeto cotization service
                    cotizationServiceLog.Create(cotization_ServiceFK);
                }
                //Obtenemos la suma de los repuestos
                for (int i = 0; i < dtr.Rows.Count; i++)
                {
                    Refaction refaction = refactionLog.Read_once(dtr.Rows[i][0].ToString());
                    //Creamos cotization_refaction (DETALLES)
                    Cotization_refactionFK cotization_RefactionFK = new Cotization_refactionFK
                    {
                        Cotization_id      = order.Cotization.Cotization_id,
                        Refaction_code     = refaction.Refaction_code,
                        Replacementof      = txtArticleCode.Text,
                        Refaction_quantity = Convert.ToByte(dtr.Rows[i][2].ToString()),
                    };
                    //Capturamos el precio unitario en string
                    string strPrice = refaction.Refaction_unit_price;
                    //Lo convertimos a decimal
                    decimal decPrice = decimal.Parse(strPrice, culture);
                    //Lo multiplicamos por la cantidad
                    decimal decAmountr = decPrice * cotization_RefactionFK.Refaction_quantity;
                    //Lo agregamos al objeto en formato string
                    cotization_RefactionFK.Refaction_amount = decAmountr.ToString().Replace(',', '.');
                    //Lo sumamos en el subtotal
                    Dsubtotal += decAmountr;
                    //Creamos el objeto cotization refaction
                    cotizationRefactionLog.Create(cotization_RefactionFK);
                    //subtotal += Decimal.Parse(cotization_RefactionFK.Refaction_amount);
                }
                Console.WriteLine("Subtotal decimal: " + Dsubtotal);
                Console.WriteLine("Subtotal string: " + Dsubtotal.ToString().Replace(',', '.'));
                cotization.Cotization_subtotal = Dsubtotal.ToString().Replace(',', '.');
                //Definimos el descuento->preguntar a EVANS si maneja descuento
                cotization.Cotization_discount = "0";
                //DEfinimos el IVA del subtotal->por ahora se hará con el 19%. pero se debe tener en cuenta el IVA
                //Consultamos el iva codigo 19
                decimal im = taxLog.Read_once_value("19");
                //Calculamos el IVA
                decimal iva = Dsubtotal * im;
                //Agregamos el string del iva al objeto cotization
                cotization.Cotization_iva = iva.ToString().Replace(',', '.');
                decimal total = Dsubtotal + iva;
                cotization.Cotization_total = total.ToString().Replace(',', '.');
                //Agregamos el usuario que la actualizará
                cotization.Update_by = UserCache.UserAccount;
                //Agregamos la fecha de actualizacion
                cotization.Update_date = cotization.Cotization_generation_date;
                //Actualizamos la cotización
                cotizationLog.Update(cotization);
                //Cambiamos el estado de la orden
                orderLog.UpdateState(order.Order_number, "Cotizada");
                DialogResult = DialogResult.Yes;
                this.Close();
            }
        }
Exemple #10
0
 public void Update(Refaction refaction)
 {
     DAOFactory.GetRefactionDAO().Update(refaction);
 }
Exemple #11
0
 public void Create(Refaction refaction)
 {
     DAOFactory.GetRefactionDAO().Create(refaction);
 }