예제 #1
0
 private void ListBox_Of_Tallies_Input_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         var item = this.ListBox_Of_Tallies_Input.IndexFromPoint(e.Location);
         if (item >= 0 && ListBox_Of_Tallies_Input.SelectedIndices.Contains(item) == false)
         {
             ListBox_Of_Tallies_Input.ClearSelected();
             ListBox_Of_Tallies_Input.SelectedIndex = item;
         }
     }
 }
예제 #2
0
        private void ListBox_Of_Tallies_Input_DoubleClick(object sender, EventArgs e)
        {
            List <string> Names_of_Tabs = new List <string>();

            TabPage tab = new TabPage();

            tab.BackColor   = Color.FromArgb(50, 50, 50);
            tab.BorderStyle = BorderStyle.None;

            DataView             dataView = new DataView();
            AdvancedDataGridView advancedDataGridView1 = new AdvancedDataGridView();

            advancedDataGridView1.ForeColor                 = Color.Black;
            advancedDataGridView1.ReadOnly                  = true;
            advancedDataGridView1.BorderStyle               = BorderStyle.None;
            advancedDataGridView1.Dock                      = DockStyle.Fill;
            advancedDataGridView1.RowHeadersVisible         = false;
            advancedDataGridView1.EnableHeadersVisualStyles = false;
            advancedDataGridView1.AllowUserToAddRows        = false;
            advancedDataGridView1.AllowUserToDeleteRows     = false;
            advancedDataGridView1.BorderStyle               = BorderStyle.None;
            advancedDataGridView1.BackgroundColor           = Color.FromArgb(50, 50, 50);
            advancedDataGridView1.ColumnHeadersDefaultCellStyle.BackColor   = Color.FromArgb(79, 129, 189);
            advancedDataGridView1.ColumnHeadersDefaultCellStyle.ForeColor   = Color.White;
            advancedDataGridView1.RowsDefaultCellStyle.BackColor            = Color.FromArgb(184, 204, 228);
            advancedDataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(220, 230, 241);
            advancedDataGridView1.SortStringChanged   += AdvancedDataGridView1_SortStringChanged;
            advancedDataGridView1.FilterStringChanged += AdvancedDataGridView1_FilterStringChanged;



            if (ListBox_Of_Tallies_Input.Items.Count > 0 && ListBox_Of_Tallies_Input.SelectedItem != null)
            {
                string name = ListBox_Of_Tallies_Input.GetItemText(ListBox_Of_Tallies_Input.SelectedItem);

                for (int i = 0; i < Open_Tally_Input.Tallies_Names.Count; i++)
                {
                    if (name == Open_Tally_Input.Tallies_Names[i])
                    {
                        dataView = new DataView(Open_Tally_Input.Tallies[i]);
                        advancedDataGridView1.DataSource = dataView;
                        tab.Text = Open_Tally_Input.Tallies_Names[i];
                        tab.Controls.Add(advancedDataGridView1);
                    }
                }

                for (int i = 0; i < Open_Tally_Input.Excels_Names.Count; i++)
                {
                    if (name == Open_Tally_Input.Excels_Names[i])
                    {
                        dataView = new DataView(Open_Tally_Input.Excels[i]);
                        advancedDataGridView1.DataSource = dataView;
                        tab.Text = Open_Tally_Input.Excels_Names[i];
                        tab.Controls.Add(advancedDataGridView1);
                    }
                }

                for (int i = 0; i < tabControl1.TabPages.Count; i++)
                {
                    Names_of_Tabs.Add(tabControl1.TabPages[i].Text);
                }

                if (!Names_of_Tabs.Contains(tab.Text) && advancedDataGridView1 != null)
                {
                    tabControl1.TabPages.Add(tab);
                    tabControl1.Visible = true;
                }


                int AllRows = 0;

                for (int j = 0; j < advancedDataGridView1.ColumnCount; j++)
                {
                    if (advancedDataGridView1.Rows.Count > 1)
                    {
                        if (advancedDataGridView1.Columns[j].Name == "GroupCount" || advancedDataGridView1.Columns[j].Name == "\"GroupCount\"")
                        {
                            for (int k = 0; k < advancedDataGridView1.Rows.Count; k++)
                            {
                                AllRows += Convert.ToInt32(advancedDataGridView1.Rows[k].Cells[j].Value);
                            }
                        }
                    }
                }

                var row = dataView.Table.Rows[dataView.Table.Rows.Count - 1];

                if (AllRows > 0)
                {
                    if (row[0].ToString() != "TOTAL")
                    {
                        foreach (DataColumn dc in dataView.Table.Columns)
                        {
                            if (dc.ColumnName == "\"GroupCount\"")
                            {
                                DataRowView drToAdd = dataView.AddNew();
                                drToAdd[0] = "TOTAL";
                                drToAdd["\"GroupCount\""] = AllRows;
                                drToAdd.EndEdit();
                            }

                            if (dc.ColumnName == "GroupCount")
                            {
                                DataRowView drToAdd = dataView.AddNew();
                                drToAdd[0]            = "TOTAL";
                                drToAdd["GroupCount"] = AllRows;
                                drToAdd.EndEdit();
                            }
                        }
                    }
                }

                var row2 = dataView.Table.Rows[dataView.Table.Rows.Count - 1];

                if (advancedDataGridView1.RowCount > 1 && row2[0].ToString() == "TOTAL")
                {
                    advancedDataGridView1.Rows[advancedDataGridView1.RowCount - 1].DefaultCellStyle.BackColor = Color.FromArgb(79, 129, 189);
                    advancedDataGridView1.Rows[advancedDataGridView1.RowCount - 1].DefaultCellStyle.ForeColor = Color.White;
                }

                advancedDataGridView1.ClearSelection();
            }
        }