/// <summary> /// CloneList /// </summary> /// <param name="list"></param> /// <returns></returns> private ObservableCollection<Models.EmployeeInfo> CloneList(ObservableCollection<Models.EmployeeInfo> list) { ObservableCollection<Models.EmployeeInfo> resList = new ObservableCollection<Models.EmployeeInfo>(); foreach (var item in list) { Models.EmployeeInfo info = new Models.EmployeeInfo(); info.Birthday = item.Birthday; info.Bonus = item.Bonus; info.DepartmentId = item.DepartmentId; info.DepartmentName = item.DepartmentName; info.Id = item.Id; info.Level = item.Level; info.Name = item.Name; info.Remark = item.Remark; info.Salary = item.Salary; info.Sex = item.Sex; ObservableCollection<Models.SkillInfo> sk = new ObservableCollection<Models.SkillInfo>(); if (item.Skills != null) { foreach (var i in item.Skills) { info.Skills.Add(i); } } info.Skills = sk; resList.Add(info); } return resList; }
public ModalWin(Models.EmployeeInfo emp) { InitializeComponent(); GetDepartment(); GetAllSkills(); this._modle = emp; if (emp.Skills == null) _modle.Skills = new ObservableCollection<Models.SkillInfo>(); CloneModle(emp); LoadMySkill(); EmployeeGrid.DataContext = _modle; this.LevelSlider.Value = this._modle.Level; _id = _modle.Id; }
public ActionResult ImportFromExcel() { try { if (ModelState.IsValid) { using (var dbConn = OrmliteConnection.openConn()) { List <DC_Telesales_Agent_Meta> listData = new List <DC_Telesales_Agent_Meta>(); string filename = @"DC_TelesaleAgent Master Error_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls"; int total = 0; var listrow = new List <NPOI.SS.UserModel.IRow>(); if (Request.Files["FileUpload"] != null && Request.Files["FileUpload"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { // Create a folder in App_Data named ExcelFiles because you need to save the file temporarily location and getting data from there. string fileLocation = string.Format("{0}/{1}", Server.MapPath("~/Excel"), "[" + currentUser.UserName + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "]" + Request.Files["FileUpload"].FileName); if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["FileUpload"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return(null); } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); DataSet ds = new DataSet(); string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } //khoi tao save file error int rowNumber = 1; string currentUserName = currentUser.UserName; FileStream fs = new FileStream(Server.MapPath(@"~\ExportExcelFile\DC_TelesaleAgent.xls"), FileMode.Open, FileAccess.Read); string ErrorfileLocation = string.Format("{0}/{1}", Server.MapPath("~/Excel"), filename); var workbook = new HSSFWorkbook(fs, true); FileStream fileStream = new FileStream(ErrorfileLocation, FileMode.Create, FileAccess.Write); var sheet = workbook.GetSheet("TelesaleAgent"); //for (int k = 0; k <= ds.Tables[0].Rows.Count; k++) //{ // var row = sheet.GetRow(k); // listrow.Add(row); // sheet.RemoveRow(row); //} //chay vong lap qua row for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string importnote = ""; string UserName = ds.Tables[0].Rows[i]["UserName"].ToString(); string Team = ds.Tables[0].Rows[i]["Team"].ToString(); string Region = ds.Tables[0].Rows[i]["Region"].ToString(); string XLiteID = ds.Tables[0].Rows[i]["XLiteID"].ToString(); try { if (string.IsNullOrWhiteSpace(UserName)) { importnote += "Null error in required field(s)! "; } if (importnote != "") { throw new Exception(importnote); } EmployeeInfo us = new Models.EmployeeInfo(); us.UserName = UserName; //var requestID = DC_Customer_lvCredit_Request.GetDC_Customer_lvCredit_Requests("[OrganizationID]='" + request.OrganizationID + "' AND [CustomerID] = '" + request.CustomerID + "'", "").FirstOrDefault(); DC_Telesales_Agent ta = dbConn.FirstOrDefault <DC_Telesales_Agent>("UserName={0}", UserName); try { if (ta == null) { importnote += "Không tìm thấy agent này trong hệ thống!"; throw new Exception(importnote); } else { ta.XLiteID = XLiteID; ta.Region = Region; ta.Team = Team; ta.CreatedAt = DateTime.Now; ta.CreatedBy = currentUser.UserName; dbConn.Update(ta); } } catch { importnote += "Không tìm thấy agent này trong hệ thống!"; throw new Exception(importnote); } } catch (Exception e) { DC_Telesales_Agent_Meta org = new DC_Telesales_Agent_Meta(); org.AgentID = UserName; org.Team = Team; org.ImportNote = e.Message; listData.Add(org); //Create a new row var row = sheet.CreateRow(rowNumber++); //Set values for the cells row.CreateCell(0).SetCellValue(UserName); row.CreateCell(1).SetCellValue(Team); row.CreateCell(2).SetCellValue(Region); row.CreateCell(2).SetCellValue(XLiteID); row.CreateCell(4).SetCellValue(importnote); //Write the workbook to a memory stream importnote = ""; continue; } } workbook.Write(fileStream); fileStream.Close(); excelConnection.Close(); excelConnection1.Close(); } else { ModelState.AddModelError("", "Plese select Excel File."); } } return(Json(new { success = true, data = listData, total = total, link = filename })); } } else { return(Json(new { success = false })); } } catch (Exception ex) { return(Json(new { success = false })); } }
private void OnCreate(object sender, RoutedEventArgs e) { var emp = new Models.EmployeeInfo(); byte[] buffer = Guid.NewGuid().ToByteArray(); emp.Id = BitConverter.ToInt32(buffer, 0); emp.Birthday = DateTime.Now.AddYears(-20); modalWindow = new ModalWin(emp); modalWindow.Title = "添加员工窗口"; modalWindow.Tag = "add"; modalWindow.Closed += (s1, e1) => { if (modalWindow.DialogResult == true) GetEmployess(); }; modalWindow.Show(); }