Ejemplo n.º 1
0
        public void TreeUsers(int roleID)
        {
            treeView2.Nodes.Clear();
            treeView2.Nodes.Add(new TreeNode("Администраторы"));
            treeView2.Nodes.Add(new TreeNode("Весовщики"));
            scalesEntities2 bd1          = new scalesEntities2();
            List <Personal> ListPersonel = bd1.Personal.ToList();

            foreach (var item in ListPersonel)
            {
                if (item.Role == 2)
                {
                    treeView2.Nodes[0].Nodes.Add(new TreeNode(item.Name));
                }
                else
                {
                    treeView2.Nodes[1].Nodes.Add(new TreeNode(item.Name));
                }
            }
            bd1.Dispose();
            switch (roleID)
            {
            case 1: treeView2.Nodes[1].Expand(); break;

            case 2: treeView2.Nodes[0].Expand(); break;

            case 3: break;
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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)
     {
     }
 }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {

            }
            else
            {
                string Log = textBox1.Text;
                string Pass = textBox2.Text;

                scalesEntities2 bd = new scalesEntities2();

                
                try
                {
                    Personal pers = bd.Personal.Where(x => x.Name == Log.ToLower() && x.Password == Pass.ToLower()).First();
                    if (pers.Role == 1)
                    {
                        Role_ID = 1;
                        Form1.USER = pers.Name;
                    }
                    if (pers.Role == 2)
                    {
                        Role_ID = 2;
                        Form1.USER = pers.Name;
                    }
                    this.Close();
                }
                catch (Exception)
                {
                    textBox2.Text = "";
                    MessageBox.Show("Пользователь не найден!", "Внимание!",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }
                bd.Dispose();
  
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                scalesEntities2 bd = new scalesEntities2();
                if (ds_info.Count < 1)
                {
                    return;
                }
                if (comboBox2.SelectedItem.ToString() == "Все весы")
                {
                    int NumbShift = 0;
                    IQueryable <DataByHours> query = null;
                    switch (comboBox3.SelectedIndex)
                    {
                    case 0: NumbShift = 1;
                        query         = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && mas_Scales.Contains(x.ScalesNumberID.Value) &&
                                                             x.ShiftNumber == NumbShift);
                        break;

                    case 1: NumbShift = 2;

                        TimeSpan tSNE          = TimeSpan.Parse("08:00");
                        TimeSpan tSNEtoday     = TimeSpan.Parse("20:00");
                        DateTime NextDateShift = dateTimePicker1.Value.Date.AddDays(1);
                        query = bd.DataByHours.Where(x => ((x.Date.Value == dateTimePicker1.Value.Date && x.Time.Value > tSNEtoday) ||
                                                           (x.Date.Value == NextDateShift && x.Time.Value < tSNE)) &&
                                                     mas_Scales.Contains(x.ScalesNumberID.Value) &&
                                                     x.ShiftNumber == NumbShift);
                        break;
                    }
                    //query = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && mas_Scales.Contains(x.ScalesNumberID.Value)
                    //&& x.ShiftNumber == NumbShift);

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable1.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable1.Rows.Add(item.ID, item.Weight, item.Time.Value.ToString(@"hh\:mm\:ss"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[0]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Время"));

                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                    bd.Dispose();
                }
                else
                {
                    int Predel    = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);
                    int NumbShift = 0;
                    IQueryable <DataByHours> query = null;
                    switch (comboBox3.SelectedIndex)
                    {
                    case 0:
                        NumbShift = 1;
                        query     = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && x.ScalesNumberID.Value == Predel &&
                                                         x.ShiftNumber == NumbShift);
                        break;

                    case 1:
                        NumbShift = 2;
                        TimeSpan tSNE          = TimeSpan.Parse("08:00");
                        TimeSpan tSNEtoday     = TimeSpan.Parse("20:00");
                        DateTime NextDateShift = dateTimePicker1.Value.Date.AddDays(1);
                        query = bd.DataByHours.Where(x => ((x.Date.Value == dateTimePicker1.Value.Date && x.Time.Value > tSNEtoday) ||
                                                           (x.Date.Value == NextDateShift && x.Time.Value < tSNE)) && x.ScalesNumberID.Value == Predel &&
                                                     x.ShiftNumber.Value == NumbShift);
                        break;
                    }
                    //query = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && mas_Scales.Contains(x.ScalesNumberID.Value));

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable1.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable1.Rows.Add(item.ID, item.Weight, item.Time.Value.ToString(@"hh\:mm\:ss"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[0]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", comboBox3.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Время"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                    bd.Dispose();
                }
            }
            if (comboBox1.SelectedIndex == 1)
            {
                if (ds_info.Count < 1)
                {
                    return;
                }
                scalesEntities2 bd = new scalesEntities2();
                if (comboBox2.SelectedItem.ToString() == "Все весы")
                {
                    //int Predel = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);
                    IQueryable <DataByHours> query = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && mas_Scales.Contains(x.ScalesNumberID.Value));

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable1.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable1.Rows.Add(item.ID, item.Weight, item.Time.Value.ToString(@"hh\:mm\:ss"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[0]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Время"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                    bd.Dispose();
                }
                else
                {
                    int Predel = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);
                    IQueryable <DataByHours> query = bd.DataByHours.Where(x => x.Date == dateTimePicker1.Value.Date && x.ScalesNumberID == Predel);

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable1.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable1.Rows.Add(item.ID, item.Weight, item.Time.Value.ToString(@"hh\:mm\:ss"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[0]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Время"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                    bd.Dispose();
                }
            }
            if (comboBox1.SelectedIndex == 2)
            {
                if (ds_info.Count < 1)
                {
                    return;
                }
                scalesEntities2 bd = new scalesEntities2();
                if (comboBox2.SelectedItem.ToString() == "Все весы")
                {
                    IQueryable <DataByDays> query = bd.DataByDays.Where(x => x.Date.Value.Month == dateTimePicker1.Value.Date.Month && mas_Scales.Contains(x.ScalesNumberID.Value));

                    List <DataByDays> ds_info = query.ToList();
                    DataSet1          ds      = new DataSet1();
                    ds.DataTable2.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable2.Rows.Add(item.ID, item.Weight, item.Date.Value.ToShortDateString());
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[1]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Дата"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
                else
                {
                    int Predel = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);
                    IQueryable <DataByDays> query = bd.DataByDays.Where(x => x.Date.Value.Month == dateTimePicker1.Value.Date.Month && x.ScalesNumberID == Predel);

                    List <DataByDays> ds_info = query.ToList();
                    DataSet1          ds      = new DataSet1();
                    ds.DataTable2.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable2.Rows.Add(item.ID, item.Weight, item.Date.Value.ToShortDateString());
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[1]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Дата"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
            }
            if (comboBox1.SelectedIndex == 3)
            {
                if (ds_info.Count < 1)
                {
                    return;
                }
                scalesEntities2 bd = new scalesEntities2();
                if (comboBox2.SelectedItem.ToString() == "Все весы")
                {
                    IQueryable <DataByMonth> query = bd.DataByMonth.Where(x => mas_Scales.Contains(x.ScalesNumberID.Value));

                    List <DataByMonth> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable3.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable3.Rows.Add(item.ID, item.Weight, item.NumberMonth.Value.ToString());
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[2]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Месяц"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
                else
                {
                    int Predel = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);
                    IQueryable <DataByMonth> query = bd.DataByMonth.Where(x => x.ScalesNumberID == Predel);

                    List <DataByMonth> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable3.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable3.Rows.Add(item.ID, item.Weight, item.NumberMonth.Value.ToString());
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[2]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "Месяц"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
            }
            if (comboBox1.SelectedIndex == 4)
            {
                if (ds_info.Count < 1)
                {
                    return;
                }
                DateTime st  = dateTimePicker1.Value;
                DateTime end = dateTimePicker2.Value;
                //MessageBox.Show(dateTimePicker2.Value.Date.ToString(), "");
                //DateTime dtS = new DateTime(st.Year,st.Month,st.Day,0,0,0);
                //DateTime dtE = new DateTime(end.Year, end.Month, end.Day, end.Hour, 59, 59);


                scalesEntities2 bd = new scalesEntities2();

                if (comboBox2.SelectedItem.ToString() == "Все весы")
                {
                    IQueryable <DataByHours> query = bd.DataByHours.Where(x => (mas_Scales.Contains(x.ScalesNumberID.Value)) && (x.Date >= st.Date && x.Date <= end.Date));

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable3.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable3.Rows.Add(item.ID, item.Weight, item.Date.Value.ToString("dd.MM.yy") + " " + item.Time.Value.ToString(@"hh"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[2]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "День/Час"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
                else
                {
                    int Predel = int.Parse(comboBox2.SelectedItem.ToString().Split(' ')[0]);

                    IQueryable <DataByHours> query = bd.DataByHours.Where(x => (x.ScalesNumberID == Predel) && (x.Date >= st.Date && x.Date <= end.Date));

                    List <DataByHours> ds_info = query.ToList();
                    DataSet1           ds      = new DataSet1();
                    ds.DataTable3.Clear();

                    foreach (var item in ds_info)
                    {
                        ds.DataTable3.Rows.Add(item.ID, item.Weight, item.Date.Value.ToString("dd.MM.yy") + " " + item.Time.Value.ToString(@"hh"));
                    }

                    ReportDataSource a = new ReportDataSource("DataSet1", ds.Tables[2]);
                    this.reportViewer1.LocalReport.DataSources.Clear();
                    this.reportViewer1.LocalReport.DataSources.Add(a);
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter1", comboBox2.SelectedItem.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter2", "-"));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter3", dateTimePicker1.Value.ToString()));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter4", Form1.USER));
                    reportViewer1.LocalReport.SetParameters(new ReportParameter("ReportParameter5", "День/Час"));
                    this.reportViewer1.LocalReport.Refresh();
                    this.reportViewer1.Refresh();
                    //this.reportViewer2.RefreshReport();
                    this.reportViewer1.RefreshReport();
                }
            }
        }
Ejemplo n.º 8
0
        private void RefreshGraph()
        {
            chart1DataX.Clear();
            chart2DataX.Clear();
            chart1DataY.Clear();
            chart2DataY.Clear();
            scalesEntities2 bd = new scalesEntities2();
            IQueryable <ScalesInformation> query = bd.ScalesInformation;

            Count_WEIGHT = query.Count();
            IQueryable <DataByHours> query_data_hour = bd.DataByHours.OrderByDescending(x => x.ID).Take(Check_Connection_with_Controllers.device_list.Count).OrderBy(x => x.ID);
            List <DataByHours>       dh_info         = query_data_hour.ToList();

            if (Count_WEIGHT > 5)
            {
                for (int i = 0; i < dh_info.Count; i++)
                {
                    if (i < 5)
                    {
                        chart1DataY.Add(dh_info[i].Weight.Value);
                        chart1DataX.Add(dh_info[i].ScalesNumberID.ToString());
                    }
                    else
                    {
                        chart2DataY.Add(dh_info[i].Weight.Value);
                        chart2DataX.Add(dh_info[i].ScalesNumberID.ToString());
                    }
                }
                try
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        cartesianChart1.Series = new SeriesCollection
                        {
                            new ColumnSeries
                            {
                                Title      = "Вес:",
                                Values     = chart1DataY,
                                DataLabels = true
                            }
                        };

                        cartesianChart2.Series = new SeriesCollection
                        {
                            new ColumnSeries
                            {
                                Title      = "Вес:",
                                Values     = chart2DataY,
                                DataLabels = true
                            }
                        };
                    });
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                foreach (var item in dh_info)
                {
                    chart1DataY.Add(item.Weight.Value);
                    chart1DataX.Add(item.ScalesNumberID.ToString());
                }
                try
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        cartesianChart1.Series = new SeriesCollection
                        {
                            new ColumnSeries
                            {
                                Title      = "Вес:",
                                Values     = chart1DataY,
                                DataLabels = true
                            }
                        };
                    });
                }
                catch (Exception e)
                { }
            }
            bd.Dispose();
        }
