private void deleteObj(String _type)
 {
     try
     {
         switch (_type)
         {
             case "CoSo":
                 if (XtraMessageBox.Show("Bạn có chắc là muốn xóa cơ sở?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                 {
                     int ree = objCoSo.delete();
                     if (ree > 0 && DBInstance.commit() > 0)
                     {
                         XtraMessageBox.Show("Xóa cơ sở thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         loadData();
                     }
                     else if(ree == -2)
                     {
                         XtraMessageBox.Show("Có phòng trong cơ sở. Vui lòng xóa phòng trước!");
                     }
                     else if (ree == -3)
                     {
                         XtraMessageBox.Show("Có dãy trong cơ sở. Vui lòng xóa dãy trước!");
                     }
                 }
                 break;
             case "Dayy":
                 if (XtraMessageBox.Show("Bạn có chắc là muốn xóa dãy?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                 {
                     objCoSo = objDay.coso;
                     int ree = objDay.delete();
                     if (ree > 0 && DBInstance.commit() > 0)
                     {
                         XtraMessageBox.Show("Xóa dãy thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         reLoadAndSelectNode(objCoSo.id, true);
                     }
                     else if(ree == -2)
                     {
                         XtraMessageBox.Show("Có phòng trong dãy. Vui lòng xóa phòng trước!");
                     }
                     else if (ree == -3)
                     {
                         XtraMessageBox.Show("Có tầng trong dãy. Vui lòng xóa tầng trước!");
                     }
                 }
                 break;
             case "Tang":
                 if (XtraMessageBox.Show("Bạn có chắc là muốn xóa tầng?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                 {
                     objDay = objTang.day;
                     if (objTang.delete() > 0 && DBInstance.commit() > 0)
                     {
                         XtraMessageBox.Show("Xóa tầng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         reLoadAndSelectNode(objDay.id, true);
                     }
                     else
                     {
                         XtraMessageBox.Show("Có phòng trong tầng. Vui lòng xóa phòng trước!");
                     }
                 }
                 break;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->deleteObj: " + ex.Message);
     }
 }
 public void LoadData()
 {
     listViTriHienThi = ViTriHienThi.getAll();
     if (listViTriHienThi.Count > 0)
     {
         ucTreeViTri.CreateTreeList();
         ucTreeViTri.ASPxTreeList_ViTri.DataSource = listViTriHienThi;
         ucTreeViTri.ASPxTreeList_ViTri.DataBind();
         SearchFunction();
         treevitri.Visible = true;
         if (Request.QueryString["key"] != null)
         {
             string key = "";
             try
             {
                 key = Request.QueryString["key"].ToString();
             }
             catch
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             DevExpress.Web.ASPxTreeList.TreeListNode node = ucTreeViTri.ASPxTreeList_ViTri.FindNodeByKeyValue(key);
             if (node != null)
             {
                 node.Focus();
                 ucTreeViTri.FocusAndExpandToNode(node);
                 Guid id = GUID.From(node.GetValue("id"));
                 string type = node.GetValue("loai").ToString();
                 if (type.Equals(typeof(CoSo).Name))
                 {
                     objCoSo = CoSo.getById(id);
                     if (objCoSo != null)
                     {
                         info.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objCoSo.ten;
                         Label_Ten.Text = objCoSo.ten;
                         ucViTri_BreadCrumb.Label_TenViTri.Text = Label_Ten.Text = objCoSo.ten;
                         Label_Thuoc.Text = "[Đại học Sài Gòn]";
                         Label_MoTa.Text = StringHelper.ConvertRNToBR(objCoSo.mota);
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else if (type.Equals(typeof(Dayy).Name))
                 {
                     objDay = Dayy.getById(id);
                     if (objDay != null)
                     {
                         info.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objDay.ten;
                         Label_Ten.Text = objDay.ten;
                         Label_Thuoc.Text = objDay.coso != null ? objDay.coso.ten : "[Cơ sở]";
                         ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                         Label_MoTa.Text = StringHelper.ConvertRNToBR(objDay.mota);
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else if (type.Equals(typeof(Tang).Name))
                 {
                     objTang = Tang.getById(id);
                     if (objTang != null)
                     {
                         info.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objTang.ten;
                         Label_Ten.Text = objTang.ten;
                         if (objTang.day != null)
                         {
                             if (objTang.day.coso != null)
                             {
                                 Label_Thuoc.Text = objTang.day.coso.ten + " - " + objTang.day.ten;
                             }
                             else
                             {
                                 Label_Thuoc.Text = "[Cơ sở] - " + objTang.day.ten;
                             }
                         }
                         else
                         {
                             Label_Thuoc.Text = "[Cơ sở] - [Dãy]";
                         }
                         ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                         Label_MoTa.Text = StringHelper.ConvertRNToBR(objTang.mota);
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else
                 {
                     Response.Redirect(Request.Url.AbsolutePath);
                 }
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
         }
         else
         {
             DevExpress.Web.ASPxTreeList.TreeListNode node = ucTreeViTri.ASPxTreeList_ViTri.FindNodeByKeyValue("");
             node.Focus();
         }
     }
     else
     {
         thongbaoloi.Visible = true;
         ucDanger.LabelInfo.Text = "Chưa có vị trí";
     }
 }
 private void setDataView()
 {
     try
     {
         dxErrorProvider1.ClearErrors();
         if (listViTriHienThi.Count > 0)
         {
             if (treeListViTri.FocusedNode != null && treeListViTri.FocusedNode.GetValue(colloai) != null && !GUID.From(treeListViTri.FocusedNode.GetValue(colid)).Equals(Guid.Empty))
             {
                 if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(CoSo).Name))
                 {
                     editGUI("view", typeof(CoSo).Name);
                     objCoSo = CoSo.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objCoSo.ten;
                     txtDiaChi.Text = objCoSo.diachi;
                     txtMoTa.Text = objCoSo.mota;
                     node = typeof(CoSo).Name;
                     listHinh = objCoSo.hinhanhs.ToList();
                     reloadImage();
                     editGUI2("view", typeof(CoSo).Name);
                 }
                 else if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(Dayy).Name))
                 {
                     editGUI("view", typeof(Dayy).Name);
                     objDay = Dayy.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objDay.ten;
                     txtMoTa.Text = objDay.mota;
                     node = typeof(Dayy).Name;
                     listHinh = objDay.hinhanhs.ToList();
                     ViTri objViTri = new ViTri();
                     objViTri.coso = objDay.coso;
                     _ucComboBoxViTri.ViTri = objViTri;
                     reloadImage();
                     editGUI2("view", typeof(Dayy).Name);
                 }
                 else if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(Tang).Name))
                 {
                     editGUI("view", typeof(Tang).Name);
                     objTang = Tang.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objTang.ten;
                     txtMoTa.Text = objTang.mota;
                     node = typeof(Tang).Name;
                     listHinh = objTang.hinhanhs.ToList();
                     ViTri objViTri = new ViTri();
                     objViTri.coso = objTang.day.coso;
                     objViTri.day = objTang.day;
                     _ucComboBoxViTriChonDay.ViTri = objViTri;
                     reloadImage();
                     editGUI2("view", typeof(Tang).Name);
                 }
             }
             else
             {
                 editGUI("nothing","");
                 editGUI2("nothing", "");
             }
         }
         else
         {
             editGUI("nothing", "");
             editGUI2("nothing", "");
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setDataView: " + ex.Message);
     }
 }
 private void addObj(String _type)
 {
     try
     {
         switch (_type)
         {
             case "CoSo":
                 CoSo objCoSoNew = new CoSo();
                 objCoSoNew.ten = txtTen.Text;
                 objCoSoNew.mota = txtMoTa.Text;
                 objCoSo.diachi = txtDiaChi.Text;
                 objCoSoNew.hinhanhs = listHinh;
                 if (objCoSoNew.add() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Thêm cơ sở thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     reLoadAndSelectNode(objCoSoNew.id);
                 }
                 else
                 {
                     XtraMessageBox.Show("Thêm cơ sở không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 break;
             case "Dayy":
                 Dayy objDayNew = new Dayy();
                 objDayNew.ten = txtTen.Text;
                 objDayNew.mota = txtMoTa.Text;
                 objDayNew.hinhanhs = listHinh;
                 ViTri _vitri = _ucComboBoxViTri.ViTri;
                 objDayNew.coso = _vitri.coso;
                 if (objDayNew.add() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Thêm dãy thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     reLoadAndSelectNode(objDayNew.id);
                 }
                 else
                 {
                     XtraMessageBox.Show("Thêm dãy không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 break;
             case "Tang":
                 Tang objTangNew = new Tang();
                 objTangNew.ten = txtTen.Text;
                 objTangNew.mota = txtMoTa.Text;
                 objTangNew.hinhanhs = listHinh;
                 ViTri _vitri2 = _ucComboBoxViTriChonDay.ViTri;
                 objTangNew.day = _vitri2.day;
                 if (objTangNew.add() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Thêm tầng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     reLoadAndSelectNode(objTangNew.id);
                 }
                 else
                 {
                     XtraMessageBox.Show("Thêm tầng không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 break;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->addObj: " + ex.Message);
     }
 }
        public static bool ImportPhong(String fileName, String sheet)
        {
            try
            {
                int line = 0;
                System.Data.DataTable dt = new System.Data.DataTable();
                const int STT = 0;
                const int MAPHONG = 1;
                const int TENPHONG = 2;
                const int LOAIPHONG = 3;
                //const int SOCHONGOI = 4;
                const int MOTA = 5;
                const int COSO = 6;
                const int DAY = 7;
                const int TANG = 8;
                const int PASS = 9;
                dt = OpenFile(fileName, sheet);
                if (dt != null)
                {
                    int lines = dt.Rows.Count;
                    foreach (System.Data.DataRow row in dt.Rows)
                    {
                        line++;
                        DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import Phòng... " +
                            String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0}", (line * 1.0 / lines) * 100) + "%");
                        bool ok = false;
                        if (!row[PASS].Equals("Pass"))
                        {
                            if (row[TENPHONG] != DBNull.Value)
                            {
                                if (Phong.getAll().FirstOrDefault(c => c.ten.ToUpper() == row[TENPHONG].ToString().Trim().ToUpper()) == null)
                                {
                                    try
                                    {
                                        ViTri objViTri = new ViTri();
                                        CoSo objCoSo = new CoSo();
                                        Dayy objDay = new Dayy();
                                        Tang objTang = new Tang();
                                        LoaiPhong objLoai = new LoaiPhong();
                                        if (row[COSO] != DBNull.Value)
                                        {
                                            objCoSo = CoSo.getAll().Where(c => c.ten.ToUpper().Equals(row[COSO].ToString().Trim().ToUpper())).FirstOrDefault();
                                            if (objCoSo != null && objCoSo.id != Guid.Empty)
                                            {
                                                if (row[DAY] != DBNull.Value && objCoSo.days.Count > 0)
                                                {
                                                    objDay = objCoSo.days.Where(c => c.ten.ToUpper().Equals(row[DAY].ToString().Trim().ToUpper())).FirstOrDefault();
                                                    if (objDay != null && objDay.id != Guid.Empty)
                                                    {
                                                        if (row[TANG] != DBNull.Value && objDay.tangs.Count > 0)
                                                        {
                                                            objTang = objDay.tangs.Where(c => c.ten.ToUpper().Equals(row[TANG].ToString().Trim().ToUpper())).FirstOrDefault();
                                                            if (objTang != null && objTang.id != Guid.Empty)
                                                            {
                                                                objViTri.coso = objCoSo;
                                                                objViTri.day = objDay;
                                                                objViTri.tang = objTang;
                                                                ok = true;
                                                            }
                                                            else
                                                            {
                                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tầng)");
                                                            }
                                                        }
                                                        else if (row[TANG] == DBNull.Value)
                                                        {
                                                            objViTri.coso = objCoSo;
                                                            objViTri.day = objDay;
                                                            objViTri.tang = null;
                                                            ok = true;
                                                        }
                                                        else
                                                        {
                                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tầng)");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có dãy)");
                                                    }
                                                }
                                                else if (row[DAY] == DBNull.Value)
                                                {
                                                    objViTri.coso = objCoSo;
                                                    objViTri.day = null;
                                                    objViTri.tang = null;
                                                    ok = true;
                                                }
                                                else
                                                {
                                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có dãy)");
                                                }
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có cơ sở)");
                                            }
                                        }

                                        if (row[LOAIPHONG] != DBNull.Value)
                                        {
                                            objLoai = LoaiPhong.getAll().Where(c => c.ten.ToUpper().Equals(row[LOAIPHONG].ToString().Trim().ToUpper())).FirstOrDefault();
                                            if (objLoai == null || objLoai.id == Guid.Empty)
                                            {
                                                objLoai = new LoaiPhong();
                                                objLoai.ten = row[LOAIPHONG].ToString().Trim();
                                                objLoai.mota = row[LOAIPHONG].ToString().Trim();
                                                //ok = false;
                                                //WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có loại phòng)");
                                            }
                                        }
                                        else
                                        {
                                            ok = false;
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có loại phòng)");
                                        }

                                        if (ok)
                                        {
                                            Phong obj = new Phong();
                                            obj.subId = row[MAPHONG] != DBNull.Value ? row[MAPHONG].ToString().Trim() : null;
                                            obj.vitri = objViTri;
                                            obj.ten = row[TENPHONG].ToString().Trim();
                                            //obj.sochongoi = row[SOCHONGOI] != DBNull.Value ? Convert.ToInt32(row[SOCHONGOI].ToString()) : 0;
                                            obj.mota = row[MOTA].ToString().Trim();
                                            obj.loaiphong = objLoai;
                                            if (obj.add() > 0 && DBInstance.commit() > 0)
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("ExcelDataBaseHelper->ImportPhong: " + ex.Message);
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                    }
                                }
                                else
                                {
                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                }
                            }
                            else
                            {
                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)");
                            }
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->ImportPhong: " + ex.Message);
                return false;
            }
        }
 public void LoadData()
 {
     listViTriHienThi = ViTriHienThi.getAll();
     if (listViTriHienThi.Count > 0)
     {
         _ucTreeViTri.CreateTreeList();
             _ucTreeViTri.ASPxTreeList_ViTri.DataSource = listViTriHienThi;
         _ucTreeViTri.ASPxTreeList_ViTri.DataBind();
         SearchFunction();
         if (Request.QueryString["key"] != null)
         {
             string key = "";
             try
             {
                 key = Request.QueryString["key"].ToString();
             }
             catch
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             DevExpress.Web.ASPxTreeList.TreeListNode node = _ucTreeViTri.ASPxTreeList_ViTri.FindNodeByKeyValue(key);
             if (node != null)
             {
                 Guid id = GUID.From(node.GetValue("id"));
                 string type = node.GetValue("loai").ToString();
                 if (type.Equals(typeof(CoSo).Name))
                 {
                     objCoSo = CoSo.getById(id);
                     if (objCoSo != null)
                     {
                         Panel_ThongTinObj.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objCoSo.ten;
                         Libraries.ImageHelper.LoadImageWeb(objCoSo.hinhanhs.ToList(), _ucASPxImageSlider_Mobile.ASPxImageSlider_Object);
                         Label_Ten.Text = objCoSo.ten;
                         ucViTri_BreadCrumb.Label_TenViTri.Text = Label_Ten.Text = objCoSo.ten;
                         Label_Thuoc.Text = "[Đại học Sài Gòn]";
                         Panel_DiaChi.Visible = true;
                         Label_DiaChi.Text = objCoSo.diachi;
                         Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objCoSo.mota);
                         if (objCoSo.diachi != null)
                         {
                             if (objCoSo.diachi.Length > 0)
                             {
                                 Button_Map.Visible = true;
                             }
                             else
                                 Button_Map.Visible = false;
                         }
                         else
                             Button_Map.Visible = false;
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else if (type.Equals(typeof(Dayy).Name))
                 {
                     objDay = Dayy.getById(id);
                     if (objDay != null)
                     {
                         Panel_ThongTinObj.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objDay.ten;
                         Libraries.ImageHelper.LoadImageWeb(objDay.hinhanhs.ToList(), _ucASPxImageSlider_Mobile.ASPxImageSlider_Object);
                         Label_Ten.Text = objDay.ten;
                         Label_Thuoc.Text = objDay.coso != null ? objDay.coso.ten : "[Cơ sở]";
                         ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                         Panel_DiaChi.Visible = false;
                         Label_DiaChi.Text = "";
                         Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objDay.mota);
                         Button_Map.Visible = false;
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else if (type.Equals(typeof(Tang).Name))
                 {
                     objTang = Tang.getById(id);
                     if (objTang != null)
                     {
                         Panel_ThongTinObj.Visible = true;
                         Label_ThongTin.Text = "Thông tin " + objTang.ten;
                         Libraries.ImageHelper.LoadImageWeb(objTang.hinhanhs.ToList(), _ucASPxImageSlider_Mobile.ASPxImageSlider_Object);
                         Label_Ten.Text = objTang.ten;
                         if (objTang.day != null)
                         {
                             if (objTang.day.coso != null)
                             {
                                 Label_Thuoc.Text = objTang.day.coso.ten + " - " + objTang.day.ten;
                             }
                             else
                             {
                                 Label_Thuoc.Text = "[Cơ sở] - " + objTang.day.ten;
                             }
                         }
                         else
                         {
                             Label_Thuoc.Text = "[Cơ sở] - [Dãy]";
                         }
                         ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                         Panel_DiaChi.Visible = false;
                         Label_DiaChi.Text = "";
                         Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objTang.mota);
                         Button_Map.Visible = false;
                     }
                     else
                     {
                         Response.Redirect(Request.Url.AbsolutePath);
                     }
                 }
                 else
                 {
                     Response.Redirect(Request.Url.AbsolutePath);
                 }
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
         }
         else
         {
             Panel_TreeViTri.Visible = true;
         }
     }
     else
     {
         ucThongBaoLoi.Panel_ThongBaoLoi.Visible = true;
         ucThongBaoLoi.Label_ThongBaoLoi.Text = "Chưa có vị trí";
     }
 }
        public static bool ImportViTri(String fileName, String sheet)
        {
            try
            {
                int line = 0;
                System.Data.DataTable dt = new System.Data.DataTable();
                const int STT = 0;
                const int MACOSO = 1;
                const int COSO = 2;
                const int MADAY = 3;
                const int DAY = 4;
                const int MATANG = 5;
                const int TANG = 6;
                const int MOTA = 7;
                const int PASS = 8;
                dt = OpenFile(fileName, sheet);
                if (dt != null)
                {
                    int lines = dt.Rows.Count;
                    foreach (System.Data.DataRow row in dt.Rows)
                    {
                        try
                        {
                            line++;
                            DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import Vị trí... " +
                                String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0}", (line * 1.0 / lines) * 100) + "%");
                            if (row[COSO] != DBNull.Value && !row[PASS].Equals("Pass"))
                            {
                                if (row[COSO] != DBNull.Value && row[DAY] != DBNull.Value && row[TANG] != DBNull.Value)
                                {
                                    CoSo objCoSo = CoSo.getAll().FirstOrDefault(c => c.ten.ToUpper().Equals(row[COSO].ToString().Trim().ToUpper()));
                                    if (objCoSo != null)
                                    {
                                        Dayy objDay = objCoSo.days.FirstOrDefault(c => c.ten.ToUpper().Equals(row[DAY].ToString().Trim().ToUpper()));
                                        if (objDay != null)
                                        {
                                            if (objDay.tangs.FirstOrDefault(c => c.ten.ToUpper().Equals(row[TANG].ToString().Trim().ToUpper())) == null)
                                            {
                                                Tang obj = new Tang();
                                                obj.subId = row[MATANG] != DBNull.Value ? row[MATANG].ToString().Trim() : null;
                                                obj.ten = row[TANG].ToString().Trim();
                                                obj.mota = row[MOTA].ToString().Trim();
                                                obj.day = objDay;
                                                if (obj.add() > 0 && DBInstance.commit() > 0)
                                                {
                                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                                }
                                                else
                                                {
                                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                                }
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                            }
                                        }
                                        else
                                        {
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có dãy)");
                                        }
                                    }
                                    else
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có cơ sở)");
                                    }

                                }
                                else if (row[COSO] != DBNull.Value && row[DAY] != DBNull.Value && row[TANG] == DBNull.Value)
                                {
                                    CoSo objCoSo = CoSo.getAll().FirstOrDefault(c => c.ten.ToUpper().Equals(row[COSO].ToString().Trim().ToUpper()));
                                    if (objCoSo != null)
                                    {
                                        if (objCoSo.days.FirstOrDefault(c => c.ten.ToUpper().Equals(row[DAY].ToString().Trim().ToUpper())) == null)
                                        {
                                            Dayy obj = new Dayy();
                                            obj.subId = row[MADAY] != DBNull.Value ? row[MADAY].ToString().Trim() : null;
                                            obj.ten = row[DAY].ToString().Trim();
                                            obj.mota = row[MOTA].ToString().Trim();
                                            obj.coso = objCoSo;
                                            if (obj.add() > 0 && DBInstance.commit() > 0)
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                            }
                                        }
                                        else
                                        {
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                        }
                                    }
                                    else
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có cơ sở)");
                                    }

                                }
                                else if (row[COSO] != DBNull.Value && row[DAY] == DBNull.Value && row[TANG] == DBNull.Value)
                                {
                                    if (CoSo.getAll().FirstOrDefault(c => c.ten.ToUpper().Equals(row[COSO].ToString().Trim().ToUpper())) == null)
                                    {
                                        CoSo obj = new CoSo();
                                        obj.subId = row[MACOSO] != DBNull.Value ? row[MACOSO].ToString().Trim() : null;
                                        obj.ten = row[COSO].ToString().Trim();
                                        obj.mota = row[MOTA].ToString().Trim();
                                        if (obj.add() > 0 && DBInstance.commit() > 0)
                                        {
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                        }
                                        else
                                        {
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                        }
                                    }
                                    else
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                    }
                                }
                                else
                                {
                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("ExcelDataBaseHelper->ImportViTri: " + ex.Message);
                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->ImportViTri: " + ex.Message);
                return false;
            }
        }
 private void LoadDataObj(Guid id, int type)
 {
     switch (type)
     {
         case 1:
             objCoSo = CoSo.getById(id);
             if (objCoSo != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objCoSo.ten);
                 Libraries.ImageHelper.LoadImageWeb(objCoSo.hinhanhs.ToList(), _ucASPxImageSlider_Web.ASPxImageSlider_Object);
                 _ucASPxImageSlider_Web.urlHinhAnh = string.Format("http://{0}/HinhAnh.aspx?id={1}&type=COSO", HttpContext.Current.Request.Url.Authority, objCoSo.id);
                 ucViTri_BreadCrumb.Label_TenViTri.Text = Label_Ten.Text = objCoSo.ten;
                 Label_Thuoc.Text = "[Đại học Sài Gòn]";
                 Panel_DiaChi.Visible = true;
                 Label_DiaChi.Text = objCoSo.diachi;
                 Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objCoSo.mota);
                 if (objCoSo.diachi != null)
                 {
                     if (objCoSo.diachi.Length > 0)
                     {
                         strSrc = @"https://www.google.com/maps/embed/v1/place?key=AIzaSyB2ryXlc0dNmczXS7O6E5htyRpkR4zvmVo&q=" + objCoSo.diachi;
                         popup.HeaderText = string.Format("Bản đồ {0}", objCoSo.ten);
                         LinkButtonBanDo.Text = popup.HeaderText;
                         LinkButtonBanDo.OnClientClick = string.Format("_ShowMaps('{0}'); return false;", strSrc);
                     }
                 }
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         case 2:
             objDay = Dayy.getById(id);
             if (objDay != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objDay.ten);
                 Libraries.ImageHelper.LoadImageWeb(objDay.hinhanhs.ToList(), _ucASPxImageSlider_Web.ASPxImageSlider_Object);
                 _ucASPxImageSlider_Web.urlHinhAnh = string.Format("http://{0}/HinhAnh.aspx?id={1}&type=DAY", HttpContext.Current.Request.Url.Authority, objDay.id);
                 Label_Ten.Text = objDay.ten;
                 Label_Thuoc.Text = objDay.coso != null ? objDay.coso.ten : "[Cơ sở]";
                 ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                 Panel_DiaChi.Visible = false;
                 Label_DiaChi.Text = "";
                 Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objDay.mota);
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         case 3:
             objTang = Tang.getById(id);
             if (objTang != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objTang.ten);
                 Libraries.ImageHelper.LoadImageWeb(objTang.hinhanhs.ToList(), _ucASPxImageSlider_Web.ASPxImageSlider_Object);
                 _ucASPxImageSlider_Web.urlHinhAnh = string.Format("http://{0}/HinhAnh.aspx?id={1}&type=TANG", HttpContext.Current.Request.Url.Authority, objTang.id);
                 Label_Ten.Text = objTang.ten;
                 if (objTang.day != null)
                 {
                     if (objTang.day.coso != null)
                     {
                         Label_Thuoc.Text = objTang.day.coso.ten + " - " + objTang.day.ten;
                     }
                     else
                     {
                         Label_Thuoc.Text = "[Cơ sở] - " + objTang.day.ten;
                     }
                 }
                 else
                 {
                     Label_Thuoc.Text = "[Cơ sở] - [Dãy]";
                 }
                 ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                 Panel_DiaChi.Visible = false;
                 Label_DiaChi.Text = "";
                 Label_MoTa.Text = Libraries.StringHelper.ConvertRNToBR(objTang.mota);
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         default:
             Response.Redirect(Request.Url.AbsolutePath);
             return;
     }
 }
        public static bool ImportPhong(String fileName, String sheet)
        {
            try
            {
                int line = 0;
                System.Data.DataTable dt = new System.Data.DataTable();
                const int STT = 0;
                const int MAPHONG = 1;
                const int TENPHONG = 2;
                const int MOTA = 3;
                const int COSO = 4;
                const int DAY = 5;
                const int TANG = 6;
                const int NHANVIENPT = 7;
                const int MANHANVIEN = 8;
                const int NGAYTAO = 9;
                const int HINHANH = 10;
                const int PASS = 11;
                dt = OpenFile(fileName, sheet);
                if (dt != null)
                {
                    int lines = dt.Rows.Count;
                    foreach (System.Data.DataRow row in dt.Rows)
                    {
                        line++;
                        DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import Phòng... " +
                            String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0}", (line * 1.0 / lines) * 100) + "%");
                        bool ok = false;
                        if (!row[PASS].Equals("Pass"))
                        {
                            if (row[TENPHONG] != DBNull.Value)
                            {
                                if (Phong.getAll().FirstOrDefault(c => c.ten.ToUpper() == row[TENPHONG].ToString().Trim().ToUpper()) == null)
                                {
                                    try
                                    {
                                        ViTri objViTri = new ViTri();
                                        CoSo objCoSo = new CoSo();
                                        Dayy objDay = new Dayy();
                                        Tang objTang = new Tang();
                                        if(row[COSO] != DBNull.Value)
                                        {
                                            objCoSo = CoSo.getAll().Where(c => c.ten.ToUpper().Equals(row[COSO].ToString().Trim().ToUpper())).FirstOrDefault();
                                            if (objCoSo != null && objCoSo.id != Guid.Empty)
                                            {
                                                if (row[DAY] != DBNull.Value && objCoSo.days.Count > 0)
                                                {
                                                    objDay = objCoSo.days.Where(c => c.ten.ToUpper().Equals(row[DAY].ToString().Trim().ToUpper())).FirstOrDefault();
                                                    if (objDay != null && objDay.id != Guid.Empty)
                                                    {
                                                        if (row[TANG] != DBNull.Value && objDay.tangs.Count > 0)
                                                        {
                                                            objTang = objDay.tangs.Where(c => c.ten.ToUpper().Equals(row[TANG].ToString().Trim().ToUpper())).FirstOrDefault();
                                                            if (objTang != null && objTang.id != Guid.Empty)
                                                            {
                                                                objViTri.coso = objCoSo;
                                                                objViTri.day = objDay;
                                                                objViTri.tang = objTang;
                                                                ok = true;
                                                            }
                                                            else
                                                            {
                                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tầng)");
                                                            }
                                                        }
                                                        else if (row[TANG] == DBNull.Value)
                                                        {
                                                            objViTri.coso = objCoSo;
                                                            objViTri.day = objDay;
                                                            objViTri.tang = null;
                                                            ok = true;
                                                        }
                                                        else
                                                        {
                                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tầng)");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có dãy)");
                                                    }
                                                }
                                                else if (row[DAY] == DBNull.Value)
                                                {
                                                    objViTri.coso = objCoSo;
                                                    objViTri.day = null;
                                                    objViTri.tang = null;
                                                    ok = true;
                                                }
                                                else
                                                {
                                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có dãy)");
                                                }
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có cơ sở)");
                                            }
                                        }

                                        if (ok)
                                        {
                                            Phong obj = new Phong();
                                            obj.subId = row[MAPHONG] != DBNull.Value ? row[MAPHONG].ToString().Trim() : null;
                                            obj.vitri = objViTri;
                                            obj.ten = row[TENPHONG].ToString().Trim();
                                            obj.date_create = row[NGAYTAO] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAYTAO]) : DateTime.Now;
                                            obj.mota = row[MOTA].ToString().Trim();
                                            if (row[HINHANH] != DBNull.Value)
                                            {
                                                String[] file_names = row[HINHANH].ToString().Trim().Split(',');
                                                obj.hinhanhs = AddImage(fileName, file_names);
                                            }

                                            if(row[NHANVIENPT] != DBNull.Value)
                                            {
                                                if (NhanVienPT.getAll().Where(c => c.hoten.ToUpper() == row[NHANVIENPT].ToString().Trim().ToUpper()).Count() == 1)
                                                {
                                                    obj.nhanvienpt = NhanVienPT.getAll().FirstOrDefault(c => c.hoten.ToUpper() == row[NHANVIENPT].ToString().Trim().ToUpper());
                                                }
                                                else if (NhanVienPT.getAll().Where(c => c.hoten.ToUpper() == row[NHANVIENPT].ToString().Trim().ToUpper()).Count() > 1)
                                                {
                                                    if (row[MANHANVIEN] != DBNull.Value)
                                                    {
                                                        if (NhanVienPT.getAll().Where(c => c.hoten.ToUpper() == row[NHANVIENPT].ToString().Trim().ToUpper() && c.subId.ToUpper() == row[MANHANVIEN].ToString().Trim().ToUpper()).Count() == 1)
                                                        {
                                                            obj.nhanvienpt = NhanVienPT.getAll().FirstOrDefault(c => c.hoten.ToUpper() == row[NHANVIENPT].ToString().Trim().ToUpper() && c.subId.ToUpper() == row[MANHANVIEN].ToString().Trim().ToUpper());
                                                        }
                                                        else
                                                        {
                                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass - Error (Mã nhân viên không đúng)");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass - Error (Nhân viên trùng tên nhưng không có mã)");
                                                    }
                                                }
                                            }

                                            if (obj.add() > 0 && DBInstance.commit() > 0)
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                            }
                                        }
                                        else
                                        {
                                            //WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Vị trí lỗi)");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("ExcelDataBaseHelper->ImportPhong: " + ex.Message);
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                    }
                                }
                                else
                                {
                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                }
                            }
                            else
                            {
                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)");
                            }
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->ImportPhong: " + ex.Message);
                return false;
            }
        }
 private void setDataView()
 {
     try
     {
         dxErrorProviderInfo.ClearErrors();
         if (listViTriHienThi.Count > 0)
         {
             if (treeListViTri.FocusedNode != null && treeListViTri.FocusedNode.GetValue(colloai) != null && !GUID.From(treeListViTri.FocusedNode.GetValue(colid)).Equals(Guid.Empty))
             {
                 if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(CoSo).Name))
                 {
                     editGUI("view", typeof(CoSo).Name);
                     objCoSo = CoSo.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objCoSo.ten;
                     txtMoTa.Text = objCoSo.mota;
                     node = typeof(CoSo).Name;
                 }
                 else if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(Dayy).Name))
                 {
                     editGUI("view", typeof(Dayy).Name);
                     objDay = Dayy.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objDay.ten;
                     txtMoTa.Text = objDay.mota;
                     node = typeof(Dayy).Name;
                     _ucComboBoxCoSo.ViTri = ViTri.request(objDay.coso, null, null);
                 }
                 else if (treeListViTri.FocusedNode.GetValue(colloai).ToString().Equals(typeof(Tang).Name))
                 {
                     editGUI("view", typeof(Tang).Name);
                     objTang = Tang.getById(GUID.From(treeListViTri.FocusedNode.GetValue(colid)));
                     txtTen.Text = objTang.ten;
                     txtMoTa.Text = objTang.mota;
                     node = typeof(Tang).Name;
                     _ucComboBoxDay.ViTri = ViTri.request(null, objTang.day, null);
                 }
             }
             else
             {
                 editGUI("nothing", "");
             }
         }
         else
         {
             editGUI("nothing", "");
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setDataView: " + ex.Message);
     }
 }
 private void LoadDataObj(Guid id, int type)
 {
     switch (type)
     {
         case 1:
             objCoSo = CoSo.getById(id);
             if (objCoSo != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objCoSo.ten);
                 ucViTri_BreadCrumb.Label_TenViTri.Text = Label_Ten.Text = objCoSo.ten;
                 Label_Thuoc.Text = "[Đại học Sài Gòn]";
                 Label_MoTa.Text = StringHelper.ConvertRNToBR(objCoSo.mota);
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         case 2:
             objDay = Dayy.getById(id);
             if (objDay != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objDay.ten);
                 Label_Ten.Text = objDay.ten;
                 Label_Thuoc.Text = objDay.coso != null ? objDay.coso.ten : "[Cơ sở]";
                 ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                 Label_MoTa.Text = StringHelper.ConvertRNToBR(objDay.mota);
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         case 3:
             objTang = Tang.getById(id);
             if (objTang != null)
             {
                 Label_ThongTin.Text = string.Format("Thông tin {0}", objTang.ten);
                 Label_Ten.Text = objTang.ten;
                 if (objTang.day != null)
                 {
                     if (objTang.day.coso != null)
                     {
                         Label_Thuoc.Text = objTang.day.coso.ten + " - " + objTang.day.ten;
                     }
                     else
                     {
                         Label_Thuoc.Text = "[Cơ sở] - " + objTang.day.ten;
                     }
                 }
                 else
                 {
                     Label_Thuoc.Text = "[Cơ sở] - [Dãy]";
                 }
                 ucViTri_BreadCrumb.Label_TenViTri.Text = string.Format("{0} ({1})", Label_Ten.Text, Label_Thuoc.Text);
                 Label_MoTa.Text = StringHelper.ConvertRNToBR(objTang.mota);
             }
             else
             {
                 Response.Redirect(Request.Url.AbsolutePath);
             }
             break;
         default:
             Response.Redirect(Request.Url.AbsolutePath);
             return;
     }
 }