Пример #1
0
        public ActionResult Edit(Catologie item,Guid r)
        {
            //chi cap nhat cac truong trong danh sach
            //UpdateModel(employee, new string[] { "ID", "Gender", "City", "DateOfBirth" });
            ViewBag.ItemGuid = r;
            item.KindCatologyGuid = r;
            //neu cac rang buoc ok
            if (ModelState.IsValid)
            {
                int max = itemBAL.GetMaxPositionByKindGuid(item.KindCatologyGuid);
              item.Position = ++max;
                //bo sung du lieu cho doi tuong item
              item.ListStringToSort = ConstantVariable.ToBinary(item.Position);
              item.IsActive = true;
              item.UserID= WebSecurity.CurrentUserId;

                //Save data
                item.CatologyGuid = itemBAL.Save(item);
                ViewBag.ItemGuid = item.CatologyGuid;
                if (item.CatologyGuid != Guid.Empty)
                {
                    return Content("<div class='alert alert-info'>Thao tác thành công!</div>", "text/html");
                }
                else
                    Content("<div class='alert alert-danger'>Thao tác thất bại!</div>", "text/html");
            }
            return View();
        }
Пример #2
0
 /// <summary>
 /// Inserts a row in the cont_Catologies table. Returns rows affected count.
 /// </summary>
 /// <returns>int</returns>
 public static int Create(Catologie item)
 {
     SqlParameterHelper sph = new SqlParameterHelper(ConnectionStringStatic.GetWriteConnectionString(), "cont_Catologies_ngocnv10052014_Insert", 10);
     sph.DefineSqlParameter("@CatologyGuid", SqlDbType.UniqueIdentifier, ParameterDirection.Input, item.CatologyGuid);
     sph.DefineSqlParameter("@CatologyName", SqlDbType.NVarChar, 256, ParameterDirection.Input, item.CatologyName);
     sph.DefineSqlParameter("@Description", SqlDbType.NVarChar, 500, ParameterDirection.Input, item.Description);
     sph.DefineSqlParameter("@KindCatologyGuid", SqlDbType.UniqueIdentifier, ParameterDirection.Input, item.KindCatologyGuid);
     sph.DefineSqlParameter("@KindCatologyName", SqlDbType.NVarChar, 256, ParameterDirection.Input, item.KindCatologyName);
     sph.DefineSqlParameter("@IsActive", SqlDbType.Bit, ParameterDirection.Input, item.IsActive);
     sph.DefineSqlParameter("@Position", SqlDbType.Int, ParameterDirection.Input, item.Position);
     sph.DefineSqlParameter("@ListStringToSort", SqlDbType.NVarChar, 256, ParameterDirection.Input, item.ListStringToSort);
     sph.DefineSqlParameter("@UserName", SqlDbType.NVarChar,256, ParameterDirection.Input, item.Massv);
     sph.DefineSqlParameter("@IsNotDelete", SqlDbType.Bit, ParameterDirection.Input, item.IsNotDelete);
     int rowsAffected = sph.ExecuteNonQuery();
     return rowsAffected;
 }
