Ejemplo n.º 1
0
        public void addDuBaoCung(DTO_DuBao dubao)
        {
            try
            {
                // Ket noi
                _conn.Open();

                // Query string
                string SQL = string.Format("INSERT INTO dubaocung(MaTruong, Nam,DuBaoTuyenSinh,TiLeDo,SoLaoDong) VALUES ('{0}','{1}','{2}','{3}','{4}')", dubao.MA_TRUONG, dubao.NAM, dubao.DU_BAO_TUYEN_SINH, dubao.TI_LE_DO, dubao.SO_LAO_DONG);
                // Command
                Console.WriteLine(SQL);
                SqlCommand cmd = new SqlCommand(SQL, _conn);
                // Query và kiểm tra
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                MessageBox.Show("Có lỗi trong khi cập nhật dự báo cung!");
            }
            finally
            {
                // Dong ket noi
                _conn.Close();
            }
        }
Ejemplo n.º 2
0
        public void updateDuBaoCung(DTO_DuBao db)
        {
            try
            {
                // Ket noi
                _conn.Open();

                // Query string
                string SQL = string.Format("update dubaocung set SoLaoDong='{0}', DuBaoTuyenSinh='{1}',TiLeDo='{2}' where dubaocung.Nam='{3}' AND dubaocung.MaTruong='{4}'", db.SO_LAO_DONG, db.DU_BAO_TUYEN_SINH, db.TI_LE_DO, db.NAM, db.MA_TRUONG);
                Console.WriteLine(SQL);
                SqlCommand cmd = new SqlCommand(SQL, _conn);
                // Query và kiểm tra
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                MessageBox.Show("Có lỗi trong khi update dữ liệu tuyển sinh!");
            }
            finally
            {
                // Dong ket noi
                _conn.Close();
            }
        }
Ejemplo n.º 3
0
        public bool updateTruong_Dubaocung(string matruong)
        {
            _conn.Open();
            string SQL = string.Format("Select Nam,ChiTieu from TuyenSinh where ChiTieu > 0 AND MaTruong = '" + matruong + "'");

            Console.WriteLine(SQL);
            // Command
            SqlCommand    cmd    = new SqlCommand(SQL, _conn);
            SqlDataReader data   = cmd.ExecuteReader();
            List <DTO_CT> listCt = new List <DTO_CT>();

            while (data.Read())
            {
                DTO_CT ct = new DTO_CT(Int32.Parse(data[0].ToString()), Int32.Parse(data[1].ToString()));
                listCt.Add(ct);
            }
            _conn.Close();

            int n = listCt.Count;

            if (n != 0)
            {
                try
                {
                    _conn.Open();
                    string SQL_1 = string.Format("Select TuyenSinh.MaTruong,TiLeDo,SoLaoDong,TuyenSinh.Nam as ts_nam,TuyenSinh.ChiTieu as ts_chitieu,dubaocung.Nam as dbc_nam from dubaocung Inner Join TuyenSinh on TuyenSinh.MaTruong = dubaocung.MaTruong where dubaocung.MaTruong = '" + matruong + "'");
                    Console.WriteLine(SQL_1);
                    // Command
                    SqlCommand    cmd_1  = new SqlCommand(SQL_1, _conn);
                    SqlDataReader data_1 = cmd_1.ExecuteReader();
                    while (data_1.Read())
                    {
                        int    dbc_nam = Int32.Parse(data_1[5].ToString());
                        int    ts_nam  = Int32.Parse(data_1[3].ToString());
                        double tile    = Convert.ToDouble(data_1[1].ToString());
                        int    chitieu = 0;
                        if (dbc_nam > 2017)
                        {
                            chitieu = bptoithieu(listCt, n, dbc_nam);
                            int       dubao  = (int)(chitieu * tile) / 100;
                            DTO_DuBao db     = new DTO_DuBao(matruong, (float)tile, dubao, dbc_nam, chitieu);
                            DAL_DuBao dal_db = new DAL_DuBao();
                            dal_db.updateDuBaoCung(db);
                        }
                        else
                        {
                            if (dbc_nam == ts_nam)
                            {
                                chitieu = Int32.Parse(data_1[4].ToString());
                                int       dubao  = (int)(chitieu * tile) / 100;
                                DTO_DuBao db     = new DTO_DuBao(matruong, (float)tile, dubao, dbc_nam, chitieu);
                                DAL_DuBao dal_db = new DAL_DuBao();
                                dal_db.updateDuBaoCung(db);
                            }
                        }
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Có lỗi trong khi update!");
                }
                finally
                {
                    // Dong ket noi
                    _conn.Close();
                }
            }
            return(false);
        }