Blame view

App/listCtruong/VcEdit.swift 7.63 KB
1341bf603   Trịnh Văn Quân   version 1.1
1
2
3
  import UIKit
  import Foundation
  import GeneralUtils
fbd62afcf   Trịnh Văn Quân   version 1.2.2
4
  import Alamofire
1341bf603   Trịnh Văn Quân   version 1.1
5
6
7
8
9
10
11
12
  
  class VcEdit: BaseViewControllerShowTransculent {
      @IBOutlet weak var root: UIView!
      @IBOutlet weak var tvTenCty: UILabel!
      @IBOutlet weak var tvTenCtruong: UILabel!
      @IBOutlet weak var tvListShootItem: UILabel!
      @IBOutlet weak var tvListWillShoot: UILabel!
      @IBOutlet weak var tvSignboard: UILabel!
fbd62afcf   Trịnh Văn Quân   version 1.2.2
13
14
      weak var tableViewListCtruong: UITableViewLoadDataFromUIThread?
      weak var vcShootItemList: VCShootItemList?
1341bf603   Trịnh Văn Quân   version 1.1
15

fbd62afcf   Trịnh Văn Quân   version 1.2.2
16
17
18
19
20
      var cTruong: CongTruong!;
      var isChangedCompany = false, isChangedConstruction = false, isChangedSignboard = false, isChangedshoot = false;
  
      static func openController(_ viewController: UIViewController, cTruong: CongTruong, tableViewListCtruong: UITableViewLoadDataFromUIThread?,
                                 vcShootItemList: VCShootItemList?) {
1341bf603   Trịnh Văn Quân   version 1.1
21
          BaseViewControllerShowTransculent.showTransculent(viewController, storyboardName: "Main", viewControllerIdentifier: "VcEdit",
fbd62afcf   Trịnh Văn Quân   version 1.2.2
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                  isDismisWhenTapOutSide: true, initBeforeLoad: { vc in
              if let vc = vc as? VcEdit {
                  vc.cTruong = cTruong;
                  vc.tableViewListCtruong = tableViewListCtruong;
                  vc.vcShootItemList = vcShootItemList;
              }
          })
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          let tap = UITapGestureRecognizer.init(target: self, action: #selector(VcEdit.bgClick))
          root.isUserInteractionEnabled = true
          root.addGestureRecognizer(tap)
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          self.updateState()
      }
  
      func updateState() {
          tvTenCty.text = cTruong.companyName
          tvTenCtruong.text = cTruong.constructionName
          if let signboard = cTruong.signboard, signboard > 0 {
              tvSignboard.text = "ON"
          } else {
              tvSignboard.text = "OFF"
          }
          tvListShootItem.text = cTruong.getShootItemsName(isWillshoot: false)
          tvListWillShoot.text = cTruong.getShootItemsName(isWillshoot: true)
1341bf603   Trịnh Văn Quân   version 1.1
53
54
55
      }
  
      @IBAction func tvTenCtyClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
56
57
58
59
60
61
62
63
64
65
66
          let dialog = DialogUtils.builderDialog(showCloseButton: false, showTitle: false)
          let edt = dialog.addTextField()
          edt.text = cTruong.companyName
          dialog.addButton(LocalizedString("OK"), action: {
              let result = (edt.text ?? "");
              self.cTruong.companyName = result;
              self.isChangedCompany = true;
              self.updateState();
          })
          dialog.showTitle("", subTitle: "施工会社名", style: .edit)
          edt.becomeFirstResponder()
1341bf603   Trịnh Văn Quân   version 1.1
67
68
69
70
71
      }
  
      @IBAction func deleteClick(_ sender: Any) {
          let dialog = DialogUtils.builderDialog()
          dialog.addButton("消去する", action: {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
              guard let id = self.cTruong.id else { return }
              let parameters: Parameters = [
                      "id": id,
              ]
              NetWorkUtils.excutePostTypeRawJSONEncoding(parameters: parameters, url: Constants.PathManager.ROOT_SERVER + "api/regulations/delete",
                      isShowProgress: true, vc: self, responseStringParam: { response in
                  guard let value = response.value else { return }
                  println(response.value)
                  let json = JSON.parse(value)
                  if let isSuccess = json["isSuccess"].bool, isSuccess {
                      guard let itemsData = self.tableViewListCtruong?.itemsData else { return }
                      var count = 0;
                      var indexFind = -1;
                      for e in itemsData {
                          if let ctr = e as? CongTruong, ObjectIdentifier(ctr) == ObjectIdentifier(self.cTruong) {
                              indexFind = count;
                              break;
                          }
                          count += 1;
                      }
                      if indexFind >= 0 {
                          self.tableViewListCtruong?.itemsData.remove(at: indexFind);
                          println("delete success: \(self.tableViewListCtruong != nil)")
                          self.tableViewListCtruong?.reloadDataTableView();
                          self.dismiss(animated: false, completion: {
                              UIApplication.topViewController()?.dismiss(animated: true)
                          })
                      }
                      return
                  } else {
                      CommonUtils.showToastLong(text: LocalizedString("Has_Error_occurred"))
                  }
              })
1341bf603   Trịnh Văn Quân   version 1.1
105
106
107
108
109
110
          })
          dialog.showTitle("リスト消去", subTitle: "リストを消去すると全ての項目が消去されます",
                  style: .warning, closeButtonTitle: "戻る")
      }
  
      @IBAction func boardSettingClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
111
112
113
114
115
116
117
          if cTruong.signboard == 1 {
              cTruong.signboard = 0
          } else {
              cTruong.signboard = 1
          }
          isChangedSignboard = true;
          updateState()
1341bf603   Trịnh Văn Quân   version 1.1
118
119
120
      }
  
      @IBAction func listWillShootClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
