Example #1
0
/*        public bool add(string login, string date, spisok_tariph.nest tariph)
 *      {
 *          int curr_hash = get_hash(login);
 *          nest curr = first;
 *
 *
 *          if (curr == null)
 *          {
 *              first = new nest();
 *              first.hash = curr_hash;
 *              first.login = login;
 *              first.date = date;
 *
 *              first.tariph = tariph;
 *              first.next = first;
 *              first.prev = first;
 *              first.chain_next = null;
 *
 *              return true;
 *          }
 *          else
 *          {
 *              while (true)
 *              {
 *                  while ((curr.hash != curr_hash) && (curr.next != first) && (curr_hash > curr.hash))
 *                  {
 *                      curr = curr.next;
 *                  }
 *
 *                  if ((curr.hash > curr_hash)&&(curr == first))
 *                  {
 *                      nest temp = new nest();
 *                      temp.login = login;
 *                      temp.date = date;
 *                      temp.tariph = tariph;
 *                      temp.hash = curr_hash;
 *                      first.prev.next = temp;
 *                      temp.prev = first.prev;
 *                      first.prev = temp;
 *                      temp.next = first;
 *                      first = temp;
 *                      temp.chain_next = null;
 *                      return true;
 *                  }
 *                  if ((curr.next == first)&&(curr_hash>curr.hash))
 *                  {
 *                          nest temp = new nest();
 *                          temp.login = login;
 *                          temp.date = date;
 *                          temp.tariph = tariph;
 *                          temp.hash = curr_hash;
 *
 *                          curr.next = temp;
 *                          temp.prev = curr;
 *                          temp.next = first;
 *                          first.prev = temp;
 *
 *                          temp.chain_next = null;
 *                          return true;
 *                  }
 *                  else if(curr_hash<curr.hash)
 *                  {
 *                      nest temp = new nest();
 *                      temp.login = login;
 *                      temp.date = date;
 *                      temp.hash = curr_hash;
 *                      temp.tariph = tariph;
 *
 *                      curr.prev.next = temp;
 *                      temp.prev = curr.prev;
 *                      curr.prev = temp;
 *                      temp.next = curr;
 *                      temp.chain_next = null;
 *                      return true;
 *                  }
 *                  else
 *                  {
 *                      while (curr.chain_next != null)
 *                          curr = curr.chain_next;
 *                      nest temp = new nest();
 *                      temp.login = login;
 *                      temp.date = date;
 *                      temp.hash = curr_hash;
 *                      temp.tariph = tariph;
 *
 *                      temp.chain_next = null;
 *                      temp.chain_prev = curr;
 *                      curr.chain_next = temp;
 *                      return true;
 *                  }
 *
 *              }
 *          }
 *
 *
 *      }*/

        public bool add(string login, string date, spisok_tariph.nest tariph)
        {
            nest temp = new nest(login, date, tariph);
            int  hash = get_hash(login);

            if (table[hash] == null)
            {
                table[hash]      = temp;
                table[hash].next = table[hash];
                table[hash].prev = table[hash];
                return(true);
            }
            else
            {
                temp.next             = table[hash].next;
                table[hash].next.prev = temp;
                table[hash].next      = temp;
                temp.prev             = table[hash];

                /*nest newtemp = table[hash].next;
                 * table[hash].next = newtemp;
                 * newtemp.prev = table[hash];
                 * newtemp.next = table[hash].next.next;
                 * table[hash].next.next.prev = newtemp*/
                return(true);
            }
        }
Example #2
0
        private void button9_Click(object sender, EventArgs e)
        {
            tree_providers.root check1 = provider.find(sale_find_provider.Text);
            spisok_tariph.nest  check  = null;
            if (check1 != null)
            {
                check = tariph.find(sale_find_tariph.Text, provider.find(sale_find_provider.Text));
            }

            if (sale_find_tariph.Text == "" || sale_find_provider.Text == "" || sale_find_size.Text == "")
            {
                error_number = 1;
                message_box(error_number);
            }
            else if (!sale_check(sale_find_size.Text) || sale_find_provider.Text.Length > 30 || sale_find_tariph.Text.Length > 30)
            {
                error_number = 2;
                message_box(error_number);
            }
            else if (check == null || check1 == null)
            {
                error_number = 3;
                message_box(error_number);
            }
            else
            {
                tree_sale.root  s          = sales.find(sale_find_size.Text, tariph.find(sale_find_tariph.Text, provider.find(sale_find_provider.Text)));
                searchform_sale searchform = new searchform_sale(s, this);
                searchform.Show();
            }

            sale_find_provider.Text = sale_find_size.Text = sale_find_tariph.Text = "";
        }
