private void btnEdit_Click(object sender, EventArgs e) { try { using (DEWSRMEntities db = new DEWSRMEntities()) { int[] selRows = ((GridView)grdSMSFormate.MainView).GetSelectedRows(); DataRowView oID = (DataRowView)(((GridView)grdSMSFormate.MainView).GetRow(selRows[0])); int nID = Convert.ToInt32(oID["ID"]); SMSFormate oSMSFormate = db.SMSFormates.FirstOrDefault(p => p.SMSFormateID == nID); if (oSMSFormate == null) { MessageBox.Show("select an item to edit", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } fSMSFormate frm = new fSMSFormate(); frm.ItemChanged = RefreshList; frm.ShowDlg(oSMSFormate, false); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDelete_Click(object sender, EventArgs e) { try { using (DEWSRMEntities db = new DEWSRMEntities()) { int[] selRows = ((GridView)grdSMSFormate.MainView).GetSelectedRows(); DataRowView oID = (DataRowView)(((GridView)grdSMSFormate.MainView).GetRow(selRows[0])); int nID = Convert.ToInt32(oID["ID"]); SMSFormate oSMSFormate = db.SMSFormates.FirstOrDefault(p => p.SMSFormateID == nID); if (oSMSFormate == null) { MessageBox.Show("select an item to delete", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.SMSFormates.Attach(oSMSFormate); db.SMSFormates.Remove(oSMSFormate); db.SaveChanges(); MessageBox.Show("Data Deleted Successfully.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshList(); } ; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void RefreshList() { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add("ID"); dt.Columns.Add("Code"); dt.Columns.Add("SDate"); dt.Columns.Add("SMS"); dt.Columns.Add("STO"); dt.Columns.Add("Status"); try { using (DEWSRMEntities db = new DEWSRMEntities()) { _SMSFormatList = db.SMSFormates.ToList(); _CustomerList = db.Customers.ToList(); var _SMSStatus = db.SMSStatuses; Customer oCustomer = null; SMSFormate oSMSFormate = null; foreach (SMSStatus oSMSStatus in _SMSStatus) { oCustomer = _CustomerList.FirstOrDefault(p => p.CustomerID == oSMSStatus.CustomerID); oSMSFormate = _SMSFormatList.FirstOrDefault(p => p.SMSFormateID == oSMSStatus.SMSFormateID); dr = dt.NewRow(); dr["ID"] = oSMSStatus.SMSStatusID; dr["Code"] = oSMSStatus.Code; dr["SDate"] = oSMSStatus.EntryDate.ToString("dd MMM yyyy"); if (oSMSFormate != null) { dr["SMS"] = oSMSFormate.SMSDescription; } if (oCustomer != null) { dr["STO"] = oCustomer.Name; } if (oSMSStatus.SendingStatus == (int)EnumSMSSendStatus.Success) { dr["Status"] = "Success"; } else { dr["Status"] = "Fail"; } dt.Rows.Add(dr); } grdSMS.DataSource = dt; label2.Text = "Total :" + _SMSStatus.Count().ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { if (!IsValid()) { return; } using (DEWSRMEntities db = new DEWSRMEntities()) { if (_SMSFormate.SMSFormateID <= 0) { RefreshObject(); _SMSFormate.SMSFormateID = db.SMSFormates.Count() > 0 ? db.SMSFormates.Max(obj => obj.SMSFormateID) + 1 : 1; db.SMSFormates.Add(_SMSFormate); } else { _SMSFormate = db.SMSFormates.FirstOrDefault(obj => obj.SMSFormateID == _SMSFormate.SMSFormateID); RefreshObject(); } db.SaveChanges(); MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //if (MessageBox.Show("Do you want to create another Brand?", "Create Brand", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) //{ // if (ItemChanged != null) // { // ItemChanged(); // } // this.Close(); //} //else //{ if (ItemChanged != null) { ItemChanged(); } _SMSFormate = new SMSFormate(); RefreshValue(); txtCode.Text = GenerateSMSCode(); //} } } catch (Exception ex) { if (ex.InnerException == null) { MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void ShowDlg(SMSFormate oSMSFormate, bool IsNew) { _IsNew = IsNew; _SMSFormate = oSMSFormate; PopulatSMSTypeCbo(); RefreshValue(); this.ShowDialog(); }
public void ShowDlg(SMSFormate oSMSFormate, bool IsNew) { this.ShowDialog(); }
private void grdCustomers_MouseDoubleClick(object sender, MouseEventArgs e) { try { Customer oCustomer = null; Supplier oSupplier = null; Employee oEmployee = null; SMSFormate oSMSFormat = null; int[] selRows = ((GridView)grdCustomers.MainView).GetSelectedRows(); DataRowView oID = (DataRowView)(((GridView)grdCustomers.MainView).GetRow(selRows[0])); int nID = Convert.ToInt32(oID["ID"]); if (nID > 0) { if (_ObjectName == "Company") { this.Text = "Supplier Control"; oSupplier = db.Suppliers.FirstOrDefault(p => p.SupplierID == nID); _ctl.SelectedID = oSupplier.SupplierID; _ctl.Code = oSupplier.Code; _ctl.Name = oSupplier.Name; } else if (_ObjectName == "Customer") { this.Text = "Customer Control"; oCustomer = db.Customers.FirstOrDefault(p => p.CustomerID == nID); _ctl.SelectedID = oCustomer.CustomerID; _ctl.Code = oCustomer.Code; _ctl.Name = oCustomer.Name; } else if (_ObjectName == "Employee") { this.Text = "Employee Control"; oEmployee = db.Employees.FirstOrDefault(p => p.EmployeeID == nID); _ctl.SelectedID = oEmployee.EmployeeID; _ctl.Code = oEmployee.Code; _ctl.Name = oEmployee.Name; } else if (_ObjectName == "CCompany") { this.Text = "Supplier Due List"; oSupplier = db.Suppliers.FirstOrDefault(p => p.SupplierID == nID); _ctl.SelectedID = oSupplier.SupplierID; _ctl.Code = oSupplier.Code; _ctl.Name = oSupplier.Name; } else if (_ObjectName == "CCustomer") { this.Text = "Customer Due List"; oCustomer = db.Customers.FirstOrDefault(p => p.CustomerID == nID); _ctl.SelectedID = oCustomer.CustomerID; _ctl.Code = oCustomer.Code; _ctl.Name = oCustomer.Name; } else if (_ObjectName == "CreditCustomer") { this.Text = "CreditCustomer"; oCustomer = db.Customers.FirstOrDefault(p => p.CustomerID == nID); _ctl.SelectedID = oCustomer.CustomerID; _ctl.Code = oCustomer.Code; _ctl.Name = oCustomer.Name; } else if (_ObjectName == "SMSFormat") { this.Text = "SMSFormat"; oSMSFormat = db.SMSFormates.FirstOrDefault(p => p.SMSFormateID == nID); _ctl.SelectedID = oSMSFormat.SMSFormateID; _ctl.Code = oSMSFormat.Code; _ctl.Name = oSMSFormat.SMSDescription; } } if (ItemChanged != null) { ItemChanged(); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }