Ejemplo n.º 1
0
        public ManualUpdateSTK(string[] STKData, int Year)
        {
            List <STKDB> NewSTKManual = new List <STKDB>();

            foreach (string OneRow in STKData)
            {
                string[] ToAdd = OneRow.Split('\t');

                if (ToAdd.Length != 1 && ToAdd.Length == 4)
                {
                    var NewRow = new STKDB
                    {
                        ANC         = ToAdd[0],
                        Description = ToAdd[1],
                        IDCO        = ToAdd[2],
                        Year        = Year,
                        Month       = 0,
                        Day         = 0,
                        Value       = Convert.ToDouble(ToAdd[3]),
                    };
                    NewSTKManual.Add(NewRow);
                }
            }

            if (NewSTKManual != null)
            {
                STKController.AddManualUpdate(NewSTKManual);
            }
        }
Ejemplo n.º 2
0
        public static bool Load(string[] NewTable)
        {
            var       PNCForm  = MainProgram.Self.actionView.PNCListView;
            DataTable PNCTable = PNCForm.GetDataTable();

            if (PNCTable.Columns.Count <= 1)
            {
                PNCTable.Columns.Clear();
                PNCTable.Columns.Add("PNC");
                PNCTable.Columns.Add("OLD ANC");
                PNCTable.Columns.Add("OLD Q");
                PNCTable.Columns.Add("NEW ANC");
                PNCTable.Columns.Add("NEW Q");
                PNCTable.Columns.Add("OLD STK");
                PNCTable.Columns.Add("NEW STK");
                PNCTable.Columns.Add("Delta");
            }

            if (PNCTable.Rows.Count > 0)
            {
                DialogResult Result = MessageBox.Show("Do you want replease exist PNC List?", "Warning!", MessageBoxButtons.YesNo);
                if (Result == DialogResult.Yes)
                {
                    PNCTable.Rows.Clear();
                }
                else
                {
                    DialogResult Result2 = MessageBox.Show("Do you want Add to exist PNC List?", "Warning!", MessageBoxButtons.YesNo);
                    if (Result2 == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            //Sprawdzenie czy dane są prawidłowo przygotowane przez użytkownika
            if (!ProtectionData(NewTable[0]))
            {
                return(false);
            }


            foreach (string OneRow in NewTable)
            {
                string[] SpecificRow = OneRow.Split(';');

                if (SpecificRow.Length != 1)
                {
                    DataRow NewRow = PNCTable.NewRow();
                    NewRow["PNC"] = SpecificRow[0];

                    if (SpecificRow[1] != string.Empty)
                    {
                        NewRow["OLD ANC"] = "ECCC(" + SpecificRow[1] + ")";
                    }

                    PNCTable.Rows.Add(NewRow);

                    int Limit = (SpecificRow.Length - 4) / 2;

                    for (int counter = 2; counter <= Limit; counter++)
                    {
                        NewRow            = PNCTable.NewRow();
                        NewRow["OLD ANC"] = SpecificRow[counter];
                        NewRow["OLD Q"]   = SpecificRow[counter + 1];
                        NewRow["NEW ANC"] = SpecificRow[counter + Limit + 1];
                        NewRow["NEW Q"]   = SpecificRow[counter + Limit + 2];
                        if (!(NewRow["OLD ANC"].ToString() == string.Empty && NewRow["NEW ANC"].ToString() == string.Empty))
                        {
                            PNCTable.Rows.Add(NewRow);
                        }
                        counter++;
                    }
                }
            }

            DataTable PNCTableDuplicate = PNCTable.Clone();
            bool      CanAdd            = false;

            foreach (DataRow Row in PNCTable.Rows)
            {
                if (Row["PNC"].ToString() != string.Empty)
                {
                    if (!PNCTableDuplicate.AsEnumerable().Any(u => u.Field <string>("PNC") == Row["PNC"].ToString()))
                    //if (!PNCTableDuplicate.AsEnumerable().Any(u => u.ToString() == Row[0].ToString()))
                    {
                        PNCTableDuplicate.Rows.Add(Row.ItemArray);
                        CanAdd = true;
                    }
                    else
                    {
                        CanAdd = false;
                    }
                }
                else
                {
                    if (CanAdd)
                    {
                        PNCTableDuplicate.Rows.Add(Row.ItemArray);
                    }
                }
            }

            if (!PNCSpecSTK.Find(PNCTableDuplicate))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private void Pb_AddData_Close_Click(object sender, EventArgs e)
        {
            //Action action = new Action();
            Cursor.Current = Cursors.WaitCursor;
            string[] row            = tb_AddData_Data.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            int      DuplicateCount = 0;
            bool     IFCalc         = false;

            if (row[0] != "")
            {
                if (Jak == "PNC")
                {
                    DataGridView dg_PNC = (DataGridView)MainProgram.Self.TabControl.Controls.Find("dg_PNC", true).First();

                    if (dg_PNC.Rows.Count > 1)
                    {
                        DialogResult result = MessageBox.Show("Do you want replace all PNC in this Action ?", "Warning!", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            dg_PNC.Rows.Clear();
                            dg_PNC.Columns.Clear();
                            dg_PNC.Columns.Add("PNC", "PNC");
                            dg_PNC.Columns["PNC"].Width    = 63;
                            dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                            IFCalc = true;
                        }
                        else if (result == DialogResult.No)
                        {
                            DialogResult result2 = MessageBox.Show("Do you want add this PNC to exisitng PNC for this Action ?", "Warning!", MessageBoxButtons.YesNo);
                            if (result2 == DialogResult.Yes)
                            {
                                IFCalc = true;
                            }
                            else if (result2 == DialogResult.No)
                            {
                                IFCalc = false;
                            }
                        }
                    }
                    else
                    {
                        dg_PNC.Rows.Clear();
                        dg_PNC.Columns.Clear();
                        dg_PNC.Columns.Add("PNC", "PNC");
                        dg_PNC.Columns["PNC"].Width    = 63;
                        dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                        IFCalc = true;
                    }


                    if (IFCalc)
                    {
                        foreach (string OneRow in row)
                        {
                            if (OneRow != "")
                            {
                                var Row = dg_PNC.Rows.Cast <DataGridViewRow>().Where(u => u.Cells["PNC"].Value.ToString().Equals(OneRow)).FirstOrDefault();
                                if (Row == null)
                                {
                                    dg_PNC.Rows.Add(OneRow);
                                }
                                else
                                {
                                    DuplicateCount++;
                                }
                            }
                        }
                    }
                    this.Close();
                    Cursor.Current = Cursors.Default;
                    if (DuplicateCount > 0)
                    {
                        MessageBox.Show($"Was remove {DuplicateCount} Duplicate Value", "Duplicate counter");
                    }
                    return;
                }
                if (Jak == "PNCSpec")
                {
                    DataGridView dg_PNC = (DataGridView)MainProgram.Self.TabControl.Controls.Find("dg_PNC", true).First();

                    if (dg_PNC.Rows.Count > 1)
                    {
                        DialogResult result = MessageBox.Show("Do you want replace all PNC in this Action ?", "Warning!", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            dg_PNC.Rows.Clear();
                            dg_PNC.Columns.Clear();
                            dg_PNC.Columns.Add("PNC", "PNC");
                            dg_PNC.Columns.Add("OLD ANC", "OLD ANC");
                            dg_PNC.Columns.Add("OLD Q", "Q");
                            dg_PNC.Columns.Add("NEW ANC", "NEW ANC");
                            dg_PNC.Columns.Add("NEW Q", "Q");
                            dg_PNC.Columns["PNC"].Width     = 80;
                            dg_PNC.Columns["OLD ANC"].Width = 65;
                            dg_PNC.Columns["OLD ANC"].DefaultCellStyle.ForeColor = Color.Red;
                            dg_PNC.Columns["OLD Q"].Width = 35;
                            dg_PNC.Columns["OLD Q"].DefaultCellStyle.ForeColor = Color.Red;
                            dg_PNC.Columns["NEW ANC"].Width = 65;
                            dg_PNC.Columns["NEW ANC"].DefaultCellStyle.ForeColor = Color.Green;
                            dg_PNC.Columns["NEW Q"].Width = 35;
                            dg_PNC.Columns["NEW Q"].DefaultCellStyle.ForeColor = Color.Green;
                            dg_PNC.Columns["PNC"].SortMode     = DataGridViewColumnSortMode.NotSortable;
                            dg_PNC.Columns["OLD ANC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                            dg_PNC.Columns["OLD Q"].SortMode   = DataGridViewColumnSortMode.NotSortable;
                            dg_PNC.Columns["NEW ANC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                            dg_PNC.Columns["NEW Q"].SortMode   = DataGridViewColumnSortMode.NotSortable;
                            IFCalc = true;
                        }
                        else if (result == DialogResult.No)
                        {
                            DialogResult result2 = MessageBox.Show("Do you want add this PNC to exisitng PNC for this Action ?", "Warning!", MessageBoxButtons.YesNo);
                            if (result2 == DialogResult.Yes)
                            {
                                IFCalc = true;
                            }
                            else if (result2 == DialogResult.No)
                            {
                                IFCalc = false;
                            }
                        }
                    }
                    else
                    {
                        dg_PNC.Rows.Clear();
                        dg_PNC.Columns.Clear();
                        dg_PNC.Columns.Add("PNC", "PNC");
                        dg_PNC.Columns.Add("OLD ANC", "OLD ANC");
                        dg_PNC.Columns.Add("OLD Q", "Q");
                        dg_PNC.Columns.Add("NEW ANC", "NEW ANC");
                        dg_PNC.Columns.Add("NEW Q", "Q");
                        dg_PNC.Columns["PNC"].Width     = 80;
                        dg_PNC.Columns["OLD ANC"].Width = 65;
                        dg_PNC.Columns["OLD ANC"].DefaultCellStyle.ForeColor = Color.Red;
                        dg_PNC.Columns["OLD Q"].Width = 35;
                        dg_PNC.Columns["OLD Q"].DefaultCellStyle.ForeColor = Color.Red;
                        dg_PNC.Columns["NEW ANC"].Width = 65;
                        dg_PNC.Columns["NEW ANC"].DefaultCellStyle.ForeColor = Color.Green;
                        dg_PNC.Columns["NEW Q"].Width = 35;
                        dg_PNC.Columns["NEW Q"].DefaultCellStyle.ForeColor = Color.Green;
                        dg_PNC.Columns["PNC"].SortMode     = DataGridViewColumnSortMode.NotSortable;
                        dg_PNC.Columns["OLD ANC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                        dg_PNC.Columns["OLD Q"].SortMode   = DataGridViewColumnSortMode.NotSortable;
                        dg_PNC.Columns["NEW ANC"].SortMode = DataGridViewColumnSortMode.NotSortable;
                        dg_PNC.Columns["NEW Q"].SortMode   = DataGridViewColumnSortMode.NotSortable;
                        IFCalc = true;
                    }


                    if (IFCalc)
                    {
                        foreach (string SingleRow in row)
                        {
                            if (SingleRow == string.Empty)
                            {
                                continue;
                            }

                            string[] SelectedRow = SingleRow.Split(';');
                            string   PNC         = SelectedRow[0];
                            string   ECCC        = string.Empty;

                            int Limit = ((SelectedRow.Length - 3) / 2);
                            if (SelectedRow[1].ToString() != string.Empty)
                            {
                                ECCC = "ECCC(" + SelectedRow[1] + ")";
                            }
                            dg_PNC.Rows.Add(PNC, ECCC, string.Empty);

                            dg_PNC.Rows[dg_PNC.Rows.Count - 1].DefaultCellStyle.BackColor = Color.LightBlue;
                            dg_PNC.Rows[dg_PNC.Rows.Count - 1].DefaultCellStyle.Font      = new Font(dg_PNC.Font, FontStyle.Bold);
                            dg_PNC.Rows[dg_PNC.Rows.Count - 1].Cells[1].Style.Font        = new Font(dg_PNC.Font, FontStyle.Regular);
                            dg_PNC.Rows[dg_PNC.Rows.Count - 1].Cells[1].Style.Font        = new Font("Tahoma", 10F, GraphicsUnit.Pixel);

                            for (int counter2 = 2; counter2 < Limit + 2; counter2++)
                            {
                                if (SelectedRow[counter2] != string.Empty || SelectedRow[counter2 + Limit + 1] != string.Empty)
                                {
                                    dg_PNC.Rows.Add(string.Empty, SelectedRow[counter2], SelectedRow[counter2 + 1], SelectedRow[counter2 + Limit + 1], SelectedRow[counter2 + Limit + 2]);
                                }
                                counter2++;
                            }
                        }
                    }
                    this.Close();
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            else
            {
                this.Close();
                Cursor.Current = Cursors.Default;
                return;
            }
            if (Jak == "BU" || Jak == "EA1" || Jak == "EA2" || Jak == "EA3")
            {
                NumericUpDown Admin_Year  = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_YearQuantity", true).First();
                CheckBox      cb_AdminPNC = (CheckBox)MainProgram.Self.TabControl.Controls.Find("cb_AdminPNC", true).First();
                CheckBox      cb_AdminANC = (CheckBox)MainProgram.Self.TabControl.Controls.Find("cb_AdminANC", true).First();
                DataTable     Baza        = new DataTable();
                DataRow       FoundRow;

                int ile;

                if (cb_AdminANC.Checked)
                {
                    Data_Import.Singleton().Load_TxtToDataTable2(ref Baza, "ANC");
                }
                if (cb_AdminPNC.Checked)
                {
                    Data_Import.Singleton().Load_TxtToDataTable2(ref Baza, "PNC");
                }
                switch (Jak)
                {
                case "BU":
                    ile = 1;
                    break;

                case "EA1":
                    ile = 3;
                    break;

                case "EA2":
                    ile = 6;
                    break;

                case "EA3":
                    ile = 9;
                    break;

                default:
                    return;
                }

                if (Baza.Columns.Contains(Jak + "/12/" + Admin_Year.Text))
                {
                    for (int counter = ile; counter <= 12; counter++)
                    {
                        Baza.Columns.Remove(Jak + "/" + counter + "/" + Admin_Year.Text);
                    }
                }
                for (int counter = ile; counter <= 12; counter++)
                {
                    Baza.Columns.Add(new DataColumn(Jak + "/" + counter + "/" + Admin_Year.Text));
                }

                foreach (string OneRow in row)
                {
                    string[] row2 = OneRow.Split('\t');
                    if (row2[0] != "")
                    {
                        if (cb_AdminANC.Checked)
                        {
                            FoundRow = Baza.Select(string.Format("BUANC LIKE '%{0}%'", row2[0])).FirstOrDefault();
                        }
                        else
                        {
                            FoundRow = Baza.Select(string.Format("BUPNC LIKE '%{0}%'", row2[0])).FirstOrDefault();
                        }
                        int zmienna;
                        if (FoundRow != null)
                        {
                            zmienna = ile;
                            for (int counter = 1; counter <= (13 - ile); counter++)
                            {
                                FoundRow[Jak + "/" + zmienna + "/" + Admin_Year.Text] = row2[counter];
                                zmienna++;
                            }
                        }
                        else
                        {
                            DataRow NewRow = Baza.NewRow();
                            NewRow[0] = row2[0];
                            zmienna   = ile;
                            for (int counter = 1; counter <= (13 - ile); counter++)
                            {
                                NewRow[Jak + "/" + zmienna + "/" + Admin_Year.Text] = row2[counter];
                                zmienna++;
                            }
                            Baza.Rows.Add(NewRow);
                        }
                    }
                }
                if (cb_AdminANC.Checked)
                {
                    Data_Import.Singleton().Save_DataTableToTXT2(ref Baza, "ANC");
                }
                if (cb_AdminPNC.Checked)
                {
                    Data_Import.Singleton().Save_DataTableToTXT2(ref Baza, "PNC");
                }
                this.Close();
                Cursor.Current = Cursors.Default;
                return;
            }
            if (Jak == "AddMonthANC" || Jak == "AddMonthPNC")
            {
                NumericUpDown Admin_Year  = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_YearMonth", true).First();
                NumericUpDown Admin_Month = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_QuantityMonth", true).First();
                DataTable     Quantity    = new DataTable();
                DataRow       FoundRow;
                string        Miesiac = Admin_Month.Value.ToString() + "/" + Admin_Year.Value.ToString();


                if (Jak == "AddMonthANC")
                {
                    Data_Import.Singleton().Load_TxtToDataTable2(ref Quantity, "ANCMonth");
                }
                if (Jak == "AddMonthPNC")
                {
                    Data_Import.Singleton().Load_TxtToDataTable2(ref Quantity, "PNCMonth");
                }

                if (Quantity.Columns.Contains(Miesiac))
                {
                    Quantity.Columns.Remove(Miesiac);
                }
                Quantity.Columns.Add(new DataColumn(Miesiac));

                foreach (string OneRow in row)
                {
                    string[] NewValue = OneRow.Split('\t');

                    if (NewValue[0] != "")
                    {
                        if (Jak == "AddMonthANC")
                        {
                            FoundRow = Quantity.Select(string.Format("ANC LIKE '%{0}%'", NewValue[0])).FirstOrDefault();
                        }
                        else
                        {
                            FoundRow = Quantity.Select(string.Format("PNC LIKE '%{0}%'", NewValue[0])).FirstOrDefault();
                        }
                        if (FoundRow != null)
                        {
                            FoundRow[Miesiac] = NewValue[1];
                        }
                        else
                        {
                            DataRow NewRow = Quantity.NewRow();
                            NewRow[0]       = NewValue[0];
                            NewRow[Miesiac] = NewValue[1];
                            Quantity.Rows.Add(NewRow);
                        }
                    }
                }
                if (Jak == "AddMonthANC")
                {
                    Data_Import.Singleton().Save_DataTableToTXT2(ref Quantity, "ANCMonth");
                }
                if (Jak == "AddMonthPNC")
                {
                    Data_Import.Singleton().Save_DataTableToTXT2(ref Quantity, "PNCMonth");
                }
                this.Close();
                Cursor.Current = Cursors.Default;
                return;
            }
        }