Пример #3
0
        void ImageButtonSave_Click(object sender, EventArgs e)
        {
            PopulateControls(Step.Step3);
            if (!IsError)
            {

            ICatologieBAL itemBAL = new CatologieBAL();

                using (DataSet ds = TempXMLHelper.ReadTemporayDataFromXml(Server.MapPath(ConfigurationManager.AppSettings["VALUE_PATH_XML_INFOTEACHING"] + "/" + SiteUtils.GetCurrentUserId().ToString() + ".xml")))
                {
                    if (ds.Tables.Count > 0)
                    {
                        DataTable dataTable = ds.Tables[0];
                        int count = 0;
                        //Save data
                        DateTime _dateUpdate = DateTime.Now;
                        int maxPosition = itemBAL.GetMaxPositionByKindGuid(ConstantVariable.Catologys_Root_Value);

                        foreach (DataRow row in dataTable.Rows)
                        {
                            try
                            {

                                //nếu có đã có tài khoản thì bỏ qua
                                Catologie sv = new Catologie();
                                sv.CatologyName = row["hovaten"].ToString();
                                sv.Khoa = row["khoa"].ToString();
                                sv.Lop = row["lop"].ToString();
                                sv.Massv = row["Massv"].ToString();

                                sv.Role = "SinhVien";
                                sv.PassWord = "******";
                                //WebSecurity.CreateUserAndAccount(sv.Massv, "123");
                                //Roles.AddUserToRole(sv.Massv, "SinhVien");
                                //int userID= WebSecurity.GetUserId(sv.Massv);
                               // Membership.GeneratePassword(
                                sv.KindCatologyGuid = ConstantVariable.Catologys_Root_Value;
                                sv.IsActive = true;
                                //sv.UserID = userID;
                                sv.Position = ++maxPosition;
                                sv.ListStringToSort = ConstantVariable.ToBinary(sv.Position);
                                Guid catGuid=Guid.Empty;
                                Guid catRootGuid = Guid.Empty;

                                catRootGuid = itemBAL.CreateImport(sv);//lưu gốc
                                if (catRootGuid != Guid.Empty)
                                {
                                    sv = new Catologie();
                                    sv.IsNotDelete = true;
                                    sv.Massv = row["Massv"].ToString();
                                    sv.CatologyName = "Danh mục chưa phân loại";
                                    sv.ListStringToSort = ConstantVariable.ToBinary(sv.Position);
                                    sv.KindCatologyGuid = catRootGuid;
                                    sv.IsActive = true;
                                    catGuid = itemBAL.Save(sv);//lưu thư mục mặc định

                                }

                                if (catGuid != Guid.Empty)
                                {
                                    count++;
                                    row["ErrorContent"] = "save successful!";
                                    row["IsDongLoi"] = false;

                                }
                                else
                                {
                                    row["ErrorContent"] = "không tạo được thư mục mặc định!";
                                    row["IsDongLoi"] = true;
                                    continue;
                                }
                            }
                            catch (Exception ex)
                            {
                                row["ErrorContent"] = ex;
                                row["IsDongLoi"] = true;
                            }
                        }

                        ErrorMessage(false, "Lưu thành công " + count.ToString() + " record!");
                        GridViewSaveOK.DataSource = dataTable;
                        GridViewSaveOK.DataBind();
                    }
                }
            }
        }
Пример #4
0
 //Kiểm tra trùng lắp dữ liệu
 private bool CheckItemCatologie(Catologie itemSP)
 {
     ICatologieBAL ItemBAL = new CatologieBAL();
     return ItemBAL.CheckExistUser(itemSP);
       //  return false;
 }
 private void OnSave_Event(Catologie parameterValue)
 {
     if (Save_Event != null)
         Save_Event(this, new OneParameterEventAgrs<Catologie>(parameterValue));
 }
        void ButtonSave_Click(object sender, EventArgs e)
        {
            Catologie item = new Catologie();

            //Truyen du lieu vao
            try
            {
                item.CatologyGuid = new Guid(LiteralCatologyGuid.Text);
            }
            catch (Exception)
            {
                item.CatologyGuid = Guid.Empty;
            }

            item.CatologyName = TextBoxCatologyName.Text.Trim();
            item.Description = TextBoxDescription.Text;
            item.KindCatologyGuid = new Guid(DropDownListCatologies.SelectedValue);
            item.KindCatologyName = DropDownListCatologies.SelectedItem.ToString();
            item.IsActive = CheckBoxIsActive.Checked;
            try
            {
                item.Position = Convert.ToInt16(TextBoxPosition.Text);
            }
            catch (Exception)
            {
                ErrorMessage = "Thứ tự hiển thị không được nhập chữ.";
            }

            //control hien thi trang chu
            //item.SaveSetting = false;
            //item.SaveSetting = true;
            //item.SettingGroup = "SHOW";//ten cua nhom setting
            //item.SettingValue = "";//guid cua item can luu setting

            //Check loi
            //Kiem tra  loi trung danh muc
            if (item.KindCatologyGuid == item.CatologyGuid)
            {
                ErrorMessage = "Vui lòng lựa chọn nhóm danh mục khác!";
                UpdatePanelPopupAddCatologie_on.Update();
                return;
            }

            //Kiem tra null ten danh muc
            if (item.CatologyName == string.Empty)
            {
                ErrorMessage = "Vui lòng nhận tên danh mục!";
                UpdatePanelPopupAddCatologie_on.Update();
                return;
            }

            OnSave_Event(item);
            UpdatePanelPopupAddCatologie_on.Update();
        }
        void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
        {
            // Uncomment to save to AsyncFileUpload\Uploads folder.
            // ASP.NET must have the necessary permissions to write to the file system.
            Catologie item = new Catologie();
            item.CatologyGuid = new Guid(LiteralCatologyGuid.Text);
            item.UrlHinhanh = AsyncFileUpload1.FileName;
            item.DataImage = AsyncFileUpload1.FileBytes;

            //co the xay ra loi cho nay
            OnSaveFile_Event(item);
        }
