Ejemplo n.º 1
0
 public Options()
 {
     InitializeComponent();
     this.FormClosing           += new FormClosingEventHandler(this.Options_FormClosing);
     this.UserComboBox.DropDown += new System.EventHandler(this.UserComboBox_DropDown);
     using (DbOption db = new DbOption())
     {
         var Options = db.UserOptions.Select(x => new { UserName = x.UserName, Id = x.Id });
         UserComboBox.DataSource                 = Options.ToList();
         UserComboBox.DisplayMember              = "UserName";
         UserComboBox.ValueMember                = "Id";
         this.UserComboBox.SelectedIndexChanged += new System.EventHandler(this.UserComboBox_SelectedIndexChanged);
         if (UserComboBox.Text != "")
         {
             int a         = Convert.ToInt32(UserComboBox.SelectedValue.ToString());
             var NewOption = db.UserOptions.Where(x => x.Id == a).FirstOrDefault();
             if (NewOption != null)
             {
                 LoginTextBox.Text     = NewOption.Login;
                 PasswordTextBox.Text  = NewOption.Password;
                 ProxyTextBox.Text     = NewOption.Proxy;
                 PortTextBox.Text      = NewOption.Port.ToString();
                 DirectoryTextBox.Text = NewOption.Directory;
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <Units> SaveUnit   = new List <Units>();
            List <Units> RemoveUnit = new List <Units>();

            for (int i = CheckedUnits.Items.Count - 1; i >= 0; i--)
            {
                if (!CheckedUnits.GetItemChecked(i))
                {
                    SaveUnit.Add((Units)CheckedUnits.Items[i]);
                }
                else
                {
                    RemoveUnit.Add((Units)CheckedUnits.Items[i]);
                }
            }
            SaveUnit.Reverse();
            CheckedUnits.DataSource    = SaveUnit;
            CheckedUnits.DisplayMember = "Name";
            CheckedUnits.ValueMember   = "UnitId";
            using (DbOption db = new DbOption())
            {
                foreach (Units a in RemoveUnit)
                {
                    var unit = db.Units.Where(u => u.Name == a.Name & u.UnitId == a.UnitId & u.GroupId == a.GroupId).First();
                    db.Units.Remove(unit);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         var NewOption = db.UserOptions.Where(x => x.UserName == UserComboBox.Text).FirstOrDefault();
         if (LoginTextBox.Text != "" & PasswordTextBox.Text != "" & ProxyTextBox.Text != "" & PortTextBox.Text != "" & UserComboBox.Text != "" & DirectoryTextBox.Text != "")
         {
             if (NewOption == null)
             {
                 db.UserOptions.Add(new UserOptions {
                     Login = LoginTextBox.Text, Password = PasswordTextBox.Text, Port = Convert.ToInt32(PortTextBox.Text), Proxy = ProxyTextBox.Text, UserName = UserComboBox.Text, Directory = DirectoryTextBox.Text
                 });
                 db.SaveChanges();
             }
             else
             {
                 db.UserOptions.Remove(NewOption);
                 db.UserOptions.Add(new UserOptions {
                     Login = LoginTextBox.Text, Password = PasswordTextBox.Text, Port = Convert.ToInt32(PortTextBox.Text), Proxy = ProxyTextBox.Text, UserName = UserComboBox.Text, Directory = DirectoryTextBox.Text
                 });
                 db.SaveChanges();
             }
         }
         else
         {
             MessageBox.Show("Заполните все поля, чтобы отредактировать данные, или добавить нового пользователя");
         }
     }
 }
Ejemplo n.º 4
0
 private void ComboBoxGroup_DropDown(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         var Groups = db.Groups.Select(x => new { GroupId = x.GroupId, Name = x.Name });
         ComboBoxGroup.DataSource    = Groups.ToList();
         ComboBoxGroup.DisplayMember = "Name";
         ComboBoxGroup.ValueMember   = "GroupId";
     }
 }
Ejemplo n.º 5
0
 private void UserComboBox_DropDown(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         var Options = db.UserOptions.Select(x => new { UserName = x.UserName, Id = x.Id });
         UserComboBox.DataSource    = Options.ToList();
         UserComboBox.DisplayMember = "UserName";
         UserComboBox.ValueMember   = "Id";
     }
 }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <Units> NewUnits = new List <Units>();

            foreach (Units a in CheckedUnits.Items)
            {
                NewUnits.Add(a);
            }
            if (ComboBoxGroup.SelectedValue != null & ComboBoxGroup.SelectedValue.ToString() != "")
            {
                foreach (Units Check in UnitsWialon.CheckedItems)
                {
                    bool flag = false;
                    foreach (Units i in CheckedUnits.Items)
                    {
                        if (Check.Name == i.Name)
                        {
                            flag = true; break;
                        }
                    }
                    if (!flag)
                    {
                        NewUnits.Add(new Units()
                        {
                            Name = Check.Name, UnitId = Check.UnitId, GroupId = Convert.ToInt32(ComboBoxGroup.SelectedValue.ToString())
                        });
                    }
                }
                CheckedUnits.DataSource    = NewUnits;
                CheckedUnits.DisplayMember = "Name";
                CheckedUnits.ValueMember   = "UnitId";
                using (DbOption db = new DbOption())
                {
                    if (NewUnits.Count != 0)
                    {
                        foreach (Units a in NewUnits)
                        {
                            try
                            {
                                db.Units.Add(new Units {
                                    Name = a.Name, UnitId = a.UnitId, GroupId = (int)ComboBoxGroup.SelectedValue
                                });
                                db.SaveChanges();
                            }
                            catch { MessageBox.Show("Не удалось добавить технику " + a.Name); }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Вы не выбрали технику");
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public AddForm()
 {
     InitializeComponent();
     this.FormClosing += new FormClosingEventHandler(this.Add_FormClosing);
     using (DbOption db = new DbOption())
     {
         this.ComboGroup.DataSource    = db.Groups.ToList();
         this.ComboGroup.DisplayMember = "Name";
         this.ComboGroup.ValueMember   = "GroupId";
     }
 }
Ejemplo n.º 8
0
 private void UserDeleteBtn_Click(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         int a         = Convert.ToInt32(UserComboBox.SelectedValue.ToString());
         var NewOption = db.UserOptions.Where(x => x.Id == a).FirstOrDefault();
         db.UserOptions.Remove(NewOption);
         db.SaveChanges();
         UserComboBox.DataSource    = db.UserOptions;
         UserComboBox.DisplayMember = "UserName";
         UserComboBox.ValueMember   = "Id";
     }
 }
Ejemplo n.º 9
0
        void ComboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ComboGroupS = (int)ComboBoxGroup.SelectedValue;

            using (DbOption db = new DbOption())
            {
                if (ComboGroupS != 0)
                {
                    CheckedUnits.DataSource    = db.Units.ToList().Where(x => x.GroupId == ComboGroupS).ToList();
                    CheckedUnits.DisplayMember = "Name";
                    CheckedUnits.ValueMember   = "UnitId";
                }
            }
        }
Ejemplo n.º 10
0
 private void AddOk_Click(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         if (ComboGroup.Text != null)
         {
             db.Groups.Add(new Groups {
                 Name = ComboGroup.Text
             });
             try { db.SaveChanges(); }
             catch { System.Windows.Forms.MessageBox.Show("Введите другое название группы. Это не соответсвует формату данных"); }
             this.ComboGroup.DataSource    = db.Groups.ToList();
             this.ComboGroup.DisplayMember = "Name";
             this.ComboGroup.ValueMember   = "GroupId";
         }
     }
 }
Ejemplo n.º 11
0
 private void RemoveBtn_Click(object sender, EventArgs e)
 {
     using (DbOption db = new DbOption())
     {
         if (ComboGroup.Text != null)
         {
             int a     = Convert.ToInt32(ComboGroup.SelectedValue.ToString());
             var group = db.Groups.OrderByDescending(u => u.Name == ComboGroup.Text & u.GroupId == a).First();
             db.Groups.Remove(group);
             var units = db.Units.Where(x => x.GroupId == a);
             db.Units.RemoveRange(units);
             db.SaveChanges();
             this.ComboGroup.DataSource    = db.Groups.ToList();
             this.ComboGroup.DisplayMember = "Name";
             this.ComboGroup.ValueMember   = "GroupId";
         }
     }
 }
Ejemplo n.º 12
0
 private void UserComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (UserComboBox.Text != "")
     {
         using (DbOption db = new DbOption())
         {
             int a         = Convert.ToInt32(UserComboBox.SelectedValue.ToString());
             var NewOption = db.UserOptions.Where(x => x.Id == a).FirstOrDefault();
             if (NewOption != null)
             {
                 LoginTextBox.Text     = NewOption.Login;
                 PasswordTextBox.Text  = NewOption.Password;
                 ProxyTextBox.Text     = NewOption.Proxy;
                 PortTextBox.Text      = NewOption.Port.ToString();
                 DirectoryTextBox.Text = NewOption.Directory;
             }
         }
     }
 }
Ejemplo n.º 13
0
        public WialonForm()
        {
            TimeZone localZone     = TimeZone.CurrentTimeZone;
            DateTime currentDate   = DateTime.Now;
            int      currentYear   = currentDate.Year;
            DateTime currentUTC    = localZone.ToUniversalTime(currentDate);
            TimeSpan currentOffset = localZone.GetUtcOffset(currentDate);

            AddForm1 = new AddForm();
            Option   = new Options();
            InitializeComponent();

            using (DbOption db = new DbOption())
            {
                ComboBoxGroup.DataSource    = db.Groups.ToList();
                ComboBoxGroup.DisplayMember = "Name";
                ComboBoxGroup.ValueMember   = "GroupId";
            }
            Wialon  = new WialonConnection();
            Units   = new WialonCollection();
            Reports = new WialonCollection();
            WialonUnit   Unit   = new WialonUnit();
            WialonReport Report = new WialonReport();
            long         CountOfUnits;

            if (Wialon == null)
            {
                MessageBox.Show("No object");
                return;
            }
            if (Option.ProxyTextBox.Text.Trim() != "" & Option.PortTextBox.Text.Trim() != "" & Option.LoginTextBox.Text.Trim() != "" & Option.PasswordTextBox.Text.Trim() != "" & Option.DirectoryTextBox.Text.Trim() != "")
            {
                Wialon.SetProxyMode(Option.ProxyTextBox.Text.Trim(), (ushort)Convert.ToInt32(Option.PortTextBox.Text.Trim()), Option.LoginTextBox.Text.Trim() + ":" + Option.PasswordTextBox.Text.Trim());
                Units = Wialon.Login(Option.ProxyTextBox.Text.Trim(), (ushort)Convert.ToInt32(Option.PortTextBox.Text.Trim()), Option.LoginTextBox.Text.Trim(), Option.PasswordTextBox.Text.Trim());
            }
            else
            {
                Wialon.SetProxyMode("activex-wln.sucden.ru", 80, "UserForApp:UserForApp");
                Units = Wialon.Login("activex-wln.sucden.ru", 80, "UserForApp", "UserForApp");
            }
            Reports = Wialon.GetReportsList();
            WialonReport   NewRep  = new WialonReport();
            List <ReportL> RepList = new List <ReportL>();

            foreach (WialonReport a in Reports)
            {
                if (a == null)
                {
                    MessageBox.Show(Wialon.GetLastError().ToString());
                    return;
                }
                else
                {
                    RepList.Add(new ReportL()
                    {
                        Name = a.Name, ReportID = a.ReportID, ResourceID = a.ResourceID
                    });
                }
            }
            RepList.Sort((a, b) => a.Name.CompareTo(b.Name));
            ReportList.DataSource    = RepList;
            ReportList.DisplayMember = "Name";
            ReportList.ValueMember   = "ReportID";
            CountOfUnits             = Units.Count;
            List <Units> UnitsCl = new List <Units>();

            for (int i = 1; i < CountOfUnits; i++)
            {
                Unit = (WialonUnit)Units[i];
                if (Unit == null)
                {
                    MessageBox.Show("Not unit");
                    return;
                }
                else
                {
                    UnitsCl.Add(new Units()
                    {
                        Name = Unit.Name, UnitId = (int)Unit.ID
                    });
                }
            }
            UnitsCl.Sort((a, b) => a.Name.CompareTo(b.Name));
            UnitsWialon.DataSource    = UnitsCl;
            UnitsWialon.DisplayMember = "Name";
            UnitsWialon.ValueMember   = "UnitId";
            //  string some = Wialon.GetReportByID(1482094800, 1482181199, UId, (int)GetTimeZoneForWialon(), "ru", ResId, RepId);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(Unit);
            Unit = null;
            // StreamWriter SW = new StreamWriter(new FileStream(@"C:\Rapport\MyXml.txt", FileMode.Create, FileAccess.Write));
            // SW.Write(some);
            // SW.Close();
            //  StreamWriter SW2 = new StreamWriter(new FileStream(@"C:\Rapport\MyXml2.txt", FileMode.Create, FileAccess.Write));
            //  if (some != null)
            //  {
            //      SW2.Write(some);
            //     SW2.Close();
            // }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(Units);
            Units  = null;
            Wialon = null;
            ComboBoxGroup.SelectedIndexChanged += ComboBoxGroup_SelectedIndexChanged;
        }