Exemple #1
0
        public ActionResult Port_Insert(PortInfo _obj)
        {
            decimal p_success = -1;

            try
            {
                p_success = PortBL.Port_Insert(_obj);
            }
            catch (Exception ex)
            {
                Common.log.Error(ex.ToString());
            }
            return(Json(new { success = p_success }));
        }
Exemple #2
0
        public Decimal Import_file_excel(HttpPostedFileBase fileImport)
        {
            try
            {
                DataSet _ds = new DataSet();
                if (fileImport != null && fileImport.ContentLength > 0)
                {
                    if (!fileImport.FileName.EndsWith(".xls") && !fileImport.FileName.EndsWith(".xlsx"))
                    {
                        return(-3);
                    }
                    else
                    {
                        Stream           stream = fileImport.InputStream;
                        IExcelDataReader reader = null;

                        if (fileImport.FileName.EndsWith(".xls"))
                        {
                            reader = ExcelReaderFactory.CreateBinaryReader(stream);
                        }
                        else if (fileImport.FileName.EndsWith(".xlsx"))
                        {
                            reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                        }

                        _ds = reader.AsDataSet();
                        reader.Close();
                    }
                }
                if (_ds != null)
                {
                    _ds.Tables[0].Rows[0].Delete();//xóa dòng title
                    _ds.AcceptChanges();
                    if (_ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in _ds.Tables[0].Rows)
                        {
                            PortInfo _obj = new PortInfo();
                            _obj.Port_Code = dr[0] == null ? "" : dr[0].ToString();
                            _obj.Port_Name = dr[1] == null ? "" : dr[1].ToString();
                            _obj.Notes     = dr[3] == null ? "" : dr[3].ToString();
                            string Type = dr[4] == null ? "" : dr[4].ToString();
                            if (Type != "")
                            {
                                _obj.Type = Convert.ToDecimal(Type);
                            }
                            if (_obj.Port_Code != "")
                            {
                                PortBL.Port_Insert(_obj);
                            }
                        }
                    }
                    else
                    {
                        return(-4);//không có dữ liệu
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                NaviCommon.Common.log.Error(ex.ToString());
                return(-1);
            }
        }