Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "anphabe Tên")
            {
                int rn = 1;
                //dbVeMTDataContext db = new dbVeMTDataContext();

                //var b = from s in db.vemts
                //        orderby db.layTen(s.hoten)
                //        select (s.hoten);
                //List<String> list1 = new List<String>();
                //list1 = b.ToList();
                ////MessageBox.Show(b.ToString());
                ////danh stt
                //foreach (String item1 in b)
                //{
                //    List<vemt> dsSbd2 = new List<vemt>();
                //   // List<vemt> dsSbd3 = new List<vemt>();
                //    dsSbd2 = (from purchase in db.vemts
                //              where purchase.hoten == item1
                //              select purchase).ToList();

                //    // dsSbd.Count();
                //    //MessageBox.Show(dsSbd1.Count().ToString());

                //    for (int i = 0; i < dsSbd2.Count(); i++)
                //    {
                //        dsSbd2[i].stt = rn;
                //        rn = rn + 1;
                //        //MessageBox.Show(rn.ToString());
                //    }

                //}

                dbVeMTDataContext db = new dbVeMTDataContext();
                var qry1 = db.vemts.OrderBy(a => db.layTen(a.hoten));
                List<vemt> list1 = new List<vemt>();
                list1 = qry1.ToList();
                //danh stt
                int n = list1.Count;
                for (int i = 0; i < n; i++)
                {
                    list1[i].stt = i + 1;
                }

                    var qry = from s in db.vemts
                              orderby db.layTen(s.hoten)
                              select (s.hoten);

                List<String> list = new List<String>();
                list = qry.ToList();

                    foreach (String item in list)
                    {
                        List<vemt> dsSbd = new List<vemt>();
                        List<vemt> dsSbd1 = new List<vemt>();
                        dsSbd = (from purchase in db.vemts
                                 where purchase.hoten == item
                                 select purchase).ToList();

                        dsSbd1 = (from r in db.vemts
                                  orderby r.hoten
                                  select r).ToList();
                        // dsSbd.Count();
                        //MessageBox.Show(dsSbd1.Count().ToString());
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {

                            decimal? stt = dsSbd[i].stt;
                            dsSbd[i].phongthi = Convert.ToDouble((int)((stt - 1) / numericUpDown1.Value ) + 1);
                           // MessageBox.Show(stt.ToString());
                           // rn = rn + 1;
                        }
                       // int sl = dsSbd.Count();

                    }

                    db.SubmitChanges();
                   // MessageBox.Show("Đã thực hiện xong");
                    double d = (int)(list1.Count() / numericUpDown1.Value) + 1;
                    var qry3 = from s in db.vemts
                               where s.phongthi == d
                               select (s.hoten);
                    int sl = qry3.Count();
                  //  MessageBox.Show(sl.ToString());
                if (numericUpDown2.Value.ToString()=="")
                {
                    MessageBox.Show("Mời nhập vào số thí sinh cần gộp");
                }
                else if (sl<= numericUpDown2.Value)
                {
                    List<vemt> upt = new List<vemt>();
                    upt = (from v in db.vemts
                           where v.phongthi == d
                           select v).ToList();
                    //for (int i = 0; i < upt.Count(); i++)
                    //{

                    //    upt[i].phongthi = Convert.ToDouble((int)((stt - 1) / numericUpDown1.Value) + 1);
                    //    // MessageBox.Show(stt.ToString());
                    //    // rn = rn + 1;
                    //}

                    foreach (vemt v in upt)
                    {
                        v.phongthi = d - 1;
                    }
                    //upt.phongthi = (d - 1.0);

                    db.SubmitChanges();
                }
                //a = số lượng người ở phòng d
                // nếu d < số người quy định*
                //{
                // update pt=d-1 cua where pt = d
            //}
                    MessageBox.Show("Chia thành công");
                    //MessageBox.Show(list.Count.ToString());

                  //  loadgrv();
                }
        }
