private void btnSave_Click(object sender, EventArgs e) { try { if (model == null) // add Industrial mode { model = new models.PremiumBannerModel(); //new model to assign data model.memberCode = comboMemCode.Text; // set province id model.adImg = imgBrowse.FileName != "imgBrowse" ? imgBrowse.SafeFileName : ""; //set file name model.adPath = txtBannerURL.Text.Trim(); // set thai name model.activeDate = dtpActivedate.Value.ToString("yyyy-MM-dd"); //set active date model.InActiveDate = dtpActivedate.Value.ToString("yyyy-MM-dd"); // set inactive date PremiumBannerController.InsertData(model); // call update method model = null; } else // update (edit) Industrial mode { model.memberCode = comboMemCode.SelectedValue.ToString(); // set province id model.adImg = imgBrowse.FileName != "imgBrowse" ? imgBrowse.SafeFileName : model.adImg; //set file name model.adPath = txtBannerURL.Text.Trim(); // set thai name model.activeDate = dtpActivedate.Value.ToString("yyyy-MM-dd"); //set active date model.InActiveDate = dtpActivedate.Value.ToString("yyyy-MM-dd"); // set inactive date PremiumBannerController.UpdateData(model); } if (imgBrowse.FileName != "imgBrowse") // Check if picture has selected { // Copy file to image folder in this project System.IO.File.Copy(imgBrowse.FileName, Properties.Settings.Default.ImagePath + imgBrowse.SafeFileName, true); } } finally { this.Close(); } }
private void btnEdit_Click(object sender, EventArgs e) { if (selectedPremiumBanner != null) { PremiumBannerController.CallAddEditForm(new AddPremiumBanner(selectedPremiumBanner)); // call form as edit data form. } ReloadDataGridView(); // Reload data in datagridview }
private void PremiumBannerForm_Load(object sender, EventArgs e) { SetEditColumnIntoDataGrid(); // Insert Edeit column into datagridview dataGridPremiumBanner.AutoGenerateColumns = true; // create gridview as auto generate columns. PremiumBannerController.GetData(dataGridPremiumBanner); // call data industrial into grid. //dataGridPremiumBanner.SelectedRows[0].Selected = true; dataGridPremiumBanner.AutoResizeColumns(); //Auto resize columns }
private void dataGridPremiumBanner_CellClick(object sender, DataGridViewCellEventArgs e) { selectedPremiumBanner = new PremiumBannerModel(); setPremiumBannerModel(dataGridPremiumBanner.SelectedRows[0]); if (e.ColumnIndex == 0 && e.RowIndex >= 0) { PremiumBannerController.CallAddEditForm(new AddPremiumBanner(selectedPremiumBanner)); // call form as edit data form. ReloadDataGridView(); // Reload data in datagridview } }
private void AddPremiumBanner_Load(object sender, EventArgs e) { PremiumBannerController.SetInitialComboBox(comboMemCode); //set province data into combobox if (model != null) //check model has data? { /* set Model into data */ comboMemCode.SelectedValue = model.memberCode; // set member code imgPreview.ImageLocation = Properties.Settings.Default.ImagePath + model.adImg; // Show selected image in Picture Box txtBannerURL.Text = model.adPath; // set banner url address dtpActivedate.Value = Convert.ToDateTime(model.activeDate); //set active date dtpInactiveDate.Value = Convert.ToDateTime(model.InActiveDate); // set inactive date } }
// Reload data When Add/Edit form was closed public void ReloadDataGridView() { PremiumBannerController.GetData(dataGridPremiumBanner); // call data industrial into grid. }
private void btnAddForm_Click(object sender, EventArgs e) { PremiumBannerController.CallAddEditForm(new AddPremiumBanner()); // call form as add data form. ReloadDataGridView(); // Reload data in datagridview }