2019年9月25日 星期三

[angularJs] popup 使用 : angular-ui

使用 : angular-ui

預覽參考 : https://plnkr.co/edit/?p=preview

1. 加入ui-bootstrap-tpls-2.5.0.min.js
2. module include ui.bootstrap
3. 加入$uibModal
4. 建立fn  openMyModalView
5. 建立template controller

<script type="text/ng-template" id="DetailView.html">
    <div class="modal-header">
        <h3 class="modal-title" id="modal-title">I'm a modal!</h3>
    </div>
    <div class="modal-body" id="modal-body">
        <ul>
            <li ng-repeat="item in ctrl.items">
                <a href="#" ng-click="$event.preventDefault(); $ctrl.selected.item = item">{{ item }}</a>
            </li>
        </ul>
        Selected: <b>{{ ctrl.selected.item }}</b>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ctrl.ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="ctrl.cancel()">Cancel</button>
    </div>
</script>
    <script>
    var DefaultApp = angular.module("Default", ['ngTable','ui.bootstrap']);
    DefaultApp.controller('RegistrationController',
        ['$scope', '$http', 'NgTableParams', '$uibModal', function ($scope, $http, NgTableParams, $uibModal) {
            console.log("test12")
 
            var self = this;
            self.List = @Html.Raw(ViewBag.Registration);
            console.log(self.List);
 
            //初始化
            self.Init = function()
            {
                self.tableParams = new NgTableParams({ count: 50 }, { dataset: self.List });
            }
            self.Init();
 
             //方法
            // ref : https://angular-ui.github.io/bootstrap
            self.openMyModalView = function (item) {
                var modalInstance = $uibModal.open({
                    templateUrl: 'DetailView.html',
                    controller: 'UserDetailCtrl as ctrl',
                    resolve: {
                        item: function () {
                            return item;
                        }
                    }
                });
 
                modalInstance.result.then(function (obj) {
                    console.log(obj)
                }, function () {
                    $log.info('modal-component dismissed at: ' + new Date());
                });
            };
 
            self.SaveHandWrite = function () {
                console.log(self.Edit);
            }
    }]
);
    //popup 事件
    angular.module('Default').controller('UserDetailCtrl', function ($uibModalInstance, item) {
        console.log(item);
        var $ctrl = this;
 
        item.Name = "test";
 
        $ctrl.ok = function () {
            $uibModalInstance.close(item);
        };
 
        $ctrl.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
    });
    </script>
 
 

2019年9月12日 星期四

[C#] SYSTEM.IO 常用到的檔案存取

以下列出一些平常會用到的操作資料方法

git : https://raw.githubusercontent.com/todomato/CSharp_IO/master/Program.cs

       static void Main(string[] args)
    {
 
        //取得Bin資料夾
        var bin = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "");
        var path = Path.Combine(Path.GetDirectoryName(bin),"Demo");
        //判斷資料夾位置
        if (!Directory.Exists(path))
        {
            //建立資料夾
            Directory.CreateDirectory(path);
        }
 
        #region 文件相關
        Console.WriteLine(Path.GetDirectoryName(path));     //取得資料夾稱, D:\TestDir
        Console.WriteLine(Path.Combine(new string[] { @"D:\", "BaseDir", "SubDir", "TestFile.txt" })); //產生路徑
        #endregion
 
        //判斷檔案位置
        var filename = "test.txt";
 
        //結合路徑
        var filePath = Path.Combine(path, filename);
 
        //判斷資料夾位置
        if (!File.Exists(filePath))
        {
            //建立檔案
            using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                AddText(fs, "This is some text");
                AddText(fs, "This is some more text,");
                AddText(fs, "\r\nand this is on a new line");
                AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n");
            }
        }