Ejemplo n.º 2
0
        //private void loadgrv()
        //{
        //    dbVeMTDataContext db = new dbVeMTDataContext();
        //    dgv_thisinh.Rows.Clear();
        //    var list = from t in db.vemts select new { t.sohs, t.hoten, Type = t.phai == true ? "Nam" : "Nữ",t.sobaodanh };
        //    dgv_thisinh.DataSource = list;
        //    dgv_thisinh.Columns[0].HeaderText = "Số HS";
        //    dgv_thisinh.Columns[1].HeaderText = "Họ và tên";
        //    dgv_thisinh.Columns[2].HeaderText = "Giới tính";
        //    dgv_thisinh.Columns[3].HeaderText = "Số báo danh";
        //    //this.dgv_thisinh.Columns[3].DefaultCellStyle.Format = ("dd/MM/yyyy");
        //    //this.dgv_thisinh.Columns[6].DefaultCellStyle.Format = ("dd/MM/yyyy");
        //    //    if (dgv_thisinh.CurrentRow.Cells[2].Value.ToString() == "True")
        //    //    {
        //    //        dgv_thisinh.CurrentRow.Cells[2].Value = "name";
        //    //    }
        //    //    else { dgv_thisinh.CurrentRow.Cells[2].Value = "nữ"; }
        //}
        private void button1_Click(object sender, EventArgs e)
        {
            //Random rd = new Random(1);
            //int rn = rd.Next(1, 100);
            if (comboBox1.Text == "anphabe Tên")
            {
                int rn = 1;
                dbVeMTDataContext db = new dbVeMTDataContext();
                //db.layTen();
                //var sort = from s in db.vemts
                //           orderby db.layTen(s.hoten)
                //           select s.hoten;
                var qry1 = db.vemts.OrderBy(a => db.layTen(a.hoten)).Select(b => b.hoten);
                List<String> list1 = new List<String>();
                list1 = qry1.ToList();
              //  var qry = db.vemts.OrderBy(a => db.layTen(a.phongthi));
                //private ArrayList al = new ArrayList();
                List<String> ds = new List<String>();
              //  ds = sort.ToList();
                // MessageBox.Show(ds.ToString());
                foreach (String item in list1)
                {
                    List<vemt> dsSbd = new List<vemt>();
                    List<vemt> dsSbd1 = new List<vemt>();
                    dsSbd = (from purchase in db.vemts
                             where purchase.hoten == item
                             select purchase).ToList();

                    dsSbd1 = (from r in db.vemts
                              orderby r.hoten
                              select r).ToList();
                    // dsSbd.Count();
                    //MessageBox.Show(dsSbd1.Count().ToString());
                    if (dsSbd1.Count() < 10)
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            string s = rn.ToString().PadLeft(1, '0') ;

                            dsSbd[i].sobaodanh = textBox1.Text + s;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }
                    else if (dsSbd1.Count() < 100)
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            //string s = i.ToString().PadLeft(2, '0') +rn.ToString();
                            string s = rn.ToString().PadLeft(2, '0');
                            dsSbd[i].sobaodanh = textBox1.Text + s;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }
                    else if (dsSbd1.Count() < 1000)
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            //string s = i.ToString().PadLeft(2, '0') +rn.ToString();
                            string s = rn.ToString().PadLeft(3, '0');
                            dsSbd[i].sobaodanh = textBox1.Text + s;//so phach la tang lien tuc
                           // MessageBox.Show(dsSbd[i].sobaodanh.ToString());
                            rn = rn + 1;
                        }

                    }
                    else
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            string s = rn.ToString().PadLeft(4, '0');

                            dsSbd[i].sobaodanh = textBox1.Text + s;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }

                }

                db.SubmitChanges();

                MessageBox.Show("Đã thực hiện xong");

               // loadgrv();
            }
            else
            {
                int rn = 1;
                dbVeMTDataContext db = new dbVeMTDataContext();
                //db.layTen();
                var sort = from s in db.vemts
                           orderby s.sohs
                           select (s.sohs);
                //private ArrayList al = new ArrayList();
                List<String> ds = new List<String>();
                ds = sort.ToList();
                // MessageBox.Show(ds.ToString());
                foreach (String item in sort)
                {
                    List<vemt> dsSbd = new List<vemt>();
                    List<vemt> dsSbd1 = new List<vemt>();
                    dsSbd = (from purchase in db.vemts
                             where purchase.sohs == item
                             select purchase).ToList();

                    dsSbd1 = (from r in db.vemts
                              orderby r.sohs
                              select r).ToList();
                    // dsSbd.Count();
                   // MessageBox.Show(dsSbd1.Count().ToString());
                    if (dsSbd1.Count() < 10)
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            string a = rn.ToString().PadLeft(1, '0');

                            dsSbd[i].sobaodanh = textBox1.Text + a;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }
                    else if (dsSbd1.Count() < 100)
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            string a = rn.ToString().PadLeft(2, '0');

                            dsSbd[i].sobaodanh = textBox1.Text + a;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < dsSbd.Count(); i++)
                        {
                            string a = rn.ToString().PadLeft(3, '0');

                            dsSbd[i].sobaodanh = textBox1.Text + a;//so phach la tang lien tuc
                            // MessageBox.Show(dsSbd[i].phach.ToString());
                            rn = rn + 1;
                        }
                    }

                }

                db.SubmitChanges();
                MessageBox.Show("Đã thực hiện xong");

              //  loadgrv();
            }
        }