Exemplo n.º 1
0
        public void pubCadastraStatus(modStatus status)
        {
            using (sqlCon = new SqlConnection(strCon))
            {
                if (sqlCon != null)
                {
                    cmd             = new SqlCommand("USP_STATUS_CADASTRO", sqlCon);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@DESCRICAO", status.descricao);

                    try
                    {
                        sqlCon.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        throw new Exception("USP_STATUS_CADASTRO = : " + e.Message);
                    }

                    finally
                    {
                        FechaConexao();
                    }
                }
                else
                {
                    throw new Exception("Problema ao tentar executar requisição!");
                }
            }
        }
Exemplo n.º 2
0
        public void pubRemoveStatusPorId(modStatus status)
        {
            using (sqlCon = new SqlConnection(strCon))
            {
                if (strCon != null)
                {
                    cmd             = new SqlCommand("USP_STATUS_DELETE", sqlCon);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@ID_STATUS", status.idStatus);

                    try
                    {
                        sqlCon.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        throw new Exception("USP_STATUS_DELETE - :" + e.Message);
                    }
                    finally
                    {
                        FechaConexao();
                    }
                }
                else
                {
                    throw new Exception("Problema ao tentar executar requisição!");
                }
            }
        }
Exemplo n.º 3
0
        public modStatus pubBuscaStatusPorId(int id)
        {
            objDr = null;

            using (sqlCon = new SqlConnection(strCon))
            {
                if (sqlCon != null)
                {
                    cmd             = new SqlCommand("USP_STATUS_LISTA_POR_ID", sqlCon);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@ID_STATUS", id);

                    try
                    {
                        sqlCon.Open();
                        objDr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        modStatus sts = null;

                        while (objDr.Read())
                        {
                            sts = new modStatus();

                            sts.idStatus  = Convert.ToInt32(objDr["ID_STATUS"]);
                            sts.descricao = objDr["DESCRICAO"].ToString();
                        }

                        return(sts);
                    }
                    catch (SqlException e)
                    {
                        throw new Exception("[USP_STATUS_LISTA_POR_ID] - : " + e.Number + " - Descrição: " + e.Message.ToString());
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Problema com a consulta informada : " + ex.Message);
                    }
                    finally
                    {
                        FechaConexao();
                    }
                }
                else
                {
                    throw new Exception("Problema com a conexão ao banco de dados! ");
                }
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(modStatus status)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _db.pubCadastraStatus(status);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(status));
                }
            }
            return(View());
        }
Exemplo n.º 5
0
        public IActionResult Create(modStatus status)
        {
            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        _db.pubCadastraStatus(status);

            //        return RedirectToAction("Index");
            //    }
            //    catch
            //    {
            //        return View(status);
            //    }
            //}
            return(View());
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id, modStatus status)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    status.idStatus = id;
                    _db.pubAtualizaStatus(status);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(status));
                }
            }
            return(View());
        }
Exemplo n.º 7
0
        public IActionResult Edit(int id, modStatus status)
        {
            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        status.idStatus = id;
            //        _db.pubAtualizaStatus(status);

            //        return RedirectToAction("Index");
            //    }
            //    catch
            //    {
            //        return View(status);
            //    }
            //}
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult Delete(int id, modStatus status)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    status.idStatus = id;

                    _db.pubRemoveStatusPorId(status);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(status));
                }
            }
            return(View());
        }
Exemplo n.º 9
0
        public IActionResult Delete(int id, modStatus status)
        {
            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        status.idStatus = id;

            //        _db.pubRemoveStatusPorId(status);

            //        return RedirectToAction("Index");
            //    }
            //    catch
            //    {
            //        return View(status);
            //    }
            //}
            return(View());
        }
Exemplo n.º 10
0
        public List <modStatus> pubListaStatus()
        {
            List <modStatus> statuss = new List <modStatus>();

            using (sqlCon = new SqlConnection(strCon))
            {
                objDr = null;

                cmd             = new SqlCommand("USP_STATUS_LISTA", sqlCon);
                cmd.CommandType = CommandType.StoredProcedure;

                try
                {
                    sqlCon.Open();

                    objDr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                    modStatus sts = null;

                    while (objDr.Read())
                    {
                        sts = new modStatus();

                        sts.idStatus  = Convert.ToInt32(objDr["ID_STATUS"].ToString());
                        sts.descricao = objDr["DESCRICAO"].ToString();

                        statuss.Add(sts);
                    }

                    return(statuss);
                }
                catch (Exception e)
                {
                    throw new Exception("USP_STATUS_LISTA - : " + e.Message);
                }

                finally
                {
                    FechaConexao();
                }
            }
        }
