コード例 #1
0
 /// <summary>
 /// Kiểm tra và thêm mới Chuyengia
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của Chuyengia Mới Thêm Vào</returns>
 public static Int32 Add(ChuyengiaEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return ChuyengiaDAL.Add(entity);
 }
コード例 #2
0
 /// <summary>
 /// Kiểm tra và chỉnh sửa Chuyengia
 /// </summary>
 /// <param name="entity">ChuyengiaEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(ChuyengiaEntity entity)
 {
     checkExist(entity.PK_iChuyengiaID);
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return ChuyengiaDAL.Edit(entity);
 }
コード例 #3
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //Page.Validate("vgChuyengia");
        //if (Page.IsValid)
        //{
            try
            {
                Int32 PK_iChuyengiaID;

                ChuyengiaEntity oChuyengia = new ChuyengiaEntity();
                oChuyengia.sHoten = txtHoten.Text;
                oChuyengia.FK_iTochucchungnhanID = int.Parse(ddlTochucchungnhan.SelectedValue);
                oChuyengia.iNamkinhnghiem = short.Parse(txtSonamkinhnghiem.Text);
                oChuyengia.sMaso = txtMaso.Text;
                oChuyengia.FK_iTrinhdoID = short.Parse(ddlTrinhdo.SelectedValue);
                oChuyengia.iNamsinh = Convert.ToInt16(txtNamsinh.Text);
                if (ddlDuyet.SelectedValue.Equals("1"))
                {
                    oChuyengia.bDuyet = true;
                }
                else
                {
                    oChuyengia.bDuyet = false;
                }
                byte[] bytImage = null;
                // xu ly anh
                if (fAnhthe.PostedFile != null)
                {
                    if (fAnhthe.PostedFile.ContentLength > 0)
                    {
                        string strEx = "jpg|jpeg|bmp|png|gif";
                        string fileEx = fAnhthe.FileName.Substring(fAnhthe.FileName.LastIndexOf('.')).Remove(0, 1);
                        string[] arrEx = strEx.Split('|');
                        bool valid = false;
                        foreach (string ex in arrEx)
                        {
                            if (ex.Equals(fileEx, StringComparison.OrdinalIgnoreCase))
                                valid = true;
                        }
                        if (valid)
                        {

                            HttpPostedFile objHttpPostedFile = fAnhthe.PostedFile;
                            int intContentlength = objHttpPostedFile.ContentLength;
                            bytImage = new Byte[intContentlength];
                            objHttpPostedFile.InputStream.Read(bytImage, 0, intContentlength);
                            oChuyengia.imAnh = bytImage;
                        }
                    }
                }
                else
                {

                }

                if (btnOK.CommandName.ToUpper() == "EDIT")
                {
                    PK_iChuyengiaID = Convert.ToInt32(btnOK.CommandArgument);
                    ChuyengiaEntity oChuyengiaOld = ChuyengiaBRL.GetOne(PK_iChuyengiaID);
                    oChuyengia.imAnh = oChuyengiaOld.imAnh;
                    oChuyengia.iTrangthai = oChuyengiaOld.iTrangthai;
                    oChuyengia.PK_iChuyengiaID = PK_iChuyengiaID;
                    luuChungchi(PK_iChuyengiaID);
                    ChuyengiaBRL.Edit(oChuyengia);
                    lblThongbao.Text = "Cập nhật thành công";
                }
                else if(btnOK.CommandName.ToUpper()=="ADDNEW")
                {

                    PK_iChuyengiaID = ChuyengiaBRL.Add(oChuyengia);

                    // Lưu chứng chỉ của chuyên gia
                    foreach (ListItem chk in cblGiaychungnhan.Items)
                    {
                        if (chk.Selected == true)
                        {
                            int PK_iChungchiID = Convert.ToInt32(chk.Value);
                            ChungchiChuyengiaEntity oChungchichuyengiaMoi = new ChungchiChuyengiaEntity();
                            oChungchichuyengiaMoi.FK_iChungchiID = int.Parse(chk.Value);
                            oChungchichuyengiaMoi.FK_iChuyengiaID = PK_iChuyengiaID;
                            ChungchiChuyengiaBRL.Add(oChungchichuyengiaMoi);
                        }
                    }
                    lblThongbao.Text = "Thêm thành công";
                }
                napGridView();
            }
            catch (Exception ex)
            {
                //lblThongbao.Text = ex.Message;
                Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=Chuyengia';</script>");
            }
            pnlEdit.Visible = false;
        //}
    }
コード例 #4
0
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">ChuyengiaEntity: entity</param>
 private static void checkLogic(ChuyengiaEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sHoten))
         throw new Exception(EX_SHOTEN_EMPTY);
     if (entity.FK_iTochucchungnhanID < 0)
         throw new Exception(EX_FK_ITOCHUCCHUNGNHANID_INVALID);
     if (entity.iNamkinhnghiem < 0)
         throw new Exception(EX_INAMKINHNGHIEM_INVALID);
     if (entity.iTrangthai < 0)
         throw new Exception(EX_ITRANGTHAI_INVALID);
     if (entity.imAnh==null)
         throw new Exception(EX_IMANH_INVALID);
     if (entity.FK_iTrinhdoID < 0)
         throw new Exception(EX_FK_ITRINHDOID_INVALID);
     if (entity.iNamsinh < 0)
         throw new Exception(EX_INAMSINH_INVALID);
 }
コード例 #5
0
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">ChuyengiaEntity:entity</param>
 private static void checkFK(ChuyengiaEntity entity)
 {
     TochucchungnhanEntity oTochucchungnhan = TochucchungnhanDAL.GetOne(entity.FK_iTochucchungnhanID);
     if (oTochucchungnhan==null)
     {
         throw new Exception("Không tìm thấy :FK_iTochucchungnhanID");
     }
     TrinhdoChuyengiaEntity oTrinhdoChuyengia = TrinhdoChuyengiaDAL.GetOne(entity.FK_iTrinhdoID);
     if (oTrinhdoChuyengia==null)
     {
         throw new Exception("Không tìm thấy :FK_iTrinhdoID");
     }
 }
コード例 #6
0
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">ChuyengiaEntity: ChuyengiaEntity</param>
 private static void checkDuplicate(ChuyengiaEntity entity,bool checkPK)
 {
     /*
     Example
     List<ChuyengiaEntity> list = ChuyengiaDAL.GetAll();
     if (list.Exists(
         delegate(ChuyengiaEntity oldEntity)
         {
             bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
             if(checkPK)
                 result=result && oldEntity.PK_iChuyengiaID != entity.PK_iChuyengiaID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_FIELD_EXISTED);
     }
     */
 }