예제 #1
0
        private void comp_data1_combobox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();

            string setNumber = comp_data1_combobox.SelectedItem as string;


            dataGridView1.NewRowNeeded +=
                new DataGridViewRowEventHandler(dataGridView1_NewRowNeeded);
            dataGridView1.RowsAdded +=
                new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
            dataGridView1.CellValueNeeded +=
                new DataGridViewCellValueEventHandler(dataGridView1_CellValueNeeded);



            //Controls.Add(dataGridView1);
            dataGridView1.VirtualMode           = true;
            dataGridView1.AllowUserToDeleteRows = false;
            dt1.Rows.Add();

            DataRow workRow = dt1.NewRow();

            var dt = dataGridView1.DataSource;

            int i = dataGridView1.Rows.Add();
            //dataGridView1.Rows.AddCopies(0,numberOfRows);
            //BindingSource bindingSource = new BindingSource();

            //bindingSource.Add(new VirtualData(setNumber));

//            dataGridView1.DataSource = bindingSource;
        }
예제 #2
0
        private void comp_data1_combobox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            this.dataGridView1.VirtualMode = true;
            click1 = true;

            string setNumber1 = comp_data1_combobox.SelectedItem as string;
            int    count1     = comp_data1_combobox.Items.Count;

            string[] set1 = new string[count1];
            set1    = setNumber1.Split('/');
            strarr1 = client.Load_data_from_DB(set1[0]);
            this.dataGridView1.RowCount = strarr1.GetLength(0) + 1;

            if (click2 == true && click1 == true)
            {
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    foreach (DataGridViewColumn col in dataGridView2.Columns)
                    {
                        dataGridView2.Rows[row.Index].Cells[col.Index].Style.BackColor = Color.White;
                    }
                }
                compare(strarr1, strarr2, 0, dataGridView1, dataGridView2);
                compare(strarr1, strarr2, 1, dataGridView2, dataGridView1);
                //dataGridView2.Refresh();
            }

            client.Close();
        }
예제 #3
0
        // 불러오기 버튼 - data 불러옴
        private void Load_Data_Button_Click(object sender, EventArgs e)
        {
            load_clicked = true;

            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();

            // combo box 값 선택 되었는지
            string selected_item = load_data_select_combobox.SelectedItem as String;

            if (selected_item != null)
            {
                string searchText = " ";
                selected_setNumber = selected_item.Substring(0, selected_item.IndexOf(searchText));
            }
            else
            {
                selected_setNumber = "";
            }
            Debug.WriteLine("Selected Number: " + selected_setNumber);
            if (selected_setNumber == "" || selected_setNumber == null)
            {
                load_clicked = false; Close();
            }       // combo box 값 선택되지 않음
            else    // combo box 값 선택 되었다면
            {
                int        arrSize = client.Load_data_from_DB(selected_setNumber).Length;
                int        col     = 19;
                int        row     = arrSize / col;
                string[][] dataArr = new string[arrSize][];
                dataArr = client.Load_data_from_DB(selected_setNumber);

                string[,] data = new string[row, col];
                //int index = 0;
                for (int r = 0; r < row; r++)
                {
                    for (int c = 0; c < col; c++)
                    {
                        data[r, c] = dataArr[r][c];
                        //index++;
                    }
                }
                LineListForm.table.Clear();
                DataRow dataRow = null;

                for (int r = 0; r < row; r++)
                {
                    dataRow = LineListForm.table.Rows.Add();
                    for (int c = 0; c < col; c++)
                    {
                        dataRow[c] = data[r, c];
                    }
                }
            }

            Close();
        }
예제 #4
0
        private void dataGridView1_CellValueNeeded(object sender,
                                                   DataGridViewCellValueEventArgs e)
        {
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();

            string setNumber = comp_data1_combobox.SelectedItem as string;

            if (newRowNeeded && e.RowIndex == numberOfRows)
            {
                e.Value = setNumber;
            }
        }
예제 #5
0
        private void setNumber()
        {
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int setNumCounts = client.Load_setNumbers().Length;

            string[] setNumbers = new string[setNumCounts];
            setNumbers = client.Load_setNumbers();

            comp_data1_combobox.Items.AddRange(setNumbers);
            comp_data2_combobox.Items.AddRange(setNumbers);

            client.Close();
        }
예제 #6
0
        DataTable table = new DataTable();  //테이블 생성
        public Save_Record()
        {
            InitializeComponent();

            save_record_view.RowHeadersVisible = false;                                                           // 첫번째 콜롬 안보이게
            save_record_view.ReadOnly          = true;                                                            // 값들 편집 불가능하게
            save_record_view.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; // 콜롬 이름 중앙 정렬
            save_record_view.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;              // 셀 값들 중앙 정렬

            // 열 생성
            table.Columns.Add(new DataColumn("Set", typeof(string)));
            table.Columns.Add(new DataColumn("Name", typeof(string)));
            table.Columns.Add(new DataColumn("Date", typeof(string)));
            table.Columns.Add(new DataColumn("Comment", typeof(string)));

            // 데이터 가져오기
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int redordsLength = client.Load_DB_Record().Length;

            string[] data = new string[redordsLength];
            data = client.Load_DB_Record();
            int col = 4;
            int row = redordsLength / 4;

            string[,] records = new string[row, col];
            int index = 0;

            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    records[r, c] = data[index];
                    index++;
                }
            }

            // 데이터 테이블에 값 넣기
            DataRow dataRow = null;

            for (int r = 0; r < row; r++)
            {
                dataRow = table.Rows.Add();
                for (int c = 0; c < col; c++)
                {
                    dataRow[c] = records[r, c];
                }
            }

            save_record_view.DataSource = table;    // grid view 에 데이터 불러옴
            //save_record_view.CurrentCell = null; // 선택 해제
        }