Example #3
0
        private void button4_Click(object sender, EventArgs e)//поиск тарифа
        {
            if ((tariph_find_provider.Text == "") || (tariph_find_title.Text == ""))
            {
                error_number = 1;
                message_box(error_number);
            }
            else if (tariph_find_provider.Text.Length > 30 || tariph_find_provider.Text.Length > 30)
            {
                error_number = 2;
                message_box(error_number);
            }
            else if ((provider.find(tariph_find_provider.Text) == null) || (tariph.find(tariph_find_title.Text, provider.find(tariph_find_provider.Text)) == null))
            {
                error_number = 3;
                message_box(error_number);
            }
            else
            {
                tariph.comparisons = 0;
                spisok_tariph.nest     a          = tariph.find(tariph_find_title.Text, provider.find(tariph_find_provider.Text));
                search_form_for_tariph searchform = new search_form_for_tariph(a, this);

                searchform.Show();
            }

            tariph_find_provider.Text = "";
            tariph_find_title.Text    = "";
        }
Example #4
0
 /*        private void to_file_Click(object sender, EventArgs e)
  *      {
  *          StreamWriter out_file = new StreamWriter(@"c:\курсач\курсач\output_user.txt"); //(@"c:\курсач\курсач\output_user.txt"); @"c:\gitjub\курсач\output_user.txt"
  *          spisok_users.nest a = user.first;
  *          spisok_users.nest temp = a.chain_next;
  *          string output;
  *          while (true)
  *          {
  *              output = "";
  *              output += a.login;
  *              output += "/";
  *              output += a.date;
  *              output += "/";
  *              output += a.tariph.name;
  *              out_file.WriteLine(output);
  *              while (temp != a)
  *              {
  *                  output = "";
  *                  output += temp.login;
  *                  output += "/";
  *                  output += temp.date;
  *                  output += "/";
  *                  output += temp.tariph.name;
  *                  out_file.WriteLine(output);
  *                  temp = temp.chain_next;
  *
  *              }
  *              a = a.next;
  *              if (a == null)
  *                  break;
  *              temp = a.chain_next;
  *          }
  *          out_file.WriteLine("//");
  *          output_for_sales(out_file, sales.main);
  *          out_file.Close();
  *
  *      }
  *      private void from_file_button_Click(object sender, EventArgs e)
  *      {
  *
  *
  *      }
  */
 public void output_for_provider(StreamWriter file, tree_providers.root pr)
 {
     if (pr == null)
     {
         return;
     }
     file.WriteLine(pr.title);
     // file.Write("\n");
     for (int i = 0; i < pr.current_tariph; i++)
     {
         string temp = "";
         temp += pr.arr[i].name;
         temp += "/";
         temp += pr.arr[i].cost.ToString();
         spisok_tariph.nest a = tariph.find(pr.arr[i].name, pr);
         temp += "/";
         temp += a.type.ToString();
         temp += "/";
         temp += a.speed.ToString();
         file.WriteLine(temp);
         // file.Write("\n");
     }
     file.WriteLine("//");
     output_for_provider(file, pr.left);
     output_for_provider(file, pr.right);
 }
Example #5
0
            public nest next, prev;//, first;//для метода цепочек

            public nest(string login, string date, spisok_tariph.nest tariph)
            {
                this.login  = login;
                this.date   = date;
                this.tariph = tariph;

                //chain_next = first;
            }
Example #6
0
            /*    public struct info
             *  {
             *      public string size;// name;
             *      public string date;//int cost;
             *  }
             *  public info[] arr = new info[5];*/

            public root(string _size, string _date, spisok_tariph.nest _tariph)//, tree_providers.root _provider)
            {
                this.size = _size;
                //this.provider = _provider;
                this.tariph = _tariph;
                this.date   = _date;
                left        = right = null;
            }
