using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LYFZ.Software.MainBusiness.SMSManagement
{
public class frmSelectSmsInfo : LYFZ.Software.UI.SMSManagement.frmSelectSmsInfo
{
LYFZ.DAL.DAL_SMSTemplates smsDal = new DAL.DAL_SMSTemplates();
LYFZ.BLL.BLL_SMSTemplates smsBLL = new BLL.BLL_SMSTemplates();
LYFZ.Model.Model_SMSTemplates smsModel = new Model.Model_SMSTemplates();
public frmSelectSmsInfo()
{
this.Load += frmAddCommonSMS_Load;
this.Shown += frmAddCommonSMS_Shown;
this.cboxSmsClass.SelectedIndexChanged += cboxSmsClass_SelectedIndexChanged;
this.dgvCommonSMS.CellDoubleClick += dgvCommonSMS_CellDoubleClick;
this.btnCommonSMSAdd.Click += btnCommonSMSAdd_Click;
}
void btnCommonSMSAdd_Click(object sender, EventArgs e)
{
frmAddCommonSMS frmAddSms = new frmAddCommonSMS();
if (frmAddSms.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
BindSmsClass(this.cboxSmsClass);
BindDgvCommonSMS();
}
}
void dgvCommonSMS_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
DataGridViewRow row = this.dgvCommonSMS.Rows[e.RowIndex];
try
{
this.SmsModel = (LYFZ.Model.Model_SMSTemplates)row.Tag;
}
catch { }
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
void cboxSmsClass_SelectedIndexChanged(object sender, EventArgs e)
{
string cClass=this.cboxSmsClass.Text.Trim();
foreach (DataGridViewRow row in this.dgvCommonSMS.Rows)
{
if (cClass == "全部")
{
row.Visible = true;
}
else {
if (row.Cells[0].Value.ToString().Trim() == cClass)
{
row.Visible = true;
}
else {
row.Visible = false;
}
}
}
}
void frmAddCommonSMS_Shown(object sender, EventArgs e)
{
BindDgvCommonSMS();
}
///
/// 短信对象
///
public LYFZ.Model.Model_SMSTemplates SmsModel
{
get { return smsModel; }
set { smsModel = value; }
}
void BindDgvCommonSMS()
{
this.dgvCommonSMS.Rows.Clear();
try
{
List smsModelList = null;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
try
{
smsModelList = smsBLL.GetModelList("ST_Type=0");
}
catch
{
MessageBoxCustom.Show("常用短信加载失败!请检查网络环境或关闭系统后重试!", backgroundWorker: backgroundWorker);
}
});
if (smsModelList != null)
{
foreach (LYFZ.Model.Model_SMSTemplates model in smsModelList)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dgvCommonSMS);
row.Cells[0].Value = model.ST_Title;
row.Cells[1].Value = model.ST_SMSContent;
row.Tag = model;
this.dgvCommonSMS.Rows.Add(row);
}
if (this.dgvCommonSMS.SortedColumn != null)
{
ListSortDirection Direction = ListSortDirection.Descending;
switch (this.dgvCommonSMS.SortOrder)
{
case SortOrder.Ascending:
Direction = ListSortDirection.Ascending;
break;
case SortOrder.Descending:
Direction = ListSortDirection.Descending;
break;
default: break;
}
this.dgvCommonSMS.Sort(this.dgvCommonSMS.SortedColumn, Direction);
}
}
}
catch
{
MessageBoxCustom.Show("常用短信记录加载失败!请检查网络环境或关闭系统后重试!");
}
}
public static void BindSmsClass(ComponentLibrary.ComboBoxEx cbox)
{
LYFZ.DAL.DAL_SMSTemplates smsTDal = new DAL.DAL_SMSTemplates();
List SMSClassList = smsTDal.GetCommonSMSClassList();
SMSClassList.Insert(0, "全部");
cbox.DataSource = SMSClassList;
smsTDal = null;
}
void frmAddCommonSMS_Load(object sender, EventArgs e)
{
BindSmsClass(this.cboxSmsClass);
}
}
}