예제 #7
0
        private void colName(DataTable dt, DataGridView dgv)
        {
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int columnCounts = client.Load_column_name().Length; //컬럼 개수

            string[] columnName = new string[columnCounts];      //컬럼명 들어있는 string[]
            columnName = client.Load_column_name();              //컬럼이름 넣기

            for (int i = 0; i < columnName.Length; i++)
            {
                dt.Columns.Add(columnName[i]);
            }

            dgv.DataSource = dt;
            client.Close();
        }
예제 #8
0
        public DB_Load()
        {
            InitializeComponent();
            load_clicked = false;

            // combo box에 띄울 set, 이름, comment 불러오기
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int recordsLength = client.Load_DB_Record().Length;

            string[] data = new string[recordsLength];
            data = client.Load_DB_Record();
            int col = 4;
            int row = recordsLength / 4;

            string[,] records = new string[row, col];
            int index = 0;

            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    records[r, c] = data[index];
                    index++;
                }
            }
            index = 0;
            string[] str = new string[row];
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    if (c == 0 || c == 1)
                    {
                        str[index] += (records[r, c].Replace("\n", string.Empty) + " / ");
                    }
                    else if (c == 3)
                    {
                        str[index] += records[r, c].Replace("\n", string.Empty);
                    }
                }
                index++;
            }
            load_data_select_combobox.Items.AddRange(str);  // combo box에 값 추가
        }
예제 #9
0
        private void addColum(DataGridView dgv)
        {
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int columnCounts = client.Load_column_name().Length; //컬럼 개수

            string[] columnName = new string[columnCounts];      //컬럼명 들어있는 string[]
            columnName = client.Load_column_name();              //컬럼이름 넣기

            for (int i = 0; i < columnName.Length; i++)
            {
                DataGridViewTextBoxColumn Column = new DataGridViewTextBoxColumn();
                Column.HeaderText = columnName[i].ToString();
                Column.Name       = columnName[i].ToString();

                dgv.Columns.Add(Column);
            }

            client.Close();
        }
예제 #10
0
        //데이터 넣기
        private void store(string item = "", DataTable dt = null, DataGridView dgv = null)
        {
            dt.Clear();
            Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
            int columnCounts = client.Load_data_from_DB(item).Length;

            string[] dataArr = new string[columnCounts];
            dataArr = client.Load_data_from_DB(item);

            int col = client.Load_column_name().Length - 1;
            int row = columnCounts / col;

            string[,] data = new string[row, col];
            for (int r = 0, index = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    data[r, c] = dataArr[index];
                    index++;
                }
            }

            DataRow dr = null;

            for (int r = 0; r < row; r++)
            {
                dr = dt.Rows.Add();

                for (int c = 0; c < col; c++)
                {
                    dr[c + 1] = data[r, c];
                }
            }



            client.Close();
        }
예제 #11
0
        private void Store_DB_Click(object sender, EventArgs e)
        {
            newRow = show_loaded_data.RowCount - 1;
            newCol = show_loaded_data.ColumnCount;
            int dataCounts = newCol * newRow;

            object[] data = new object[dataCounts];

            Data_save.save_btn_clicked = false;
            bool PK_value_check = true;

            newRow = show_loaded_data.RowCount - 1;
            newCol = show_loaded_data.ColumnCount;
            int Counts = newCol * newRow;

            object[] inputs = new object[Counts];
            int      index  = 0;

            //PK 값들 다 채워져 있는지 체크
            for (int r = 0; r < newRow; r++)
            {
                for (int c = 0; c < newCol; c++)
                {
                    inputs[index] = show_loaded_data.Rows[r].Cells[c].Value;
                    if (c > 0 && c < 5)
                    {
                        if (inputs[index] == null || inputs[index].ToString() == "")
                        {
                            PK_value_check = false;
                        }
                    }
                    index++;
                }
            }
            if (PK_value_check == false)
            {
                MessageBox.Show($"UNIT, FLUID, SEQUENCE NUMBER, PIPING SPEC. 열을 채워야 합니다.");
            }
            else
            {
                object[,] data2 = new object[newRow, newCol];
                index           = 0;
                for (int r = 0; r < newRow; r++)
                {
                    for (int c = 0; c < newCol; c++)
                    {
                        data[index] = show_loaded_data.Rows[r].Cells[c].Value;
                        data2[r, c] = show_loaded_data.Rows[r].Cells[c].Value;
                        //Debug.WriteLine("data[" + r + "," + c + "] = " + data2[r, c]);
                        index++;
                    }
                }
                List <int> pickedRows = dataCheck(data2, newRow);

                if (pickedRows.Count == 0)  // 겹치는 PK 값이 없다면
                {
                    Data_save save = new Data_save();
                    save.ShowDialog();
                }
                else    // 겹치는 PK 값이 있다면
                {
                    foreach (int r in pickedRows)
                    {
                        for (int c = 1; c < 5; c++)
                        {
                            show_loaded_data.Rows[r].Cells[c].Style.BackColor = System.Drawing.Color.Pink;
                        }
                    }
                    MessageBox.Show("값이 겹치는 행이 있습니다.");
                }
            }

            // PK값 체크를 통과하고 저장 버튼이 눌리면
            if (Data_save.save_btn_clicked)
            {
                bool success = false;
                Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
                success = client.Put_data_into_DB(data, newRow, newCol, Data_save.user_name_input, Data_save.date_input, Data_save.comment_input);
                if (success)
                {
                    MessageBox.Show($"데이터를 성공적으로 저장했습니다.");
                }
                else
                {
                    MessageBox.Show($"DB 연결 실패");
                }
            }
            else
            {
                Debug.WriteLine("저장 안됌");
            }
        }