Пример #8
0
 //Kiểm tra trùng lắp dữ liệu
 private bool CheckItemCatologie(Catologie itemSP)
 {
     //kiểm tra tồn tại trong bảng user chưa
     ICatologieBAL ItemBAL = new CatologieBAL();
     return ItemBAL.CheckExistUser(itemSP);
     //return false;
 }
Пример #9
0
 private Guid Create(Catologie item)
 {
     item.CatologyGuid = Guid.NewGuid();
     int rowsAffected = CatologieDAL.Create(item);
     return rowsAffected > 0 ? item.CatologyGuid : Guid.Empty;
 }
Пример #10
0
        private Guid Update(Catologie item)
        {
            string query = string.Empty;
            //1 build query update of main item
            //2 build list query update of sub item
            //3 run sql query

            //--load data
            List<Catologie> listCatologies = new List<Catologie>();
            listCatologies = LoadListFromReader(CatologieDAL.GetAllCatologies(item.CatologyGuid, -1));

            if (listCatologies.Count < 1)
                return item.CatologyGuid;

            //--buid query
            query += @"SET XACT_ABORT ON
                     BEGIN TRANSACTION ";

            //lay then [0] lam truoc.
            //chay auto cac then con lai.
            query += @"UPDATE 		[dbo].[cont_Catologies]

                        SET
                                    [CatologyName] = N'" + item.CatologyName + @"',
                                    [Description] = N'" + item.Description + @"',
                                    [KindCatologyGuid] = '" + item.KindCatologyGuid + @"',
                                    [KindCatologyName] = N'" + item.KindCatologyName + @"',
                                    IsActive='" + item.IsActive + @"',
                                    ListStringToSort=(select ListStringToSort from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"') + '" + item.ListStringToSort + @"',
                                    ListPlacementGuid=(select ListPlacementGuid from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"') + ';' + convert(nvarchar(256),'" + item.KindCatologyGuid + @"'),
                                    ListPlacementName=(select ListPlacementName from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"') + '\' + (select CatologyName from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"'),
                                    Levels=(select Levels from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"') + 1,
                                    ListPlacementID=convert(nvarchar(18),(select ListPlacementID from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"')) + '\' + convert(nvarchar(18),(select CatologyID from cont_Catologies where CatologyGuid='" + item.KindCatologyGuid + @"')),
                                    Position=" + item.Position + @",
                                    UserID="+item.UserID+@",
                                    IsNotDelete='"+item.IsNotDelete+@"'

                        WHERE
                                    [CatologyGuid] = '" + listCatologies[0].CatologyGuid + @"'";
            //cap nhat du lieu item dau tien trong list
            //listCatologies[0].ListStringToSort

            //update cac subItem
            for (int i = 1; i < listCatologies.Count; i++)
            {
                query += @"
                        UPDATE 		[dbo].[cont_Catologies]
                        SET
                                    ListStringToSort=(select ListStringToSort from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"') + '" + ConstantVariable.ToBinary(listCatologies[i].Position) + @"',
                                    ListPlacementGuid=(select ListPlacementGuid from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"') + ';' + convert(nvarchar(256),'" + listCatologies[i].KindCatologyGuid + @"'),
                                    ListPlacementName=(select ListPlacementName from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"') + '\' + (select CatologyName from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"'),
                                    ListPlacementID=convert(nvarchar(18),(select ListPlacementID from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"')) + '\' + convert(nvarchar(18),(select CatologyID from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"')),
                                    Levels=(select Levels from cont_Catologies where CatologyGuid='" + listCatologies[i].KindCatologyGuid + @"') + 1
                        WHERE
                                    [CatologyGuid] = '" + listCatologies[i].CatologyGuid + @"'";
            }

            query += @" COMMIT TRANSACTION";

            return CatologieDAL.Update(query) ? item.CatologyGuid : Guid.Empty;
        }
Пример #11
0
 public Guid CreateImport(Catologie item)
 {
     item.CatologyGuid = Guid.NewGuid();
     int rowsAffected = CatologieDAL.CreateImport(item);
     return rowsAffected > 0 ? item.CatologyGuid : Guid.Empty;
 }
Пример #12
0
        private Catologie PopulateFromReader(IDataReader reader)
        {
            Catologie item = new Catologie();
            if (reader.Read())
            {

                item.CatologyGuid = new Guid(reader["CatologyGuid"].ToString());
                item.CatologyID = Convert.ToInt32(reader["CatologyID"]);
                item.CatologyName = reader["CatologyName"].ToString();
                item.Description = reader["Description"].ToString();
                item.KindCatologyGuid = new Guid(reader["KindCatologyGuid"].ToString());
                item.KindCatologyName = reader["KindCatologyName"].ToString();
                item.IsActive = Convert.ToBoolean(reader["IsActive"].ToString());
                item.UrlHinhanh = reader["UrlHinhanh"].ToString();

                item.ListPlacementName = reader["ListPlacementName"].ToString();
                item.Levels = Convert.ToInt32(reader["Levels"]);
                item.Position = Convert.ToInt32(reader["Position"]);
                try
                {
                    item.IsNotDelete = Convert.ToBoolean(reader["IsNotDelete"].ToString());
                }
                catch { }
                try
                {
                    item.UserID=Convert.ToInt32(reader["UserID"]);
                }
                catch { }
            }
            return item;
        }
Пример #13
0
 public bool CheckExistUser(Catologie itemSP)
 {
     return CatologieDAL.CheckExistUser(itemSP);
 }
Пример #14
0
        private List<Catologie> LoadListFromReader(IDataReader reader)
        {
            List<Catologie> items = new List<Catologie>();
            try
            {
                while (reader.Read())
                {
                    Catologie item = new Catologie();
                    item.CatologyGuid = new Guid(reader["CatologyGuid"].ToString());
                    item.CatologyID = Convert.ToInt32(reader["CatologyID"]);
                    item.CatologyName = reader["CatologyName"].ToString();
                    item.Description = reader["Description"].ToString();
                    item.KindCatologyGuid = new Guid(reader["KindCatologyGuid"].ToString());
                    item.KindCatologyName = reader["KindCatologyName"].ToString();
                    item.IsActive = Convert.ToBoolean(reader["IsActive"].ToString());
                    item.UrlHinhanh = reader["UrlHinhanh"].ToString();

                    item.ListPlacementName = reader["ListPlacementName"].ToString();
                    item.Levels = Convert.ToInt32(reader["Levels"]);
                    item.Position = Convert.ToInt32(reader["Position"]);
                    try
                    {
                        item.IsNotDelete = Convert.ToBoolean(reader["IsNotDelete"].ToString());
                    }
                    catch { }
                    try
                    {
                        item.UserID = Convert.ToInt32(reader["UserID"]);
                    }
                    catch { }
                    items.Add(item);
                }
            }
            finally
            {
                reader.Close();
            }
            return items;
        }
Пример #15
0
        //xem trước các lỗi bắt bước 1
        private void ProcessPreviewExcelFile(string excelPath, string extension)
        {
            bool IsError = false;
            ExcelHelper excelHelper = new ExcelHelper();
            DataSet dataset = new DataSet();

            try { excelHelper.OpenExcelFile(excelPath, extension); }
            catch
            {
                ErrorMessage(true, "Lỗi không tìm thấy file import");
                return;
            }

            try { dataset = excelHelper.GetWorksheets(excelHelper.WorkSheetNames[0]); }
            catch
            {
                lblMessError.Text = Resource.ErrorD002;
                DeleteFileTemp(excelPath);
                return;
            }

            if (dataset.Tables[0].Rows.Count > 2000)
            {
                ErrorMessage(true, "Để đảm bảo đường truyền. Vui lòng chỉ import tối đa 2000 record trong một lần!");
                return;
            }

            if (dataset.Tables.Count > 0)
            {
                //kiem tra mau import
                int count = 0;
                int countError = 0;
                if (dataset.Tables[0].Rows.Count > 0 && !ValidateColumnName(dataset.Tables[0].Rows[0]))
                {
                    lblMessError.Text = Resource.ErrorD001;
                    return;
                }

                dataset.Tables[0].Columns.Add(new DataColumn("STT", typeof(int)));
                dataset.Tables[0].Columns.Add(new DataColumn("ErrorContent", typeof(string)));
                dataset.Tables[0].Columns.Add(new DataColumn("IsDongLoi", typeof(bool)));

                //Check data import
                string stringError;
                bool boolError;
                List<Catologie> listCatologie = new List<Catologie>();
                string itemInRow;
                string positionRecordError = string.Empty;
                try
                {
                    foreach (DataRow row in dataset.Tables[0].Rows)
                    {
                        itemInRow = string.Empty;
                        stringError = string.Empty;
                        boolError = false;
                        row["STT"] = ++count;

                        Catologie itemSP = new Catologie();

                        itemInRow = row["Massv"].ToString().Trim().ToUpper();
                        if (itemInRow.Equals(""))
                        {
                            stringError += ", Mã sinh viên " + Resource.ErrorD003;
                            IsError = true;
                        }
                        else
                            itemSP.Massv = itemInRow;

                        itemInRow = row["hovaten"].ToString().Trim();
                        if (itemInRow == "")
                        {
                            stringError += ", Tên sinh viên " + Resource.ErrorD003;
                            IsError = true;
                        }
                        else
                            itemSP.CatologyName = itemInRow;

                        itemInRow = row["lop"].ToString().Trim().ToUpper();
                        if (itemInRow == "")
                        {
                            stringError += ", Lớp " + Resource.ErrorD003;
                            IsError = true;
                        }
                        else
                            itemSP.Lop = itemInRow;

                        itemInRow = row["khoa"].ToString().Trim().ToUpper();
                        if (itemInRow == "")
                        {
                            stringError += ", Khoa " + Resource.ErrorD003;
                            IsError = true;
                        }
                        else
                            itemSP.Khoa = itemInRow;

                        //Check exist data
                        try
                        {
                            //Check row exist in data import
                            if (listCatologie.Contains(itemSP))
                            {
                                stringError += ", record " + Resource.ErrorD006;
                                IsError = true;
                            }
                            else
                                listCatologie.Add(itemSP);

                            //Check row exist in database
                            if (CheckItemCatologie(itemSP))
                            {
                                stringError += ", Trùng lắp thông tin CSDL";
                                IsError = true;
                            }
                        }
                        catch (Exception)
                        {
                            stringError = Resource.ErrorD007;
                            IsError = true;
                        }

                        //Check error; true: error - false: unError
                        boolError = stringError == string.Empty ? false : true;
                        if (boolError)
                        {
                            countError++;
                            positionRecordError = positionRecordError + ", " + count;
                        }
                        row["IsDongLoi"] = IsError;// boolError;
                        row["ErrorContent"] = stringError;

                    }
                }
                catch { }
                DeleteFileTemp(excelPath);

                //Save xml to preview and next step 2, then, save data into database
                lblMessageError.Text = "Lỗi " + countError.ToString() + " record! <b>Vị trí</b>: " + positionRecordError;
                if (TempXMLHelper.SaveTemporayDataAsXml(Server.MapPath(ConfigurationManager.AppSettings["VALUE_PATH_XML_INFOTEACHING"] + "/" + SiteUtils.GetCurrentUserId() + ".xml"), dataset))
                {
                    if (!IsError)
                        PopulateControls(Step.Step2);
                    else
                        PopulateControls(Step.Error);
                }
                else
                    PopulateControls(Step.Step1);
            }
        }
Пример #16
0
 internal static bool CheckExistUser(Catologie itemSP)
 {
     SqlParameterHelper sph = new SqlParameterHelper(ConnectionStringStatic.GetReadConnectionString(), "cont_UserProfile_CheckExistUser", 1);
     sph.DefineSqlParameter("@UserName", SqlDbType.NVarChar,256, ParameterDirection.Input, itemSP.Massv);
     return Convert.ToInt32(sph.ExecuteScalar())>0;
 }
Пример #17
0
 // <summary>
 /// Saves this instance of Catologie. Returns a new Guid on success.
 /// </summary>
 public Guid Save(Catologie item)
 {
     if (item.CatologyGuid == Guid.Empty)
         return Create(item);
     return Update(item);
 }