Пример #1
0
        public ActionResult Create(WorksModel collection, List <HttpPostedFileBase> Img)
        {
            // TODO: Add insert logic here

            collection.UploadWorksFiles = Img;
            if (string.IsNullOrEmpty(collection.Remarks))
            {
                collection.Remarks = "";
            }
            if (collection.Create())
            {
                return(RedirectToAction("Index"));
            }

            CreateSelect();

            return(View());
        }
Пример #2
0
        public static void 新增作品(匯入資料 _匯入資料)
        {
            if (!_匯入資料.藝術家中文名稱.Contains(";"))
            {
                List <string> _作品風格       = 分割文字(_匯入資料.作品風格);
                List <string> StyleNoList = new List <string>();
                StyleNoList.Add("1");


                List <string> _作品類型       = 分割文字(_匯入資料.作品類型);
                List <string> GenreNoList = new List <string>();
                GenreNoList.Add("1");

                List <string> _作品所有人      = 分割文字(_匯入資料.作品所有人);
                List <string> OwnerNoList = new List <string>();
                OwnerNoList.Add("1");

                List <string> _作品庫別          = 分割文字(_匯入資料.作品庫別);
                List <string> WareTypeNoList = new List <string>();
                WareTypeNoList.Add("1");


                List <string> _作品藝術家        = 分割文字(_匯入資料.藝術家中文名稱);
                List <string> AuthorsNoList = new List <string>();
                AuthorsNoList.Add("1");

                List <WorksModel.WorksModuleModel> WorksModuleModelList = new List <WorksModel.WorksModuleModel>();

                using (var context = new EG_MagicCubeEntities())
                {
                    string _作品編號 = 處理文字(_匯入資料.作品編號);

                    var _Works = context.Works.AsQueryable().Where(c => c.MaterialsID == _作品編號).Select(c => c).FirstOrDefault();
                    if (_Works == null)
                    {
                        var _匯入資料List = 匯入資料List.Where(c => c.作品編號 == _匯入資料.作品編號).Select(c => c).ToList();

                        //風格
                        var 風格List = _匯入資料List.Select(c => c.作品風格).ToList();
                        if (風格List != null && 風格List.Count > 0)
                        {
                            foreach (string str in 風格List)
                            {
                                _作品風格 = 處理標籤(_作品風格, str, true);
                            }
                            if (_作品風格 != null && _作品風格.Count > 0)
                            {
                                var _Array = context.Menu_Style.AsQueryable().Where(c => _作品風格.Contains(c.StyleName)).Select(c => c.StyleNo).ToList();
                                if (_Array != null && _Array.Count > 0)
                                {
                                    StyleNoList = _Array.Select(c => c.ToString()).ToList();
                                }
                            }
                        }

                        var 類型List = _匯入資料List.Select(c => c.作品類型).ToList();
                        if (類型List != null && 類型List.Count > 0)
                        {
                            foreach (string str in 類型List)
                            {
                                _作品類型 = 處理標籤(_作品類型, str, true);
                            }
                            if (_作品類型 != null && _作品類型.Count > 0)
                            {
                                var _Array = context.Menu_Genre.AsQueryable().Where(c => _作品類型.Contains(c.GenreName)).Select(c => c.GenreNo).ToList();
                                if (_Array != null && _Array.Count > 0)
                                {
                                    GenreNoList = _Array.Select(c => c.ToString()).ToList();
                                }
                            }
                        }

                        var 所有人List = _匯入資料List.Select(c => c.作品所有人).ToList();
                        if (所有人List != null && 所有人List.Count > 0)
                        {
                            foreach (string str in 所有人List)
                            {
                                _作品所有人 = 處理標籤(_作品所有人, str, true);
                            }
                            if (_作品所有人 != null && _作品所有人.Count > 0)
                            {
                                var _Array = context.Menu_Owner.AsQueryable().Where(c => _作品所有人.Contains(c.OwnerName)).Select(c => c.OwnerNo).ToList();
                                if (_Array != null && _Array.Count > 0)
                                {
                                    OwnerNoList = _Array.Select(c => c.ToString()).ToList();
                                }
                            }
                        }

                        var 庫別List = _匯入資料List.Select(c => c.作品庫別).ToList();
                        if (庫別List != null && 庫別List.Count > 0)
                        {
                            foreach (string str in 庫別List)
                            {
                                _作品庫別 = 處理標籤(_作品庫別, str, true);
                            }
                            if (_作品庫別 != null && _作品庫別.Count > 0)
                            {
                                var _Array = context.Menu_WareType.AsQueryable().Where(c => _作品庫別.Contains(c.WareTypeName)).Select(c => c.WareTypeNo).ToList();
                                if (_Array != null && _Array.Count > 0)
                                {
                                    WareTypeNoList = _Array.Select(c => c.ToString()).ToList();
                                }
                            }
                        }

                        var 藝術家List = _匯入資料List.Select(c => c.藝術家中文名稱).ToList();
                        if (藝術家List != null && 藝術家List.Count > 0)
                        {
                            foreach (string str in 藝術家List)
                            {
                                _作品藝術家 = 處理標籤(_作品藝術家, str, true);
                            }
                            if (_作品藝術家 != null && _作品藝術家.Count > 0)
                            {
                                var _Array = context.Authors.AsQueryable().Where(c => _作品藝術家.Contains(c.AuthorsCName)).Select(c => c.AuthorsNo).ToList();
                                if (_Array != null && _Array.Count > 0)
                                {
                                    AuthorsNoList = _Array.Select(c => c.ToString()).ToList();
                                }
                            }
                        }

                        foreach (匯入資料 mm in _匯入資料List)
                        {
                            WorksModel.WorksModuleModel _WorksModuleModel = new WorksModel.WorksModuleModel();
                            int _Amount = 1;
                            int.TryParse(處理文字(mm.數量), out _Amount);
                            _WorksModuleModel.Amount = _Amount;

                            int _CountNounNo = context.Menu_CountNoun.AsQueryable().Where(c => c.CountNounName == mm.單位詞).Select(c => c.CountNounNo).FirstOrDefault();
                            if (_CountNounNo == 0)
                            {
                                _CountNounNo = 1;
                            }
                            _WorksModuleModel.CountNoun = new MenuViewModel()
                            {
                                MenuID = _CountNounNo
                            };

                            int _MaterialNo = context.Menu_Material.AsQueryable().Where(c => c.MaterialName == mm.媒材).Select(c => c.MaterialNo).FirstOrDefault();
                            if (_MaterialNo == 0)
                            {
                                _MaterialNo = 1;
                            }
                            _WorksModuleModel.Material = new MenuViewModel()
                            {
                                MenuID = _MaterialNo
                            };

                            double _Height = 0.0;
                            double.TryParse(處理文字(mm.高度), out _Height);
                            _WorksModuleModel.Height = _Height;

                            double _Width = 0.0;
                            double.TryParse(處理文字(mm.寬度), out _Width);
                            _WorksModuleModel.Width = _Width;

                            double _Deep = 0.0;
                            double.TryParse(處理文字(mm.深度), out _Deep);
                            _WorksModuleModel.Deep = _Deep;

                            _WorksModuleModel.Length     = 0;
                            _WorksModuleModel.Measure    = 處理文字(mm.計算尺寸);
                            _WorksModuleModel.TimeLength = 處理文字(mm.錄像長度);
                            WorksModuleModelList.Add(_WorksModuleModel);
                        }
                        WorksModel _WorksModel = new WorksModel();

                        _WorksModel.MaterialsID = 處理文字(_匯入資料.作品編號);
                        _WorksModel.AuthorsNo   = -1;
                        _WorksModel.WorksName   = 處理文字(_匯入資料.作品名稱);

                        short _YearStart = 0;
                        short.TryParse(處理文字(_匯入資料.作品年代起), out _YearStart);
                        _WorksModel.YearStart = _YearStart;

                        short _YearEnd = 0;
                        short.TryParse(處理文字(_匯入資料.作品年代迄), out _YearEnd);
                        _WorksModel.YearEnd = _YearEnd;

                        int _Cost = 0;
                        int.TryParse(處理文字(_匯入資料.成本), out _Cost);
                        _WorksModel.Cost = _Cost;

                        int _Price = 0;
                        int.TryParse(處理文字(_匯入資料.定價), out _Price);
                        _WorksModel.Price = _Price;

                        _WorksModel.GrossMargin = Math.Round((((Convert.ToDouble((_Price / double.Parse("1.05"))) - Convert.ToDouble(_Cost)) / Convert.ToDouble((_Price / double.Parse("1.05")))) * Convert.ToDouble(100)), 3);
                        _WorksModel.PricingDate = DateTime.Parse("2017/09/10");

                        double _Artisticability = 0.0;
                        double.TryParse(處理文字(_匯入資料.藝術性), out _Artisticability);
                        _WorksModel.Artisticability = _Artisticability;

                        double _Marketability = 0.0;
                        double.TryParse(處理文字(_匯入資料.市場性), out _Marketability);
                        _WorksModel.Marketability = _Marketability;

                        double _Packageability = 0.0;
                        double.TryParse(處理文字(_匯入資料.包裹性), out _Packageability);
                        _WorksModel.Packageability = _Packageability;

                        double _Valuability = 0.0;
                        double.TryParse(處理文字(_匯入資料.增值性), out _Valuability);
                        _WorksModel.Valuability = _Valuability;

                        _WorksModel.CreateUser = "******";
                        _WorksModel.CreateDate = DateTime.Now;
                        _WorksModel.ModifyUser = "******";
                        _WorksModel.ModifyDate = DateTime.Now;
                        _WorksModel.Remarks    = 處理文字(_匯入資料.備註);


                        //藝術家
                        _WorksModel.AuthorNo_InputString = AuthorsNoList;
                        //類型
                        _WorksModel.GenreNo_InputString = GenreNoList;
                        //風格
                        _WorksModel.StyleNo_InputString = StyleNoList;
                        //擁有者
                        _WorksModel.OwnerNo_InputString = OwnerNoList;
                        //庫別
                        _WorksModel.WareTypeNo_InputString = WareTypeNoList;
                        //組件
                        _WorksModel.WorksModuleList = WorksModuleModelList;
                        //圖片
                        Console.WriteLine(JsonConvert.SerializeObject(_WorksModel));
                        _WorksModel.Create();
                    }
                }
            }
        }