Exemplo n.º 11
0
        public void RealWork()
        {
            //try
            //{
            string Checksum;

            //dummy here
            while (Work)
            {
                //set ild, update data
                //form the command

                string s = System.Text.Encoding.GetEncoding(1252).GetString(new byte[2] {
                    0x81, 0x12
                });
                s = s + this.Iset + ";";                                           //Iset0
                s = s + (int)0 + ";";                                              //Iset1
                {                                                                  //forming "command" sequence
                    int tmp = 0;
                    tmp = tmp + (int)Math.Pow(2, 0) * Convert.ToInt32(EmissionOn); //emission
                    tmp = tmp + (int)Math.Pow(2, 1) * 0;                           //DAC0 Iset
                    tmp = tmp + (int)Math.Pow(2, 2) * 0;                           //No residual current
                    tmp = tmp + (int)Math.Pow(2, 3) * Convert.ToInt32(QCWmode);    //external start
                    if (resetError)
                    {
                        tmp = tmp + (int)Math.Pow(2, 4) * 1;    //reset errors
                    }
                    else
                    {
                        tmp = tmp + (int)Math.Pow(2, 4) * 0;                    //reset errors
                    }
                    tmp = tmp + (int)Math.Pow(2, 5) * 0;                        //disable module emission (for single module operation)
                    tmp = tmp + (int)Math.Pow(2, 6) * Convert.ToInt32(QCWmode); //Pulsed mode
                    s   = s + tmp.ToString() + ";";

                    resetError = false;
                }

                s        = s + (int)1 + ";";//???adress
                Checksum = Crc16.ComputeChecksum(Encoding.GetEncoding(1252).GetBytes(s)).ToString();
                s        = s + Checksum;

                //wait
                try
                {
                    s = writeGetDataCom(s, true);
                    int index = s.IndexOf(System.Text.Encoding.GetEncoding(1252).GetString(new byte[2] {
                        0x81, 0x12
                    }));
                    if (s.IndexOf(System.Text.Encoding.GetEncoding(1252).GetString(new byte[2] {
                        0x81, 0x12
                    })) == 0)
                    {
                        //strip s from 1st two system symbols
                        s = s.Remove(0, 2);
                        string[] tmp = s.Split(';');
                        //1st string is output power
                        //clear it off control signals
                        tmp[0]        = new String(tmp[0].Where(c => char.IsDigit(c)).ToArray());
                        DataMod.Power = Convert.ToDouble(tmp[0]);    //2nd string is Temp*10
                        DataMod.Temp  = Convert.ToDouble(tmp[1]) / 10;
                        //3rd, 4th, 5th, 6th, 7th and 8th is Current 1 * 100
                        DataMod.ILD1 = Convert.ToDouble(tmp[2]) / 100;
                        DataMod.ILD2 = Convert.ToDouble(tmp[3]) / 100;
                        DataMod.ILD3 = Convert.ToDouble(tmp[4]) / 100;
                        DataMod.ILD4 = Convert.ToDouble(tmp[5]) / 100;
                        DataMod.ILD5 = Convert.ToDouble(tmp[6]) / 100;
                        DataMod.ILD6 = Convert.ToDouble(tmp[7]) / 100;
                        //8th is PD1
                        DataMod.PD1 = Convert.ToInt32(tmp[8]);
                        //9th is PD2
                        DataMod.PD2 = Convert.ToInt32(tmp[9]);
                        //10th is PD3
                        DataMod.PD3 = Convert.ToInt32(tmp[10]);
                        //11th is PD4
                        DataMod.PD4 = Convert.ToInt32(tmp[11]);
                        //12th is PD5
                        DataMod.PD5 = Convert.ToInt32(tmp[12]);
                        //13th is Uset
                        DataMod.Uset = Convert.ToDouble(tmp[13]);
                        //14th is PS Voltage * 10
                        DataMod.PSVoltage = Convert.ToDouble(tmp[14]) / 10;
                        //15th is Status

                        int Status = Convert.ToInt32(tmp[15]);
                        //Debug.WriteLine("Status=" + Status.ToString());
                        this.Status.Emission         = GetBit(Status, 0);
                        this.Status.Enabled          = GetBit(Status, 1);
                        this.Status.PowerSupply      = GetBit(Status, 2);
                        this.Status.ExternalStart    = GetBit(Status, 3);
                        this.Status.ExternalShutdown = GetBit(Status, 4);
                        this.Status.PulsedMode       = GetBit(Status, 6);
                        this.Status.Error            = GetBit(Status, 8);



                        //17th is Alarms
                        Status          = Convert.ToInt32(tmp[16]);
                        this.Alarms.PD1 = GetBit(Status, 0);
                        this.Alarms.PD2 = GetBit(Status, 1);
                        this.Alarms.PD3 = GetBit(Status, 2);
                        this.Alarms.PD4 = GetBit(Status, 3);
                        this.Alarms.PD5 = GetBit(Status, 4);

                        this.Alarms.Overheat    = GetBit(Status, 5);
                        this.Alarms.CurrentLeak = GetBit(Status, 6);
                        this.Alarms.PowerSupply = GetBit(Status, 7);
                        this.Alarms.CS1         = GetBit(Status, 8);
                        this.Alarms.CS2         = GetBit(Status, 9);
                        this.Alarms.CS3         = GetBit(Status, 10);
                        this.Alarms.CS4         = GetBit(Status, 11);
                        this.Alarms.CS5         = GetBit(Status, 12);
                        this.Alarms.CS6         = GetBit(Status, 13);

                        this.Alarms.UnexpectedPump1 = GetBit(Status, 14);
                        this.Alarms.UnexpectedPump2 = GetBit(Status, 15);
                        this.Alarms.UnexpectedPump3 = GetBit(Status, 16);
                        this.Alarms.UnexpectedPump4 = GetBit(Status, 17);
                        this.Alarms.UnexpectedPump5 = GetBit(Status, 18);
                        this.Alarms.UnexpectedPump6 = GetBit(Status, 19);

                        this.Alarms.DutyCycle = GetBit(Status, 20);
                    }
                }
                catch (TimeoutException ex)
                {
                    DataMod.Power = 0;                    //2nd string is Temp*10
                    DataMod.Temp  = 0;
                    //3rd, 4th, 5th, 6th, 7th and 8th is Current 1 * 100
                    DataMod.ILD1 = 0;
                    DataMod.ILD2 = 0;
                    DataMod.ILD3 = 0;
                    DataMod.ILD4 = 0;
                    DataMod.ILD5 = 0;
                    DataMod.ILD6 = 0;
                    //8th is PD1
                    DataMod.PD1 = 0;
                    //9th is PD2
                    DataMod.PD2 = 0;
                    //10th is PD3
                    DataMod.PD3 = 0;
                    //11th is PD4
                    DataMod.PD4 = 0;
                    //12th is PD5
                    DataMod.PD5 = 0;
                    //13th is Uset
                    DataMod.Uset = 0;
                    //15th is Status

                    //Debug.WriteLine("Status=" + Status.ToString());
                    this.Status.Emission         = false;
                    this.Status.Enabled          = false;
                    this.Status.PowerSupply      = false;
                    this.Status.ExternalStart    = false;
                    this.Status.ExternalShutdown = false;
                    this.Status.PulsedMode       = false;
                    this.Status.Error            = false;



                    //17th is Alarms

                    this.Alarms.PD1 = false;
                    this.Alarms.PD2 = false;
                    this.Alarms.PD3 = false;
                    this.Alarms.PD4 = false;
                    this.Alarms.PD5 = false;

                    this.Alarms.Overheat    = false;
                    this.Alarms.CurrentLeak = false;
                    this.Alarms.PowerSupply = false;
                    this.Alarms.CS1         = false;
                    this.Alarms.CS2         = false;
                    this.Alarms.CS3         = false;
                    this.Alarms.CS4         = false;
                    this.Alarms.CS5         = false;
                    this.Alarms.CS6         = false;

                    this.Alarms.UnexpectedPump1 = false;
                    this.Alarms.UnexpectedPump2 = false;
                    this.Alarms.UnexpectedPump3 = false;
                    this.Alarms.UnexpectedPump4 = false;
                    this.Alarms.UnexpectedPump5 = false;
                    this.Alarms.UnexpectedPump6 = false;

                    this.Alarms.DutyCycle = false;
                    //this.Alarms.TimeOut = true;
                }

                Thread.Sleep(50);
                RaiseNewDataAvaliable();
            }
            //}

            /*
             * catch (TimeoutException ex)
             * {
             *  Work = false;
             *  ComPort.Close();
             * }*/
        }