Example #7
0
 public root find(string size, spisok_tariph.nest tariph)//поиск
 {
     if (main == null)
     {
         //error
         return(null);
     }
     else
     {
         root curr = main;
         while (true)
         {
             int i = compare(size, curr.size);
             //int j = compare(tariph, curr.tariph);
             if (i == 0)
             {
                 while (curr != null)
                 {
                     comparisons++;
                     if (curr.tariph == tariph)
                     {
                         return(curr);
                     }
                     curr = curr.right;
                 }
                 return(null);
             }
             else if (i == -1)
             {
                 comparisons++;
                 if (curr.left != null)
                 {
                     curr = curr.left;
                 }
                 else
                 {
                     return(null);
                 }
             }
             else if (i == 1)
             {
                 comparisons++;
                 if (curr.right != null)
                 {
                     curr = curr.right;
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
Example #8
0
 public void delete_tariph(spisok_tariph.nest tar, tree_sale.root current)
 {
     if (current == null)
     {
         return;
     }
     delete_tariph(tar, current.left);
     delete_tariph(tar, current.right);
     if (current.tariph == tar)
     {
         delete(current.size, current.tariph);
     }
 }
Example #9
0
 private void buttonCreateReport_Click(object sender, EventArgs e)
 {
     dataGridViewTypeRep.Rows.Clear();
     pr   = f2.provider.find(textBoxProvider.Text);
     type = 0;
     if ((checkBoxAddTariphInternet.Checked) && (checkBoxAddTariphTV.Checked))
     {
         type = 2;
     }
     else if (checkBoxAddTariphTV.Checked)
     {
         type = 3;
     }
     else if (checkBoxAddTariphInternet.Checked)
     {
         type = 2;
     }
     if (type == 0)
     {
         error_number = 1;
         f2.message_box(error_number);
     }
     else if (textBoxProvider.Text == "")
     {
         error_number = 1;
         f2.message_box(error_number);
     }
     else if (pr == null)
     {
         error_number = 3;
         f2.message_box(error_number);
     }
     else if (textBoxProvider.Text.Length > 30)
     {
         error_number = 2;
         f2.message_box(error_number);
     }
     else
     {
         string name = "";
         for (int i = 0; i < pr.current_tariph; i++)
         {
             spisok_tariph.nest a = f2.tariph.find(pr.arr[i].name, pr);
             if (a.type == type)
             {
                 name = a.name;
                 dataGridViewTypeRep.Rows.Add(name);
             }
         }
     }
 }
Example #10
0
 public tree_sale.root check_for_sale(spisok_tariph.nest tar, tree_sale.root s, spisok_users.nest u)
 {
     if (s == null)
     {
         return(null);
     }
     tree_sale.root s1 = check_for_sale(tar, s.left, u);
     tree_sale.root s2 = check_for_sale(tar, s.right, u);
     if ((u.tariph == s.tariph) && (Can_get_sale(u, s)))
     {
         if (s2 != null)
         {
             if (s2.size.Length > s.size.Length)
             {
                 return(s2);
             }
             else if (s2.size[0] > s.size[0])
             {
                 return(s2);
             }
             else if (s2.size[1] > s.size[1])
             {
                 return(s2);
             }
         }
         else
         {
             return(s);
         }
     }
     else
     if ((s1 != null) || (s2 != null))
     {
         if (s2 != null)
         {
             return(s2);
         }
         else
         {
             return(s1);
         }
     }
     return(null);
 }
Example #11
0
        public void add_sale(string size, string date, spisok_tariph.nest tariph)//, tree_providers.root provider)
        {
            bool placed = false;

            if (main == null)
            {
                main = new root(size, date, tariph);//, provider);
            }
            else
            {
                root curr = main;
                while (!placed)
                {
                    int i = compare(size, curr.size);
                    if (i == -1)
                    {
                        if (curr.left == null)
                        {
                            root temp = new root(size, date, tariph);//, provider);
                            curr.left = temp;
                            placed    = true;
                        }
                        else
                        {
                            curr = curr.left;
                        }
                    }
                    else if ((i == 1) | (i == 0))
                    {
                        if (curr.right == null)
                        {
                            root temp = new root(size, date, tariph);//, provider);
                            curr.right = temp;
                            placed     = true;
                        }
                        else
                        {
                            curr = curr.right;
                        }
                    }
                }
            }
        }
Example #12
0
 private void button6_Click(object sender, EventArgs e)
 {
     tree_providers.root check1 = provider.find(tariph_del_provider.Text);
     spisok_tariph.nest  check  = null;
     if (check1 != null)
     {
         check = tariph.find(tariph_del_title.Text, check1);
     }
     spisok_tariph.nest a = check;
     if (tariph_del_title.Text == "" || tariph_del_provider.Text == "")
     {
         error_number = 1;
         message_box(error_number);
     }
     else if (tariph_del_title.Text.Length > 30 || tariph_del_provider.Text.Length > 30)
     {
         error_number = 2;
         message_box(error_number);
     }
     else if (check == null || check1 == null)
     {
         error_number = 3;
         message_box(error_number);
     }
     else
     {
         for (int i = 0; i < a.provider.current_user; i++)
         {
             if (user.find(a.provider.users[i]).tariph == a)
             {
                 user.delete(a.provider.users[i]);
                 provider.delete_user(a.provider.users[i], a.provider.title);
             }
         }
         sales.delete_tariph(a, sales.main);
         provider.del_tariph(a.name, a.provider);
         tariph.delete(a.name, check1);
         error_number = 10;
         message_box(error_number);
     }
     tariph_del_title.Text = tariph_del_provider.Text = "";
 }
Example #13
0
        private void add_sale_Click(object sender, EventArgs e)
        {
            tree_providers.root check1 = provider.find(sale_provider.Text);
            spisok_tariph.nest  check  = null;
            if (check1 != null)
            {
                check = tariph.find(sale_tariph.Text, check1);
            }

            if (sale_num.Text == "" || sale_length.Text == "" || sale_provider.Text == "" || sale_tariph.Text == "")
            {
                error_number = 1;
                message_box(error_number);
            }
            else if (check == null || check1 == null)
            {
                error_number = 3;
                message_box(error_number);
            }
            else if (!sale_check(sale_num.Text) || !check_for_int(sale_length.Text) || sale_length.Text.Length > 3 || sale_provider.Text.Length > 30 || sale_tariph.Text.Length > 30)
            {
                error_number = 2;
                message_box(error_number);
            }
            else if (sales.find(sale_num.Text, check) != null)
            {
                error_number = 4;
                message_box(error_number);
            }
            else
            {
                //spisok_tariph.nest a = tariph.find(sale_tariph.Text, provider.find(sale_provider.Text));
                sales.add_sale(sale_num.Text, sale_length.Text, check);//, a.provider);

                error_number = 0;
                message_box(error_number);
            }
            sale_num.Text = sale_tariph.Text = sale_provider.Text = sale_length.Text = "";
        }
Example #14
0
        private void button8_Click(object sender, EventArgs e)
        {
            tree_providers.root check1 = provider.find(user_provider.Text);
            spisok_tariph.nest  check  = null;
            if (check1 != null)
            {
                check = tariph.find(user_tariph.Text, check1);
            }

            if (user_login.Text == "" || user_provider.Text == "" || user_tariph.Text == "" || user_date.Text == "")
            {
                error_number = 1;
                message_box(error_number);
            }
            else if (!date_check(user_date.Text) || user_login.Text.Length > 30 || user_provider.Text.Length > 30 || user_tariph.Text.Length > 30)
            {
                error_number = 2;
                message_box(error_number);
            }
            else if (check == null || check1 == null)
            {
                error_number = 3;
                message_box(error_number);
            }
            else if (user.find(user_login.Text) != null)
            {
                error_number = 4;
                message_box(error_number);
            }
            else
            {
                user.add(/*user.get_hash(user_login.Text),*/ user_login.Text, user_date.Text, tariph.find(user_tariph.Text, provider.find(user_provider.Text)));
                provider.add_user(user_login.Text, user_provider.Text);
                error_number = 0;
                message_box(error_number);
            }

            user_login.Text = user_date.Text = user_tariph.Text = user_provider.Text = "";
        }//
Example #15
0
        private void button11_Click(object sender, EventArgs e)
        {
            tree_providers.root check1 = provider.find(sale_del_provider.Text);
            spisok_tariph.nest  check  = null;
            if (check1 != null)
            {
                check = tariph.find(sale_del_tar.Text, provider.find(sale_del_provider.Text));
            }

            if (sale_del_size.Text == "" || sale_del_tar.Text == "" || sale_del_provider.Text == "")
            {
                error_number = 1;
                message_box(error_number);
            }
            else if (!sale_check(sale_del_size.Text) || sale_del_tar.Text.Length > 30 || sale_find_provider.Text.Length > 30)
            {
                error_number = 2;
                message_box(error_number);
            }
            else if (check1 == null || check == null)
            {
                error_number = 3;
                message_box(error_number);
            }
            else if (sales.find(sale_del_size.Text, check) == null)
            {
                error_number = 3;
                message_box(error_number);
            }
            else
            {
                sales.delete(sale_del_size.Text, tariph.find(sale_del_tar.Text, provider.find(sale_del_provider.Text)));
                error_number = 10;
                message_box(error_number);
            }
            sale_del_tar.Text = sale_del_size.Text = sale_del_provider.Text = "";
        }
        public int add_grid_param(DataGridView grid)
        {
            string[] temp = new string[4];
            int      curr = 0;
            int      comp = 0;

            f2.tariph.comparisons = 0;
            while (curr < pr.current_tariph)
            {
                spisok_tariph.nest a = f2.tariph.find(pr.arr[curr].name, pr);
                comp += f2.tariph.comparisons;
                //temp[0] = a.hash.ToString();
                temp[1] = pr.arr[curr].name;
                temp[2] = a.speed.ToString();
                temp[3] = pr.arr[curr].cost.ToString();
                grid.Rows.Add(temp);
                curr++;
            }
            return(comp);
            // grid.Rows.
            //string[] check = { "test1", "test2", "test3", "test4" };
            //grid.Rows.Add(check);
            //grid.Rows.Add(n);//добивить строку в столбцы
        }
Example #17
0
 public search_form_for_tariph(spisok_tariph.nest a, Form2 f2)
 {
     InitializeComponent();
     tariph  = a;
     this.f2 = f2;
 }
Example #18
0
        private void Form2_Load(object sender, EventArgs e)
        {
            StreamReader file_in = new StreamReader(@"a:\gitjub\курсач\output_provider.txt");//(@"c:\курсач\курсач\output_user.txt");//@"a:\gitjub\курсач\output_provider.txt"

            input_for_provider(file_in);
            file_in.Close();
            file_in = new StreamReader(@"a:\gitjub\курсач\output_user.txt");//@"a:\gitjub\курсач\output_user.txt"@"c:\курсач\курсач\output_user.txt"
            string[] line = new string[4];
            string   temp = file_in.ReadLine();

            while (temp != "//")
            {
                int j = 0;
                int i = 0;
                while (j < temp.Length)
                {
                    if (temp[j] == '/')
                    {
                        j++;
                        i++;
                    }

                    line[i] += temp[j];
                    j++;
                }
                if (provider.find(line[3]) == null)
                {
                    message_choise_resilt = MessageBox.Show("Элемент не может быть добавлен. Перейти к следующему?", "Ошибка", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                }
                else
                {
                    user.add(line[0], line[1], tariph.find(line[2], provider.find(line[3])));
                    provider.add_user(line[0], line[3]);
                }
                line[0] = line[1] = line[2] = line[3] = "";
                temp    = file_in.ReadLine();

                if (message_choise_resilt == DialogResult.Cancel)
                {
                    file_in.Close();
                    return;
                }
            }

            while (file_in.Peek() > -1)
            {
                temp = file_in.ReadLine();
                int j = 0;
                int i = 0;
                while (j < temp.Length)
                {
                    if (temp[j] == '/')
                    {
                        j++;
                        i++;
                    }
                    line[i] += temp[j];
                    j++;
                }
                spisok_tariph.nest a = tariph.find(line[2], provider.find(line[3]));
                sales.add_sale(line[0], line[1], a);// a.provider);
                line[0] = line[1] = line[2] = line[3] = "";
            }

            file_in.Close();
        }
Example #19
0
        public bool delete(string size, spisok_tariph.nest tariph)//удаление
        {
            bool left   = true;
            root parent = main;
            root curr   = main;
            int  i      = compare(size, main.size);

            if (i == 0)//удаляем корень дерева, проверка на что заменить
            {
                if (curr.tariph == tariph)
                {
                    root swap = find_max(main);
                    if (swap == null)
                    {
                        main = main.left;
                    }
                    else
                    {
                        swap.left = main.left;
                        if (main.right != swap)
                        {
                            swap.right = main.right;
                        }
                        main = swap;
                    }
                    return(true);
                }
                else
                {
                    curr = curr.right;
                    left = false;
                }
            }
            else if (i == -1)
            {
                left = true;
                curr = main.left;
            }

            else if (i == 1)
            {
                left = false;
                curr = main.right;
            }

            while (true)
            {
                //нужна проверка на отсутствие
                i = compare(size, curr.size);
                if (i == -1)
                {
                    parent = curr;
                    left   = true;
                    curr   = curr.left;
                }
                else if (i == 1)
                {
                    parent = curr;
                    left   = false;
                    curr   = curr.right;
                }

                else if (i == 0)
                {
                    while (curr != null)
                    {
                        if (curr.tariph == tariph)
                        {
                            root swap = find_max(curr);
                            if (swap == null)
                            {
                                if (left)
                                {
                                    parent.left = curr.right;
                                }
                                else
                                {
                                    parent.right = curr.right;
                                }
                            }
                            else
                            {
                                if (left)
                                {
                                    parent.left = swap;
                                }
                                else
                                {
                                    parent.right = swap;
                                }
                            }
                            return(true);
                        }
                        else
                        {
                            parent = curr;
                            curr   = curr.right;
                        }
                    }
                }
                else if (curr == null)
                {
                    return(false);
                }
            }
        }