public void SaveOp2(CS_CustQuotasOperation op)
        {
            try
            {
                op.CostOperation = string.IsNullOrEmpty(op.CostOperation.ToString()) ? 0 : op.CostOperation;
                string sql = @"INSERT INTO CS_CustQuotasOperation (
                    Id, Line, Operation, DescriptionOperation, TimeProcessStr, Item, BOM, Obs, 
                    TBCreated, TBModified, TBCreatedID, CostOperation, UoM, Qty
                )" + $" VALUES ( {op.Id}, {op.Line}, '{op.Operation}', '{op.DescriptionOperation}', '{op.TimeProcessStr}'," +
                             $"'{op.Item}', '{op.BOM}', '{op.Obs}', '{op.TBCreated}'," +
                             $"'{op.TBModified}', {op.TBCreatedID}, {op.CostOperation.ToString().Replace(",", ".")}, '{ op.UoM }', { op.Qty })";

                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
 public List <CS_CustQuotasOperation> GetSimulationOperations2_2(int id, string item)
 {
     //return _context.CS_CustQuotasOperation.Where(x => x.Id == id && x.BOM == item).ToList();
     try
     {
         List <CS_CustQuotasOperation> listOp = new List <CS_CustQuotasOperation>();
         conn.Open();
         string        sql    = $"SELECT *, (SELECT ISNULL(AdditionalCost, 0) FROM MA_Operations WHERE Operation = CQ.Operation) AS Cost FROM CS_CustQuotasOperation CQ WHERE id = { id } AND BOM = '{ item }'";
         SqlCommand    cmd    = new SqlCommand(sql, conn);
         SqlDataReader reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             CS_CustQuotasOperation op = new CS_CustQuotasOperation();
             op.Id                   = Convert.ToInt32(reader["Id"]);
             op.Line                 = Convert.ToInt32(reader["Line"]);
             op.Operation            = reader["Operation"].ToString().Trim();
             op.DescriptionOperation = reader["DescriptionOperation"].ToString().Trim();
             op.TimeProcess          = Convert.ToDateTime(reader["TimeProcess"]);
             op.Item                 = reader["Item"].ToString().Trim();
             op.BOM                  = reader["BOM"].ToString().Trim();
             op.Obs                  = reader["Obs"].ToString().Trim();
             op.TimeProcessStr       = reader["TimeProcessStr"].ToString();
             double valor = OperationView.CalculateCostOperation(reader["TimeProcessStr"].ToString(), Convert.ToDouble(reader["Cost"]));
             op.CostOperation = Math.Round(valor, 2);
             op.UoM           = reader["UoM"].ToString().Trim();
             op.Qty           = string.IsNullOrEmpty(reader["Qty"].ToString()) ? 0 : Convert.ToDouble(reader["Qty"]);
             listOp.Add(op);
         }
         conn.Close();
         return(listOp);
     }
     catch (Exception ex)
     {
         conn.Close();
         throw ex;
     }
 }
        public List <CS_CustQuotasOperation> GetSimulationOperations(int id, string item)
        {
            //return _context.CS_CustQuotasOperation.Where(x => x.Id == id && x.Item == item).ToList();
            List <CS_CustQuotasOperation> list = new List <CS_CustQuotasOperation>();

            try
            {
                conn.Open();
                string        sql    = $"SELECT * FROM CS_CustQuotasOperation WHERE Id = { id } AND Item = '{ item }'";
                SqlCommand    cmd    = new SqlCommand(sql, conn);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    CS_CustQuotasOperation op = new CS_CustQuotasOperation();
                    op.Id            = Convert.ToInt32(reader["Id"]);
                    op.Line          = Convert.ToInt32(reader["Line"]);
                    op.Item          = reader["Item"].ToString();
                    op.Obs           = reader["Obs"].ToString();
                    op.Operation     = reader["Operation"].ToString();
                    op.TimeProcess   = string.IsNullOrEmpty(reader["TimeProcess"].ToString()) ? Convert.ToDateTime(DateTime.Now.ToShortDateString()) : Convert.ToDateTime(reader["TimeProcess"]);
                    op.BOM           = reader["BOM"].ToString();
                    op.CostOperation = string.IsNullOrEmpty(reader["CostOperation"].ToString()) ? 0 : Convert.ToDouble(reader["CostOperation"]);

                    list.Add(op);
                }

                conn.Close();
                reader.Close();
                return(list);
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
 public void SaveOp(CS_CustQuotasOperation op)
 {
     _context.CS_CustQuotasOperation.Add(op);
     _context.SaveChanges();
 }