121
122
          VCChonMucChup.openControllerFromEdit(self, cTruong: self.cTruong);
          isChangedshoot = true;
1341bf603   Trịnh Văn Quân   version 1.1
123
124
125
      }
  
      @IBAction func listShootClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
126
127
          VCNhapMucChup.openControllerFromEdit(self, cTruong: self.cTruong);
          isChangedshoot = true;
1341bf603   Trịnh Văn Quân   version 1.1
128
129
130
      }
  
      @IBAction func cTruongClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
131
132
133
134
135
136
137
138
139
140
141
          let dialog = DialogUtils.builderDialog(showCloseButton: false, showTitle: false)
          let edt = dialog.addTextField()
          edt.text = cTruong.constructionName
          dialog.addButton(LocalizedString("OK"), action: {
              let result = (edt.text ?? "");
              self.cTruong.constructionName = result;
              self.isChangedConstruction = true;
              self.updateState();
          })
          dialog.showTitle("", subTitle: "工事件名", style: .edit)
          edt.becomeFirstResponder()
1341bf603   Trịnh Văn Quân   version 1.1
142
143
144
145
146
147
148
149
150
      }
  
      override func getHeightContent() -> CGFloat {
          return self.view.bounds.height
      }
  
      override func isFullWidth() -> Bool {
          return true
      }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
151
152
      @IBAction func whiteClick(_ sender: Any) {
      }
1341bf603   Trịnh Văn Quân   version 1.1
153
154
      func bgClick() {
          dismiss(animated: true)
fbd62afcf   Trịnh Văn Quân   version 1.2.2
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
          guard let id = self.cTruong.id else { return }
          if isChangedshoot {
              if let vcShootItemList = self.vcShootItemList {
                  vcShootItemList.tableView.initAndLoadData(vcShootItemList)
              }
              var shootingItems = [Any]()
              if let shootItems = cTruong.shootItems {
                  for item in shootItems {
                      shootingItems.append(item.toDic())
                  }
              }
  
              let parameters: Parameters = [
                      "idRegulation": id,
                      "shootingItems": shootingItems
              ]
              NetWorkUtils.excutePostTypeRawJSONEncoding(parameters: parameters, url: Constants.PathManager.ROOT_SERVER + "api/regulations/update/shooting",
                      responseStringParam: { response in
                      });
          }
  
          var parameters: Parameters = [
                  "id": id
          ]
          if isChangedConstruction || isChangedCompany || isChangedSignboard {
              if isChangedConstruction{
                  parameters["constructionName"] = self.cTruong.constructionName!;
              }
              if isChangedCompany{
                  parameters["companyName"] = self.cTruong.companyName!;
              }
              if isChangedSignboard{
                  parameters["signboard"] = self.cTruong.signboard!;
              }
              NetWorkUtils.excutePostTypeRawJSONEncoding(parameters: parameters, url: Constants.PathManager.ROOT_SERVER + "api/regulations/update",
                      responseStringParam: { response in
                      });
          }
1341bf603   Trịnh Văn Quân   version 1.1
193
194
      }
  }