Esempio n. 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            USER_METAS uSER_METAS = db.USER_METAS.Find(id);

            db.USER_METAS.Remove(uSER_METAS);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "USER_ID,DEPARTMENT_ID,SEX,BIRTHDAY,START_TIME,NUMBER_PHONE,SENIORITY,NATIVE_LAND,LITERACY")] USER_METAS uSER_METAS)
 {
     if (ModelState.IsValid)
     {
         db.Entry(uSER_METAS).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DEPARTMENT_ID = new SelectList(db.DEPARTMENTS, "DEPARTMENT_ID", "DEPARTMENT_NAME", uSER_METAS.DEPARTMENT_ID);
     ViewBag.USER_ID       = new SelectList(db.USERS, "USER_ID", "USERNAME", uSER_METAS.USER_ID);
     return(View(uSER_METAS));
 }
Esempio n. 3
0
        // GET: USER_METAS/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            USER_METAS uSER_METAS = db.USER_METAS.Find(id);

            if (uSER_METAS == null)
            {
                return(HttpNotFound());
            }
            return(View(uSER_METAS));
        }
Esempio n. 4
0
        // GET: USER_METAS/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            USER_METAS uSER_METAS = db.USER_METAS.Find(id);

            if (uSER_METAS == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DEPARTMENT_ID = new SelectList(db.DEPARTMENTS, "DEPARTMENT_ID", "DEPARTMENT_NAME", uSER_METAS.DEPARTMENT_ID);
            ViewBag.USER_ID       = new SelectList(db.USERS, "USER_ID", "USERNAME", uSER_METAS.USER_ID);
            return(View(uSER_METAS));
        }
        public ActionResult Import_UserMetas(HttpPostedFileBase file)
        {
            try
            {
                DataSet ds = new DataSet();
                if (Request.Files["file"].ContentLength > 0)
                {
                    string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName);

                    if (fileExtension == ".xls" || fileExtension == ".xlsx")
                    {
                        string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName;
                        if (System.IO.File.Exists(fileLocation))
                        {
                            System.IO.File.Delete(fileLocation);
                        }
                        Request.Files["file"].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\"";
                        //connection String for xls file format.
                        if (fileExtension == ".xls")
                        {
                            excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                        }
                        //connection String for xlsx file format.
                        else if (fileExtension == ".xlsx")
                        {
                            excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                        }
                        //Create Connection to Excel work book and add oledb namespace
                        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);


                        string query = string.Format("Select * from [{0}]", excelSheets[0]);
                        using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1))
                        {
                            dataAdapter.Fill(ds);
                        }
                    }
                    if (fileExtension.ToString().ToLower().Equals(".xml"))
                    {
                        string fileLocation = Server.MapPath("~/Content/") + Request.Files["FileUpload"].FileName;
                        if (System.IO.File.Exists(fileLocation))
                        {
                            System.IO.File.Delete(fileLocation);
                        }

                        Request.Files["FileUpload"].SaveAs(fileLocation);
                        XmlTextReader xmlreader = new XmlTextReader(fileLocation);
                        // DataSet ds = new DataSet();
                        ds.ReadXml(xmlreader);
                        xmlreader.Close();
                    }
                    so_dong_thanh_cong = 0;
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string usname = ds.Tables[0].Rows[i][0].ToString();
                        var    query  = (from u in db.USERS
                                         where u.USERNAME == usname
                                         select u).FirstOrDefault();
                        int id = query.USER_ID;

                        USER_METAS query_meta = new USER_METAS();
                        query_meta.USER_ID       = id;
                        query_meta.DEPARTMENT_ID = ds.Tables[0].Rows[i][1].ToString();
                        query_meta.SEX           = ds.Tables[0].Rows[i][2].ToString();
                        query_meta.BIRTHDAY      = xuLyNgayThang.XuLyChuoiNgayThang(ds.Tables[0].Rows[i][3].ToString());
                        query_meta.START_TIME    = xuLyNgayThang.XuLyChuoiNgayThang(ds.Tables[0].Rows[i][4].ToString());
                        query_meta.NUMBER_PHONE  = ds.Tables[0].Rows[i][5].ToString();
                        query_meta.SENIORITY     = ds.Tables[0].Rows[i][6].ToString();
                        query_meta.NATIVE_LAND   = ds.Tables[0].Rows[i][7].ToString();
                        query_meta.LITERACY      = ds.Tables[0].Rows[i][8].ToString();

                        db.USER_METAS.Add(query_meta);

                        db.SaveChanges();
                        so_dong_thanh_cong++;
                    }
                }
            }
            catch (Exception Ex)
            {
                ViewBag.Error = " Đã xảy ra lỗi, Liên hệ ngay với admin. " + Environment.NewLine + " Thông tin chi tiết về lỗi:" + Environment.NewLine + Ex;
            }
            finally
            {
                ViewBag.Message = "Đã import thành công " + so_dong_thanh_cong + " dòng";
            }

            return(View());
        }