protected void linkImportContentButton_Click(object sender, EventArgs e) { litErrorSpaceHolder.Text = ""; //try //{ divDefaultCategory.Visible = false; DataTable contentTable = create_ContentTable(); if (String.IsNullOrEmpty(txtFileName.Text)) { throw new Exception("You must select a source file!"); } //chuyển đổi địa chỉ URL sang Physycal string sFileURL = txtFileName.Text; string sFileName = sFileURL.Replace(System.Configuration.ConfigurationManager.AppSettings["LegoWebFilesVirtuaPath"], System.Configuration.ConfigurationManager.AppSettings["LegoWebFilesPhysicalPath"]); sFileName = sFileName.Replace("/", "\\"); if (!System.IO.File.Exists(sFileName)) { throw new Exception("Source file does not exists!"); } else { divDefaultCategory.Visible = true; } CRecords myRecs = new CRecords(); myRecs.load_File(sFileName); int iSkipCount = 0; for (int i = 0; i < myRecs.Count; i++) { CRecord myRec = new CRecord(); myRec.load_Xml(myRecs.Record(i).OuterXml); if (myRec.get_LeaderValueByPos(6, 6) == "s")//system tables data { import_SystemTableData(myRec); } else { Int32 iID = String.IsNullOrEmpty(myRecs.Record(i).Controlfields.Controlfield("001").Value) ? 0 : Int32.Parse(myRecs.Record(i).Controlfields.Controlfield("001").Value); Int32 iCatID = String.IsNullOrEmpty(myRecs.Record(i).Controlfields.Controlfield("002").Value) ? 0 : Int32.Parse(myRecs.Record(i).Controlfields.Controlfield("002").Value); switch (radioImportTypes.SelectedValue) { case "0": //append myRec.Controlfields.Controlfield("001").Value = "0"; switch (radioForceToDefaultCategory.SelectedValue) { case "0": //auto detech category id if (!LegoWebAdmin.BusLogic.Categories.is_CATEGORY_ID_EXIST(iCatID)) { myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; } break; case "1": //force to default category myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; break; } LegoWebAdmin.BusLogic.MetaContents.save_META_CONTENTS_XML(myRec.OuterXml, this.Page.User.Identity.Name); break; case "1": //skip if ID exsist if (!LegoWebAdmin.BusLogic.MetaContents.is_META_CONTENTS_EXIST(iID)) { switch (radioForceToDefaultCategory.SelectedValue) { case "0": //auto detech category id if (!LegoWebAdmin.BusLogic.Categories.is_CATEGORY_ID_EXIST(iCatID)) { myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; } break; case "1": //force to default category myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; break; } LegoWebAdmin.BusLogic.MetaContents.save_META_CONTENTS_XML(myRec.OuterXml, this.Page.User.Identity.Name); } else { iSkipCount++; } break; case "2": switch (radioForceToDefaultCategory.SelectedValue) { case "0": //auto detech category id if (!LegoWebAdmin.BusLogic.Categories.is_CATEGORY_ID_EXIST(iCatID)) { myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; } break; case "1": //force to default category myRec.Controlfields.Controlfield("002").Value = dropCategories.SelectedValue; break; } LegoWebAdmin.BusLogic.MetaContents.save_META_CONTENTS_XML(myRec.OuterXml, this.Page.User.Identity.Name); break; } } } litErrorSpaceHolder.Text = String.Format("Imports successfully {0} records, skips {1}!.", myRecs.Count.ToString(), iSkipCount.ToString()); // } // catch (Exception ex) // { // String errorFomat = @"<dl id='system-message'> // <dd class='error message fade'> // <ul> // <li>{0}</li> // </ul> // </dd> // </dl>"; // litErrorSpaceHolder.Text = String.Format(errorFomat, ex.Message); // } }