예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            int             ListPersonelCount;
            scalesEntities2 bd = new scalesEntities2();

            try
            {
                ListPersonelCount = bd.Personal.Where(p => p.Name == login.Text).Count();
            }
            catch (Exception)
            {
                MessageBox.Show("Не все поля заполнены!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (ListPersonelCount > 0)
            {
                MessageBox.Show("Такой пользователь уже существует", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                bool chek = false;
                if (login.Text == "")
                {
                    chek = true;
                }
                if (passwred.Text == "")
                {
                    chek = true;
                }
                if (roleCombo.SelectedIndex < 1)
                {
                    chek = true;
                }

                if (chek == true)
                {
                    MessageBox.Show("Не все поля заполнены!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    Personal pNew = new Personal();
                    pNew.Name     = login.Text.ToLower();
                    pNew.Password = passwred.Text.ToLower();
                    pNew.Role     = roleCombo.SelectedIndex;
                    int roleID = roleCombo.SelectedIndex;
                    bd.Personal.Add(pNew);
                    bd.SaveChanges();
                    bd.Dispose();
                    MessageBox.Show("Пользователь добавлен!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    login.Text              = "";
                    passwred.Text           = "";
                    roleCombo.SelectedIndex = 0;
                    TreeUsers(roleID);
                }
            }
        }
예제 #2
0
        private void удалитьУстройствоToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                scalesEntities2 bd = new scalesEntities2();

                if (delDevice.Level == 0)
                {
                    IQueryable <ScalesInformation> x = bd.ScalesInformation.Where(p => p.IPaddress == delDevice.Text);
                    foreach (var item in x)
                    {
                        bd.ScalesInformation.Remove(item);
                    }
                    bd.SaveChanges();
                    bd.Dispose();
                    treeView1.Nodes.Remove(delDevice);
                    DeviceInBD();
                    MessageBox.Show("Группа устройств удалена!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    string Eq = delDevice.Text.Split(' ')[1];
                    var    x  = bd.ScalesInformation.Where(p => p.ModbusID == Eq && p.IPaddress == delDevice.Parent.Text).First();
                    bd.ScalesInformation.Remove(x);
                    bd.SaveChanges();
                    bd.Dispose();
                    treeView1.Nodes.Remove(delDevice);
                    DeviceInBD();
                    MessageBox.Show("Устройство удалено!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Выберите устройство!\nДля этого нажмите на узел ЛК мышки.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
예제 #3
0
 private void удалитьПользователяToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         scalesEntities2 bd = new scalesEntities2();
         var             x  = bd.Personal.Where(p => p.Name == delUser.Text).First();
         bd.Personal.Remove(x);
         bd.SaveChanges();
         bd.Dispose();
         treeView2.Nodes.Remove(delUser);
         MessageBox.Show("Пользователь удален!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     catch (Exception)
     {
     }
 }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Match m = Regex.Match(textBox1.Text, patternIP);//проверяем правильно ли введен ІР-адрес в текстовое поле

            if (m.Success)
            {
                Match m2 = Regex.Match(textBox2.Text, patternMODBUS);//проверяем правильно ли введен ІР-адрес в текстовое поле
                if (m2.Success)
                {
                    scalesEntities2 bd        = new scalesEntities2();
                    var             CountCopy = bd.ScalesInformation.Where(p => p.IPaddress == textBox1.Text && p.ModbusID == textBox2.Text).Count();
                    if (CountCopy > 0)
                    {
                        MessageBox.Show("Такое устройство уже существует!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        ScalesInformation sc = new ScalesInformation();
                        sc.IPaddress = textBox1.Text;
                        sc.ModbusID  = textBox2.Text;
                        if (comboBox1.SelectedIndex == 0)
                        {
                            sc.Scales_Number = "A";
                        }
                        if (comboBox1.SelectedIndex == 1)
                        {
                            sc.Scales_Number = "K";
                        }
                        bd.ScalesInformation.Add(sc);
                        bd.SaveChanges();
                        bd.Dispose();
                        textBox1.Text = "";
                        textBox2.Text = "";
                        DeviceInBD();
                        MessageBox.Show("Устройство добавлено!\nДля того что бы устройство начало функционировать НЕОБХОДИМО перезапустить программу!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                else
                {
                    MessageBox.Show("ModBus адрес введен не верно!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("IP адрес введен не верно!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #5
0
        private void GetInfo()
        {
            //List<Device> NoWork = new List<Device>();
            for (int q = 0; q < device_list.Count; q++)
            {
                NetworkStream serverStream = default(NetworkStream);
                try
                {
                    bool      NoDevice     = false;
                    TcpClient clientSocket = new TcpClient();
                    foreach (var dev in device_list)
                    {
                        if (device_list[q].device_ip == dev.device_ip)
                        {
                            device_list[q].clientSocket = dev.clientSocket;
                            //serverStream = dev.clientSocket.GetStream();
                        }
                        else
                        {
                            NoDevice = true;
                        }
                    }
                    //clientSocket.Connect(item.device_ip, 9761);
                    serverStream = device_list[q].clientSocket.GetStream();

                    byte   NumbDevice = byte.Parse(device_list[q].device_number);
                    byte[] otvet      = new byte[2];
                    GetCRC16(new byte[] { NumbDevice, 3, 0, 19, 0, 1 }, ref otvet);
                    string CRC_L = ByteToStrHex(otvet[0]);
                    string CRC_H = ByteToStrHex(otvet[1]);

                    String[] message = new String[] { device_list[q].device_number, "03", "00", "13", "00", "01", CRC_L, CRC_H };
                    Byte[]   mes     = new Byte[128]; //переменная, которая будет содержать данные для отправки
                    int      i       = 0;             // счетчик

                    for (i = 0; i < 8; i++)
                    {
                        mes[i] = StrHexToByte(message[i]);
                    }

                    serverStream.Write(mes, 0, 8);
                    serverStream.Flush();
                    clientSocket.ReceiveTimeout = 1010;

                    serverStream = device_list[q].clientSocket.GetStream();            //получаем поток
                    int    buffSize  = 0;
                    int    bytesRead = 0;
                    byte[] inStream  = new byte[10025];                       // инициализируем массив для приема данных
                    buffSize = device_list[q].clientSocket.ReceiveBufferSize; //получаем размер буфера


                    bytesRead = serverStream.Read(inStream, 0, buffSize);    //считываем данные из потока
                    this.Invoke((MethodInvoker) delegate
                    {
                        this.Text = "";
                    });



                    if (bytesRead > 0)
                    {
                        string answer_Power = "";

                        for (int z = 3; z < 7; z++)
                        {
                            answer_Power = answer_Power + ByteToStrHex(inStream[z]);
                            //формируем сообщения для вывода в ListView в 16-ричном виде
                        }
                        //int weight_geter = int.Parse(answer_Weight, System.Globalization.NumberStyles.AllowHexSpecifier);
                        //double REALY_WEIGHT_VARIABLE = weight_geter * 0.001;

                        int    power_geter          = int.Parse(answer_Power, System.Globalization.NumberStyles.AllowHexSpecifier);
                        double REALY_POWER_VARIABLE = power_geter * 0.01;


                        if (REALY_POWER_VARIABLE < 0)
                        {
                            REALY_POWER_VARIABLE = 0;
                        }


                        if (Settings.kalibrovka == false)
                        {
                            double          REALY_WEIGHT_VARIABLE = (REALY_POWER_VARIABLE * 1.35) / 3.6;
                            scalesEntities2 bd   = new scalesEntities2();
                            MeasurementData inf1 = new MeasurementData();
                            inf1.ScalesNumberID      = device_list[q].device_name;
                            inf1.CurrentWeight       = REALY_WEIGHT_VARIABLE;
                            inf1.CurrentProductivity = REALY_POWER_VARIABLE;
                            inf1.TimeOfMeasurement   = DateTime.Now;
                            bd.MeasurementData.Add(inf1);
                            bd.SaveChanges();
                            bd.Dispose();
                            if (REALY_WEIGHT_VARIABLE > 0)
                            {
                                if (AllGraphRefresh != null)
                                {
                                    AllGraphRefresh();
                                }
                                RefreshGraph();
                            }
                        }

                        if (device_list[q].device_name.ToString() == WeightInformation.CURRENT_DEVICE_COMBO)
                        {
                            scalesEntities2 bd  = new scalesEntities2();
                            DataByShift     dbs = new DataByShift();
                            DataByHours     dbh = new DataByHours();
                            DataByDays      dbd = new DataByDays();
                            DataByMonth     dbm = new DataByMonth();

                            int ee = int.Parse(WeightInformation.CURRENT_DEVICE_COMBO);
                            dbs = bd.DataByShift.OrderByDescending(x => x.ID).Where(x => x.ScalesNumberID == ee).First();
                            dbh = bd.DataByHours.OrderByDescending(x => x.ID).Where(x => x.ScalesNumberID == ee).First();
                            dbd = bd.DataByDays.OrderByDescending(x => x.ID).Where(x => x.ScalesNumberID == ee).First();
                            dbm = bd.DataByMonth.OrderByDescending(x => x.ID).Where(x => x.ScalesNumberID == ee).First();

                            WEIGHT_STATIC_SHIFT = WEIGHT_STATIC_SHIFT + (REALY_POWER_VARIABLE / 3600);
                            double REALY_WEIGHT_VARIABLE = REALY_POWER_VARIABLE / 3.6;
                            if (DataLive != null)
                            {
                                DataLive(dbs.Weight.Value, REALY_POWER_VARIABLE, dbh.Weight.Value, dbd.Weight.Value, dbm.Weight.Value);
                            }
                            //dbs.Weight.Value
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
        }