Ejemplo n.º 9
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)
                {
                }
            }
        }
Ejemplo n.º 10
0
        private void RefreshGraph()
        {
            chart1DataX.Clear();
            chart2DataX.Clear();
            chart1DataY.Clear();
            chart2DataY.Clear();
            scalesEntities2 bd = new scalesEntities2();
            IQueryable <ScalesInformation> query = bd.ScalesInformation;

            Count_WEIGHT = query.Count();
            //var ListDevRab = new List<int>() {1 };
            int[] devL = new int[device_list.Count];
            for (int i = 0; i < devL.Length; i++)
            {
                devL[i] = device_list[i].device_name;
            }
            IQueryable <DataByShift> query_data_shift = bd.DataByShift.OrderByDescending(x => x.ID).Take(device_list.Count).Where(x => devL.Contains(x.ScalesNumberID.Value)).OrderBy(x => x.ID);
            List <DataByShift>       ds_info          = query_data_shift.ToList();

            if (Count_WEIGHT > 5)
            {
                for (int i = 0; i < ds_info.Count; i++)
                {
                    if (i < 5)
                    {
                        chart1DataY.Add(ds_info[i].Weight.Value);
                        chart1DataX.Add(ds_info[i].ScalesNumberID.ToString());
                    }
                    else
                    {
                        chart2DataY.Add(ds_info[i].Weight.Value);
                        chart2DataX.Add(ds_info[i].ScalesNumberID.ToString());
                    }
                }
                this.Invoke((MethodInvoker) delegate
                {
                    cartesianChart1.Series = new SeriesCollection
                    {
                        new ColumnSeries
                        {
                            Title      = "Вес:",
                            Values     = chart1DataY,
                            DataLabels = true
                        }
                    };

                    cartesianChart2.Series = new SeriesCollection
                    {
                        new ColumnSeries
                        {
                            Title      = "Вес:",
                            Values     = chart2DataY,
                            DataLabels = true
                        }
                    };
                });
            }
            else
            {
                foreach (var item in ds_info)
                {
                    chart1DataY.Add(item.Weight.Value);
                    chart1DataX.Add(item.ScalesNumberID.ToString());
                }
                this.Invoke((MethodInvoker) delegate
                {
                    cartesianChart1.Series = new SeriesCollection
                    {
                        new ColumnSeries
                        {
                            Title      = "Вес:",
                            Values     = chart1DataY,
                            DataLabels = true
                        }
                    };
                });
            }
            bd.Dispose();
        }