예제 #12
0
        private void Excel_Button_Click(object sender, EventArgs e)
        {
            //엑셀 변수 선언
            Excel.Application xlApp       = null;
            Excel.Workbook    xlWorkbook  = null;
            Excel.Worksheet   xlWorksheet = null;
            object[,] data;
            //파일 선택
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "엑셀 파일 (*.xlsx)|*.xlsx|엑셀 파일 (*.xls)|*.xls";

            //파일을 열수 있는지 확인
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    xlApp       = new Excel.Application();
                    xlWorkbook  = xlApp.Workbooks.Open(ofd.FileName);// 엑셀 파일 가져오기
                    xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);

                    range = xlWorksheet.UsedRange;   //엑셀 시트범위 설정

                    data      = range.Value;         // 지정된 시트 2차원 배열에 담기
                    rowCounts = range.Rows.Count;    // 행 개수
                    colCounts = range.Columns.Count; //열 개수

                    //Debug.WriteLine("col counts: " + colCounts);

                    int dataStartRow = 1;
                    int dataStartCol = 1;
                    int dataEndRow   = 0;
                    int dataEndCol   = 0;

                    for (int r = 1; r < rowCounts; r++)
                    {
                        for (int c = 1; c < colCounts; c++)
                        {
                            Debug.WriteLine("row, col: " + r + ", " + c);
                            if (data[r, c] != null)
                            {
                                Debug.WriteLine("data[r, c]: " + data[r, c]);
                                if (data[r, c].ToString().Equals("P&ID NO."))
                                {
                                    dataEndRow = r;
                                    dataEndCol = c;
                                    break;
                                }
                                else if (data[r, c].ToString().Equals("LINE INFORMATION"))
                                {
                                    dataStartRow = r + 1;
                                    dataStartCol = c;
                                    break;
                                }
                            }
                        }
                        if (dataEndRow != 0)
                        {
                            break;
                        }
                    }
                    Debug.WriteLine("data start row: " + dataStartRow);
                    Debug.WriteLine("data start col: " + dataStartCol);
                    Debug.WriteLine("data end row: " + dataEndRow);


                    if ((dataEndCol - dataStartCol + 1) != 19)
                    {    // 콜롬 개수가 지정된 19개가 아니라면 경고 창 띄움
                        MessageBox.Show("정의된 열 개수를 벗어났습니다.\n 데이터를 저장하지 않았습니다.");
                    }
                    else
                    {
                        newRow = rowCounts - dataStartRow;
                        newCol = colCounts - dataStartCol;  //19
                        int newArrayCounts = newRow * newCol;
                        arr = new object[newArrayCounts];
                        int index = 0;

                        for (int r = dataStartRow + 1; r <= rowCounts; r++)
                        {
                            if (index > newArrayCounts)
                            {
                                break;
                            }
                            for (int c = dataStartCol; c < colCounts; c++)
                            {
                                arr[index] = data[r, c];
                                index++;
                                //Debug.WriteLine("data[" + r + ", " + c + "] = " + data[r, c]);
                            }
                        }
                        bool success = false;
                        Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client();
                        success = client.Put_data_into_DB(arr, newRow, newCol, "", "", "");
                        if (success)
                        {
                            MessageBox.Show($"데이터를 성공적으로 저장했습니다.");
                        }
                        else
                        {
                            MessageBox.Show($"DB 연결 실패");
                        }
                    }
                    xlWorkbook.Close(true);
                    xlApp.Quit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    ReleaseExcelObject(xlWorksheet);
                    ReleaseExcelObject(xlWorkbook);
                    ReleaseExcelObject(xlApp);
                }
            }
            else
            {
                MessageBox.Show($"저장 할 파일이 선택 되지 않았습니다.");
            }
        }