private void AddVehicle() { try { var verhicleBL = new VehicleFactory(); if (grdVehicle.SelectedRows.Count == 1) { var vehicleInfo = verhicleBL.SelectByID(int.Parse(grdVehicle.SelectedRows[0].Cells["VehicleID"].Value.ToString())); try { OnSelectedVehichle(this, new SelectedVehichleEventArgs() { Vehicle = vehicleInfo }); } catch (Exception) { MessageBox.Show("Phương tiện này đã tồn tại trong tờ khai!"); } } else { MessageBox.Show("Bạn cần chọn 1 phương."); } } catch (Exception ex) { logger.Error(ex.ToString()); if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString()); } }
private void Init() { try { // TODO: Need to handler it if (_mode == 3) { btnDelete.Enabled = false; } btnSearch.Enabled = false; if (_mode == 0 || _mode == 4) // Add mode - Click on Add New { dtpImportDate.Visible = false; mtxtImportHour.Visible = false; dtpExportDate.Visible = false; mtxtExportHour.Visible = false; lblIsExport.Visible = true; lblIsImport.Visible = true; btnUpdate.Enabled = false; btnAdd.Enabled = true; btnDelete.Enabled = false; btnConfirmImport.Enabled = true; btnConfirmExport.Enabled = true; btnAdd.Enabled = true; ResetForm(); btnAdd.Text = "Lưu trữ phương tiện"; btnSearch.Enabled = true; } else if (_mode == 1) // Add mode - CLick on Update { dtpImportDate.Visible = false; mtxtImportHour.Visible = false; btnUpdate.Enabled = true; btnAdd.Enabled = false; btnDelete.Enabled = true; btnConfirmImport.Enabled = true; foreach (VehicleInfo vehicleInfo in _vehicleInfosTemp) { if (vehicleInfo.Count == _count) { BindDataToControls(vehicleInfo); break; } } btnAdd.Text = "Lưu trữ phương tiện"; } else if (_mode == 2 || _mode == 3) // EditMode - Update { btnAdd.Enabled = false; // Get data from database _vehicleBOL = new VehicleFactory(); var vehicleInfo = _vehicleBOL.SelectByID(_vehicleID); if (_vehicleID == 0) // If vehicleID > 0 --> this form is opened form search form. so get data from database. If vehicle=0--> get by Count { foreach (VehicleInfo vehicleInfoTemp in _vehicleInfosTemp) { if (vehicleInfoTemp.Count == _count) { vehicleInfo = vehicleInfoTemp; } } } if (vehicleInfo.ImportDate != null && vehicleInfo.IsImport) { if (vehicleInfo.ImportDate.Value.Year.Equals(1900)) { vehicleInfo.ImportDate = null; dtpImportDate.Visible = false; mtxtImportHour.Visible = false; lblIsImport.Visible = true; } if (vehicleInfo.ExportDate != null && vehicleInfo.IsExport) if (vehicleInfo.ExportDate.Value.Year.Equals(1900)) { vehicleInfo.ImportDate = null; dtpExportDate.Visible = false; mtxtExportHour.Visible = false; lblIsExport.Visible = true; } } // Bind data to Controls //if(vehicleInfo.IsExport){ //if(vehicleInfo.ConfirmExportBy != _userInfo.UserID) //} BindDataToControls(vehicleInfo); _declarationID = vehicleInfo.DeclarationID; btnAdd.Text = "Thêm mới phương tiện"; } //// Check permission //if (_userInfo.PermissionID != 2) // Not is admin //{ // btnConfirmExport.Enabled = false; // btnConfirmImport.Enabled = false; //} InitialPermission(); } catch (Exception ex) { logger.Error(ex.ToString()); if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString()); } }