コード例 #1
0
ファイル: Form2.cs プロジェクト: HuyLuuVan/CSharp-Winform
 private void btnOK2_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(txtMa2.Text) || cbbCapDeTai2.SelectedItem == null || cbbChuNhiem2.SelectedItem == null)
     {
         MessageBox.Show("Ma De Tai , Cap De Tai , Chu Nhiem la bat buoc");
         return;
     }
     else
     {
         DeTai deTai = new DeTai();
         deTai.MaDeTai  = txtMa2.Text.Trim();//bo khoang trang truoc ,sau MaDeTai
         deTai.TenDeTai = txtTen2.Text.Trim();
         if (rdHThanh2.Checked)
         {
             deTai.TinhTrang = true;
         }
         else
         {
             deTai.TinhTrang = false;
         }
         deTai.TenCapDeTai   = cbbCapDeTai2.SelectedItem.ToString();
         deTai.NgayNhanDeTai = Convert.ToDateTime(dpkNgayNhan2.Value);
         deTai.ChuNhiem      = cbbChuNhiem2.SelectedItem.ToString();
         sd(deTai);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: HuyLuuVan/CSharp-Winform
        //sau khi lay duoc du lieu tu formAdd -- > Add De Tai
        public void getAddInfo(DeTai dt)
        {
            SqlConnection cnn = DBConnect.openConnection();

            cnn.Open();
            //Test De Tai Trung Nhau
            string     quTrung  = "select count(*) from DeTai " + "where MaDeTai =N'" + dt.MaDeTai + "' ";
            SqlCommand cmdTrung = new SqlCommand(quTrung, cnn);

            if ((int)cmdTrung.ExecuteScalar() > 0)
            {
                MessageBox.Show("De Tai da ton tai");
                cnn.Close();
            }
            else
            {
                string quInsert = "DECLARE @MaCDT nchar(10)" +
                                  " Select @MaCDT = MaCapDeTai From CapDeTai where TenCapDeTai = N'" + dt.TenCapDeTai + "'" +
                                  " INSERT INTO DeTai(MaDeTai, TenDeTai, TinhTrang, MaCapDeTai, NgayNhanDeTai, ChuNhiem) VALUES(N'" + dt.MaDeTai + "', N'" +
                                  dt.TenDeTai + "','" + dt.TinhTrang + "'," + "@MaCDT" + ",'" + String.Format("{0:yyyy-MM-d }", dt.NgayNhanDeTai) + "', N'" + dt.ChuNhiem + "')";
                SqlCommand cmd = new SqlCommand(quInsert, cnn);// chu y gap loi string dai qua 10 ki tu
                cmd.ExecuteNonQuery();
                showDataTableOnGrid();
                cnn.Close();
            }
        }