/// <summary>
        /// 리스트뷰에서 브릭선택시 해당 정보 및 데이터 저장 및 보여주기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lv_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lv_Type.SelectedItems.Count > 0)
            {
                select_data = null;
                select_data = new Brick_sub_data();
                lb_SubParts.Items.Clear();
                tb_Entered.Text = "";
                tb_BQ.Text = "";
                tb_Status.Text = "";
                tb_Result.Text = "";

                if (lv_Type.SelectedItems[0].Group.Name == "Registered Brick")
                {
                    string str_q = "select * from part where part_name = '" + lv_Type.SelectedItems[0].Text + "'";

                    OleDbDataReader oddr = connector.select_Data(str_q);

                    while (oddr.Read())
                    {
                        select_data.part_id = oddr.GetInt32(0);
                        select_data.part_name = oddr.GetString(1);
                        select_data.part_desc = oddr.GetString(3);
                        select_data.part_type = oddr.GetString(4);
                        select_data.part_status = oddr.GetString(5);
                        tb_Status.Text = oddr.GetString(5);

                        select_data.part_result = oddr.GetString(6);
                        tb_Result.Text = oddr.GetString(6);

                        select_data.part_entered = oddr.GetString(10);
                        tb_Entered.Text = oddr.GetString(10);

                        select_data.part_author = oddr.GetString(11);
                        select_data.best_qulity = oddr.GetString(12);
                        tb_BQ.Text = oddr.GetString(12);
                    }

                    str_q = "select sequences.seq_data from sequences, part where part.part_name = '" + lv_Type.SelectedItems[0].Text + "' and part.part_id = sequences.part_id";

                    oddr = connector.select_Data(str_q);

                    while (oddr.Read())
                    {
                        select_data.part_seq = oddr.GetString(0);
                    }

                    str_q = "select p.part_name from part as p, specified_subparts as sp where sp.part_id = " + select_data.part_id + " and sp.subpart_id = p.part_id";

                    oddr = connector.select_Data(str_q);

                    while (oddr.Read())
                    {
                        select_data.subparts.Add(oddr.GetString(0));
                        lb_SubParts.Items.Add(oddr.GetString(0));
                    }
                }
                else if (lv_Type.SelectedItems[0].Group.Name == "User's Brick")
                {
                    string str_q = "select * from userbricks where part_name = '" + lv_Type.SelectedItems[0].Text + "'";

                    OleDbDataReader oddr = connector.select_Data(str_q);

                    while (oddr.Read())
                    {
                        select_data.part_name = oddr.GetString(0);
                        select_data.part_desc = oddr.GetString(2);
                        select_data.part_type = oddr.GetString(1);
                        select_data.part_seq = oddr.GetString(3);
                    }
                }

            }
        }
        /// <summary>
        /// 브릭데이터 추가하기
        /// </summary>
        /// <param name="bsd"></param>
        public void Add_BrickData(Brick_sub_data bsd)
        {
            if (isCloning)
            {
                if (MessageBox.Show("Do you want to cancel Cloning?", "Cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.newBD.cancel_scar();
                    cancel_cloning();
                }
                else
                {
                    return;
                }
            }

            this.newBD.sl_subpart_list.Add(this.newBD.sl_subpart_list.Count, bsd);

            paint_BrickData();
            listbox_from_BrickData();
            paint_linear_Seq();
        }
        private void bt_Scar_Click(object sender, EventArgs e)
        {
            Brick_sub_data _bsd = new Brick_sub_data();
            _bsd.part_name = "Scar";
            _bsd.part_type = "Scar";
            _bsd.part_seq = "";

            this.Add_BrickData(_bsd);
        }
        /// <summary>
        /// 클로닝 시퀀스 하는거염
        /// </summary>
        /// <param name="bb_name"></param>
        /// <param name="bb_seq"></param>
        /// <param name="rs1"></param>
        /// <param name="i_rs1"></param>
        /// <param name="rs2"></param>
        /// <param name="i_rs2"></param>
        public void processing_Seq(string bb_name, string bb_seq, string rs1, int i_rs1, string rs2, int i_rs2, bool isReg)
        {
            // 먼저 브릭리스트 앞에 해당되는 pre, suf 붙여주기
            // 그런 다음에 bb seq를 가공하고 seq의 정보를 보고

            // 먼저 위치계산을 먼저 해서 브릭이 앞에 갈지 뒤에 갈지를 결정

            // 하지만 rs가 오는 순서는 prefix인지 suffix인지는 결정되어 있으니

            string str_brick_prefix;
            string str_brick_suffix;

            string str_plasmid_seq;

            if (rs1 == "Ecor1")
            {
                if (this.newBD.sl_subpart_list[0].part_seq.StartsWith("atg"))
                {
                    str_brick_prefix = "cgcggccgcttctaga";
                }
                else
                {
                    str_brick_prefix = "cgcggccgcttctagag";
                }
            }
            else
            {
                if (this.newBD.sl_subpart_list[0].part_seq.StartsWith("atg"))
                {
                    str_brick_prefix = "ag";
                }
                else
                {
                    str_brick_prefix = "a";
                }
            }

            if (rs2 == "Pst1")
            {
                str_brick_suffix = "tactagtagcggccgc";
            }
            else
            {
                str_brick_suffix = "ta";
            }

            // 제한효소가 뒤집어 있으면 서열 뒤집기
            // 아니면 그대로
            // 그리고 나서 prefix 넣고 브릭 넣고 서픽스 넣고 제한효소 넣고 시퀀스 넣고 제한효소 넣고 끝.

            // 백본 시퀀스 서브시퀀스 가져오기
            // rs1 이 더 큼
            // rs2 는 앞 쪽임

            str_plasmid_seq = bb_seq.Substring(i_rs2 + 5, Math.Abs(i_rs1 + 1 - (i_rs2 + 5)));

            // 현재 백본 시퀀스 처리

            if (i_rs2 > i_rs1)
            {
                string str_plasmid_seq_d = "";
                foreach (char c in str_plasmid_seq.ToCharArray())
                {
                    switch (c)
                    {
                        case 'a':
                            str_plasmid_seq_d += 't';
                            break;
                        case 't':
                            str_plasmid_seq_d += 'a';
                            break;
                        case 'c':
                            str_plasmid_seq_d += 'g';
                            break;
                        case 'g':
                            str_plasmid_seq_d += 'c';
                            break;
                    }
                }
                str_plasmid_seq = str_plasmid_seq_d;
            }

            // 클로닝 리스트 작성
            // 1. Prefix
            // 2. 브릭리스트
            // 3. Suffix
            // 4. 제한효소
            // 5. 백본 시퀀스
            // 6. 제한효소

            int i = 0;

            Brick_sub_data _bsd = new Brick_sub_data();
            _bsd.part_name = "Prefix";
            _bsd.part_type = "Prefix";
            _bsd.part_seq = str_brick_prefix;
            this.newBD.sl_cloning_list.Add(0, _bsd);

            for (i = 1; i < this.newBD.sl_subpart_list.Count + 1; i++)
            {
                this.newBD.sl_cloning_list.Add(i, newBD.sl_subpart_list[i - 1]);
            }

            _bsd = new Brick_sub_data();
            _bsd.part_name = "Suffix";
            _bsd.part_type = "Suffix";
            _bsd.part_seq = str_brick_suffix;
            this.newBD.sl_cloning_list.Add(i, _bsd);

            _bsd = new Brick_sub_data();
            _bsd.part_name = rs2;
            _bsd.part_type = rs2;
            _bsd.part_seq = this.get_SR_seq(rs1);
            this.newBD.sl_cloning_list.Add(i + 1, _bsd);

            _bsd = new Brick_sub_data();
            //_bsd.part_name = bb_name;

            connector = new DBconnector();

            if (isReg) // 등록된 브릭이면
            {
                string str_q = "select * from part where part_name = '" + bb_name + "'";

                OleDbDataReader oddr = connector.select_Data(str_q);

                while (oddr.Read())
                {
                    _bsd.part_id = oddr.GetInt32(0);
                    _bsd.part_name = oddr.GetString(1);
                    _bsd.part_desc = oddr.GetString(3);
                    _bsd.part_type = oddr.GetString(4);
                    _bsd.part_status = oddr.GetString(5);

                    _bsd.part_result = oddr.GetString(6);

                    _bsd.part_entered = oddr.GetString(10);

                    _bsd.part_author = oddr.GetString(11);
                    _bsd.best_qulity = oddr.GetString(12);
                }

                str_q = "select p.part_name from part as p, specified_subparts as sp where sp.part_id = " + _bsd.part_id + " and sp.subpart_id = p.part_id";

                oddr = connector.select_Data(str_q);

                while (oddr.Read())
                {
                    _bsd.subparts.Add(oddr.GetString(0));
                    lb_Subparts.Items.Add(oddr.GetString(0));
                }
            }
            else
            {
                string str_q = "select * from userbricks where part_name = '" + bb_name + "'";

                OleDbDataReader oddr = connector.select_Data(str_q);

                while (oddr.Read())
                {
                    _bsd.part_name = oddr.GetString(0);
                    _bsd.part_desc = oddr.GetString(2);
                    _bsd.part_type = oddr.GetString(1);
                    _bsd.part_seq = oddr.GetString(3);
                }
            }

            _bsd.part_seq = str_plasmid_seq;
            this.newBD.sl_cloning_list.Add(i + 2, _bsd);

            _bsd = new Brick_sub_data();
            _bsd.part_name = rs1;
            _bsd.part_name = rs1;
            _bsd.part_seq = this.get_SR_seq(rs2);
            this.newBD.sl_cloning_list.Add(i + 3, _bsd);
        }
        public void data_load()
        {
            StringBuilder sbLoad = new StringBuilder();
            Stream sr_Stream;

            connector = new DBconnector();

            OpenFileDialog openFD = new OpenFileDialog();
            openFD.Filter = "project files (*brp)|*.brp";

            if (openFD.ShowDialog() == DialogResult.OK)
            {
                if ((sr_Stream = openFD.OpenFile()) != null)
                {
                    this.newBD = new Brick_data();

                    TextReader tr = new StreamReader(sr_Stream);
                    string _str;

                    int i = 0;
                    int j = 0;
                    while ((_str = tr.ReadLine()) != null)
                    {

                        if (_str.Length == 0)
                        {
                            continue;
                        }

                        if (i == 0)
                        {
                            this.newBD.str_brick_name = _str;
                        }
                        else if (i == 1)
                        {
                            this.newBD.str_brick_type = _str;
                        }
                        else if (i == 2)
                        {
                            this.newBD.str_brick_desc = _str;
                        }
                        else
                        {
                            // 여기서 브릭 네임으로 가져와서 정보를 서브 데이터로 저장해야함

                            Brick_sub_data bsd = new Brick_sub_data();
                            string[] split_str = _str.Split(' ');

                            if (split_str[0] == "Scar" || split_str[0] == "Spe1+Xba1")
                            {
                                // 여긴 스칼임
                                bsd.part_name = "Scar";
                                bsd.part_type = "Scar";
                                bsd.part_seq = "";

                                this.newBD.sl_subpart_list.Add(j, bsd);

                            }
                            else if (split_str[1] == "-1")
                            {
                                // 유저브릭임.
                                string str_q = "select * from userbricks where part_name = '" + split_str[0] + "'";

                                OleDbDataReader oddr = connector.select_Data(str_q);

                                while (oddr.Read())
                                {
                                    bsd.part_name = oddr.GetString(0);
                                    bsd.part_type = oddr.GetString(1);
                                    bsd.part_desc = oddr.GetString(2);
                                    bsd.part_seq = oddr.GetString(3);

                                    if (split_str.Count() > 2)
                                    {
                                        bsd.part_icon = int.Parse(split_str[2]);
                                    }
                                }

                                this.newBD.sl_subpart_list.Add(j, bsd);
                            }
                            else
                            {
                                string str_q = "select * from part where part_name = '" + split_str[0] + "'";

                                OleDbDataReader oddr = connector.select_Data(str_q);

                                while (oddr.Read())
                                {
                                    bsd.part_id = oddr.GetInt32(0);
                                    bsd.part_name = oddr.GetString(1);
                                    bsd.part_desc = oddr.GetString(3);
                                    bsd.part_type = oddr.GetString(4);
                                    bsd.part_status = oddr.GetString(5);
                                    bsd.part_result = oddr.GetString(6);
                                    bsd.part_entered = oddr.GetString(10);
                                    bsd.part_author = oddr.GetString(11);
                                    bsd.best_qulity = oddr.GetString(12);
                                }

                                str_q = "select sequences.seq_data from sequences, part where part.part_name = '" + split_str[0] + "' and part.part_id = sequences.part_id";

                                oddr = connector.select_Data(str_q);

                                while (oddr.Read())
                                {
                                    bsd.part_seq = oddr.GetString(0);
                                }

                                str_q = "select p.part_name from part as p, specified_subparts as sp where sp.part_id = " + bsd.part_id + " and sp.subpart_id = p.part_id";

                                oddr = connector.select_Data(str_q);

                                while (oddr.Read())
                                {
                                    bsd.subparts.Add(oddr.GetString(0));
                                }

                                if (split_str.Count() > 2)
                                {
                                    bsd.part_icon = int.Parse(split_str[2]);
                                }

                                this.newBD.sl_subpart_list.Add(j, bsd);
                            }

                            j++;
                        }
                        i++;
                    }

                }
            }

            connector = null;
            this.change_FromName();
        }
        /// <summary>
        /// 클로닝 시퀀스 하는거염
        /// </summary>
        /// <param name="bb_name"></param>
        /// <param name="bb_seq"></param>
        /// <param name="rs1"></param>
        /// <param name="i_rs1"></param>
        /// <param name="rs2"></param>
        /// <param name="i_rs2"></param>
        public void processing_Seq(string bb_name ,string bb_seq, string rs1, int i_rs1, string rs2, int i_rs2)
        {
            // 먼저 브릭리스트 앞에 해당되는 pre, suf 붙여주기
            // 그런 다음에 bb seq를 가공하고 seq의 정보를 보고

            // 먼저 위치계산을 먼저 해서 브릭이 앞에 갈지 뒤에 갈지를 결정

            // 하지만 rs가 오는 순서는 prefix인지 suffix인지는 결정되어 있으니

            string str_brick_prefix;
            string str_brick_suffix;

            string str_plasmid_seq;

            if (rs1 == "Ecor1")
            {
                if (this.newBD.sl_subpart_list[0].part_seq.StartsWith("atg"))
                {
                    str_brick_prefix = "cgcggccgcttctaga";
                }
                else
                {
                    str_brick_prefix = "cgcggccgcttctagag";
                }
            }
            else
            {
                if (this.newBD.sl_subpart_list[0].part_seq.StartsWith("atg"))
                {
                    str_brick_prefix = "ag";
                }
                else
                {
                    str_brick_prefix = "a";
                }
            }

            if (rs2 == "Pst1")
            {
                str_brick_suffix = "tactagtagcggccgc";
            }
            else
            {
                str_brick_suffix = "ta";
            }

            // 제한효소가 뒤집어 있으면 서열 뒤집기
            // 아니면 그대로
            // 그리고 나서 prefix 넣고 브릭 넣고 서픽스 넣고 제한효소 넣고 시퀀스 넣고 제한효소 넣고 끝.

            // 백본 시퀀스 서브시퀀스 가져오기
            // rs1 이 더 큼
            // rs2 는 앞 쪽임

            str_plasmid_seq = bb_seq.Substring(i_rs2 + 5, Math.Abs(i_rs1 + 1 - (i_rs2 + 5)));

            // 현재 백본 시퀀스 처리

            if (i_rs2 > i_rs1)
            {
                string str_plasmid_seq_d = "";
                foreach (char c in str_plasmid_seq.ToCharArray())
                {
                    switch(c){
                        case 'a':
                            str_plasmid_seq_d += 't';
                            break;
                        case 't':
                            str_plasmid_seq_d += 'a';
                            break;
                        case 'c':
                            str_plasmid_seq_d += 'g';
                            break;
                        case 'g':
                            str_plasmid_seq_d += 'c';
                            break;
                    }
                }
                str_plasmid_seq = str_plasmid_seq_d;
            }

            // 클로닝 리스트 작성
            // 1. Prefix
            // 2. 브릭리스트
            // 3. Suffix
            // 4. 제한효소
            // 5. 백본 시퀀스
            // 6. 제한효소

            int i = 0;

            Brick_sub_data _bsd = new Brick_sub_data();
            _bsd.part_name = "Prefix";
            _bsd.part_seq = str_brick_prefix;
            this.newBD.sl_cloning_list.Add(0, _bsd);

            for (i = 1; i < this.newBD.sl_subpart_list.Count+1; i++ )
            {
                this.newBD.sl_cloning_list.Add(i, newBD.sl_subpart_list[i - 1]);
            }

            _bsd = new Brick_sub_data();
            _bsd.part_name = "Suffix";
            _bsd.part_seq = str_brick_suffix;
            this.newBD.sl_cloning_list.Add(i, _bsd);

            _bsd = new Brick_sub_data();
            _bsd.part_name = rs2;
            _bsd.part_seq = this.get_SR_seq(rs1);
            this.newBD.sl_cloning_list.Add(i+1, _bsd);

            _bsd = new Brick_sub_data();
            _bsd.part_name = bb_name;
            _bsd.part_seq = str_plasmid_seq;
            this.newBD.sl_cloning_list.Add(i + 2, _bsd);

            _bsd = new Brick_sub_data();
            _bsd.part_name = rs1;
            _bsd.part_seq = this.get_SR_seq(rs2);
            this.newBD.sl_cloning_list.Add(i + 3, _bsd);
        }