private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     try
     {
         if (lineBackup == null)
         {
             lineBackup = data.NewProductionLine(line.Name, line.Capacity, line.Efficiency);
             line.Id = lineBackup.Id;
         }
         else
         {
             data.UpdateProductionLine(line, lineBackup);
             lineBackup.Name = line.Name;
             lineBackup.Capacity = line.Capacity;
             lineBackup.Efficiency = line.Efficiency;
             lineBackup.Active = line.Active;
         }
     }
     catch { }
 }
 public void DeleteProductionLine(ProductionLine line)
 {
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         if (connection.State != ConnectionState.Open)
             connection.Open();
         // delete record from table
         DeleteProductionLine(connection, line);
     }
 }
        private void DeleteProductionLine(OracleConnection connection, ProductionLine line)
        {
            OracleCommand cmd = connection.CreateCommand();
            cmd.CommandText = "delete from tis_vyrobni_linka where vyrobni_linka_id = :1";
            cmd.Parameters.Add(GetNumber(":1", line.Id));
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();

            cmd.Dispose();
        }
 public void UpdateProductionLine(ProductionLine newLine, ProductionLine oldLine)
 {
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         if (connection.State != ConnectionState.Open)
             connection.Open();
         // update record in table
         UpdateProductionLine(connection, newLine, oldLine);
     }
 }
 public Plan ProductionStart(ProductionLine line)
 {
     Plan plan = null;
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         if (connection.State != ConnectionState.Open)
             connection.Open();
         // update record in table
         Nullable<int> planId = ProductionStart(connection, line);
         if (planId != null)
             plan = GetPlan(connection, (int)planId);
     }
     return plan;
 }
 public void ProductionEnd(ProductionLine line)
 {
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         if (connection.State != ConnectionState.Open)
             connection.Open();
         // update record in table
         ProductionEnd(connection, line);
     }
 }
 public Plan GetProductionLinePlan(ProductionLine line)
 {
     Plan plan = null;
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         if (connection.State != ConnectionState.Open)
             connection.Open();
         // select record from table
         plan = GetProductionLinePlan(connection, line);
     }
     return plan;
 }
        private void UpdateProductionLine(OracleConnection connection, ProductionLine newLine, ProductionLine oldLine)
        {
            if (newLine.Id != oldLine.Id) // probably different production lines - wrong input
                return;

            OracleCommand cmd = connection.CreateCommand();
            cmd.CommandText = "update tis_vyrobni_linka set ";
            cmd.CommandType = CommandType.Text;

            int paramIdx = 1;
            paramIdx = AddUpdateField(cmd, "nazev", paramIdx, CheckForInjection(newLine.Name), oldLine.Name);
            paramIdx = AddUpdateField(cmd, "kapacita", paramIdx, newLine.Capacity, oldLine.Capacity);
            paramIdx = AddUpdateField(cmd, "vykonnost", paramIdx, newLine.Efficiency, oldLine.Efficiency);
            paramIdx = AddUpdateField(cmd, "aktivni", paramIdx, newLine.Active, oldLine.Active);
            if (paramIdx > 1)
            {
                cmd.CommandText += " where vyrobni_linka_id = :" + paramIdx.ToString();
                cmd.Parameters.Add(GetNumber(":" + paramIdx.ToString(), newLine.Id));
                cmd.ExecuteNonQuery();
            }
            cmd.Dispose();
        }
        private Nullable<int> ProductionStart(OracleConnection connection, ProductionLine line)
        {
            OracleCommand cmd = connection.CreateCommand();
            cmd.CommandText = "TIS.vyroba_start";
            cmd.CommandType = CommandType.StoredProcedure;
            OracleParameter res = cmd.Parameters.Add("result", OracleType.Int32);
            res.Direction = ParameterDirection.ReturnValue;
            OracleParameter par = cmd.Parameters.Add("p_vyrobni_linka_id", OracleType.Number);
            par.Value = line.Id;
            cmd.ExecuteNonQuery();

            Nullable<int> planId = null;
            try
            {
                planId = Convert.ToInt32(res.Value);
            }
            catch { }
            cmd.Dispose();

            return planId;
        }
        private void ProductionEnd(OracleConnection connection, ProductionLine line)
        {
            OracleCommand cmd = connection.CreateCommand();
            cmd.CommandText = "TIS.vyroba_konec";
            cmd.CommandType = CommandType.StoredProcedure;
            OracleParameter par = cmd.Parameters.Add("p_vyrobni_linka_id", OracleType.Number);
            par.Value = line.Id;
            cmd.ExecuteNonQuery();

            cmd.Dispose();
        }
        private Plan GetProductionLinePlan(OracleConnection connection, ProductionLine line)
        {
            Plan plan = null;

            OracleCommand cmd = connection.CreateCommand();
            cmd.CommandText = "select * from " +
                                "(select * from tis_plan where vyrobni_linka_id = :1 order by datum_vyroba_start desc)" +
                                " where rownum = 1";
            cmd.Parameters.Add(GetNumber(":1", line.Id));
            OracleDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                Nullable<int> orderId = null;
                if (!reader.IsDBNull(2))
                    orderId = reader.GetInt32(2);
                Nullable<DateTime> dateStart = null;
                if (!reader.IsDBNull(5))
                    dateStart = reader.GetDateTime(5);
                Nullable<DateTime> dateEnd = null;
                if (!reader.IsDBNull(6))
                    dateEnd = reader.GetDateTime(6);
                plan = GetPlan(reader.GetInt32(0), reader.GetInt32(1), orderId, line.Id,
                    reader.GetDateTime(4), dateStart, dateEnd, reader.GetInt32(7), reader.GetString(8));
                plan.ProductionLine = line;
            }

            cmd.Dispose();

            if (plan != null)
            {
                // get product - musts be new query
                plan.Product = GetProduct(connection, plan.ProductId);
                // get order - musts be new query
                if (plan.OrderId != null)
                    plan.Order = GetOrder(connection, (int)plan.OrderId);
            }

            return plan;
        }
 private void EditLine(ProductionLine editLine)
 {
     line = new ProductionLine();
     if (editLine != null)
     {
         line.Id = editLine.Id;
         line.Name = editLine.Name;
         line.Capacity = editLine.Capacity;
         line.Efficiency = editLine.Efficiency;
         line.Active = editLine.Active;
     }
     gridEdit.DataContext = line;
 }