using LYFZ.ComponentLibrary;
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 partial class FrmSendRecords : LYFZ.Software.UI.SMSManagement.FrmSendRecords
{
private delegate void UpdateControl();
public FrmSendRecords()
{
this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
this.Shown+=FrmSendRecords_Shown;
this.btnClose.Click+=btnClose_Click;
this.btnRefresh.Click+=btnRefresh_Click;
this.btnDelete.Click+=btnDelete_Click;
this.btnExport.Click+=btnExport_Click;
this.btnNewSend.Click += btnNewSend_Click;
this.dgv.CellDoubleClick += dgv_CellDoubleClick;
this.tabControlEx1.SelectedIndexChanged += tabControlEx1_SelectedIndexChanged;
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SendRecordsCompetence, CustomAttributes.OperatingAuthority.SMSResendSend))
{
this.btnNewSend.Enabled = true;
this.btnResendMicro.Enabled = true;
}
else
{
this.btnNewSend.Enabled = false;
this.btnResendMicro.Enabled = false;
}
#region 删除
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SendRecordsCompetence, CustomAttributes.OperatingAuthority.Delete))
{
btnDelete.Enabled = true;
this.btnDeleteMicro.Enabled = true;
}
else
{
btnDelete.Enabled = false;
this.btnDeleteMicro.Enabled = false;
}
#endregion
#region 导出
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SendRecordsCompetence, CustomAttributes.OperatingAuthority.DataExport))
{
btnExport.Enabled = true;
this.btnExpordMicro.Enabled = true;
}
else
{
btnExport.Enabled = false;
this.btnExpordMicro.Enabled = true;
}
#endregion
this.ucPagerEx2.EventPaging += ucPagerEx2_EventPaging;
this.btnQueryMicro.Click += btnQueryMicro_Click;
this.btnExpordMicro.Click += btnExpordMicro_Click;
this.btnCloseMicro.Click += btnCloseMicro_Click;
this.btnDeleteMicro.Click += btnDeleteMicro_Click;
this.btnResendMicro.Click += btnResendMicro_Click;
this.dgvMicroletter.CellDoubleClick += dgvMicroletter_CellDoubleClick;
}
void dgvMicroletter_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (dgvMicroletter.Rows.Count > 0 && dgvMicroletter.CurrentRow != null && e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
LYFZ.Software.MainBusiness.SMSManagement.SendRecords.FrmSMSContent set = new SendRecords.FrmSMSContent();
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)dgvMicroletter.CurrentRow.Tag;
if (e.ColumnIndex == 6)
{
set.Text = "模板消息发送日志";
set.Content = model.SR_SendReport + "\r\n" + model.SR_SendLogs;
}
else
{
// string Smsr_Content = dgv.CurrentRow.Cells["Smsr_Content"].Value.ToString();
set.Text = "推送消息内容预览";
set.Content = MessageContentPreview(model);
}
set.ShowDialog();
}
}
///
/// 获取推送消息预览内容
///
///
///
string MessageContentPreview(LYFZ.Model.Model_SMSRecord model)
{
string retInfo = "";
retInfo = model.SR_Content;
return retInfo;
}
void btnResendMicro_Click(object sender, EventArgs e)
{
try
{
if (this.dgvMicroletter.SelectedRows.Count <= 0)
{
MessageBoxCustom.Show("请选中你要重发的消息记录!");
return;
}
if (MessageBoxCustom.Show("你确定要重发选中的消息记录吗?", "重发提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
List modelList = new List();
foreach (DataGridViewRow row in this.dgvMicroletter.SelectedRows)
{
if (row.Tag != null)
{
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)row.Tag;
if (model.SR_Status != 100 && model.SR_Status != 0)
{
modelList.Add(model);
}
}
}
bool sendOK = true;
if (modelList.Count <= 0)
{
MessageBoxCustom.Show("您选中的消息记录没有需要重新发送的记录!发送中 和 等待发送的消息不需要重新发送");
return;
}
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
foreach (LYFZ.Model.Model_SMSRecord model in modelList)
{
model.SR_Status = (int)EnumPublic.SmsSendStatus.等待发送;
model.SR_SendReport = "手动重发中...";
model.SR_SendLogs = "手动重发/" + model.SR_SendLogs;
model.SR_StartSendDatetime = SDateTime.Now;
if (!this.bllSR.Update(model))
{
sendOK = false;
return;
}
}
});
if (sendOK)
{
MessageBoxCustom.Show("已标记为重发,稍后系统将重新发送消息");
this.Invoke(new UpdateControl(delegate()
{
bindMicro();
}));
}
else
{
MessageBoxCustom.Show("标记为重发失败,请重启软件后重试。");
}
}
}
catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
}
void btnDeleteMicro_Click(object sender, EventArgs e)
{
try
{
if (this.dgvMicroletter.SelectedRows.Count <= 0)
{
MessageBoxCustom.Show("请选中你要删除的数据!");
return;
}
if (MessageBoxCustom.Show("你确定要删除选择的消息记录吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string delSmsIDStr = "";
foreach (DataGridViewRow row in this.dgvMicroletter.SelectedRows)
{
if (row.Tag != null)
{
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)row.Tag;
if (model.SR_Status != 100)
{
delSmsIDStr += model.ID.ToString() + ",";
}
else
{
MessageBoxCustom.Show(EnumPublic.SmsSendStatus.发送中.ToString() + "的消息不能删除!");
return;
}
}
}
int delCount = this.dgvMicroletter.SelectedRows.Count;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
if (bllSR.DeleteList(delSmsIDStr.Trim().Trim(',')))
{
#region 写入操作日志
LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除模板消息记录, "删除" + delCount.ToString() + "条模板消息记录 ", LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
#endregion
MessageBoxCustom.Show("删除成功!");
this.Invoke(new UpdateControl(delegate()
{
bindMicro();
}));
}
else { MessageBoxCustom.Show("删除失败!"); }
});
}
}
catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
}
void btnCloseMicro_Click(object sender, EventArgs e)
{
this.Close();
}
void btnExpordMicro_Click(object sender, EventArgs e)
{
this.dgvMicroletter.ExportDataTable();
}
void btnQueryMicro_Click(object sender, EventArgs e)
{
try
{
bindMicro();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
void tabControlEx1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.tabControlEx1.SelectedIndex == 1)
{
if (this.dgvMicroletter.Rows.Count <= 0)
{
bindMicro();
}
}
}
int ucPagerEx2_EventPaging(UCPager.EventPagingArg e)
{
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
dgvMicroletter.DataSource = null;
DataTable dt = new DataTable();
string whereStr = " [SR_SendChannel]=1 ";
if (txtKeyWordMicro.Text.Trim().Length > 0)
{
whereStr = " [SR_SendChannel]=1 and ([SR_RecipientNumber] like '%" + txtKeyWordMicro.Text.Trim() + "%' or [SR_Content] like '%" + txtKeyWordMicro.Text.Trim() + "%') ";
}
this.dgvMicroletter.Rows.Clear();
List modelList = new List();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
pageData.TableName = "tb_SMSRecords";
pageData.PageIndex = this.ucPagerEx2.PageCurrent;
pageData.PageSize = this.ucPagerEx2.PageSize;
pageData.QueryCondition = whereStr + " and SR_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID.Trim() + "'";
pageData.QueryFieldName = "[id]"
+ " ,[SR_SendChannel]"
+ " ,[SR_Type]"
+ " ,[SR_SendEvent]"
+ " ,[SR_SMSGenerateIdentity]"
+ " ,[SR_SMSSendIdentity]"
+ " ,[SR_RecipientNumber]"
+ " ,[SR_Content]"
+ " ,[SR_StartSendDatetime]"
+ " ,[SR_SendSumCount]"
+ " ,[SR_Status]"
+ " ,[SR_SendLogs]"
+ " ,[SR_SendReport]"
+ " ,[SR_CreateDatetime]"
+ " ,[SR_SendDatetime]"
+ " ,[SR_SMSSendSender]";
pageData.OrderStr = " ID desc ";
DataSet da = pageData.QueryDataTable();
dt = da.Tables[0];
if (dt.Rows.Count > 0)
{
for (int t = 0; t < dt.Rows.Count; t++)
{
modelList.Add(bllSR.DataRowToModel(dt.Rows[t]));
}
}
});
if (dt.Rows.Count > 0)
{
foreach (LYFZ.Model.Model_SMSRecord model in modelList)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dgvMicroletter);
row.Cells[0].Value = model.SR_RecipientNumber;//客户名字
try
{
row.Cells[1].Value = ((LYFZ.EnumPublic.MicroTemplate)model.SR_SendSumCount).ToString();//模板标识
}
catch
{
row.Cells[1].Value = "未知模板";
}
row.Cells[2].Value = MessageContentPreview(model); //model.SR_Content;//发送消息预览
row.Cells[3].Value = model.SR_StartSendDatetime.ToString("yyyy-MM-dd HH:mm");
if (model.SR_SendDatetime > LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime())
{
row.Cells[4].Value = model.SR_SendDatetime.ToString("yyyy-MM-dd HH:mm");
}
row.Cells[5].Value = ((EnumPublic.SmsSendStatus)model.SR_Status).ToString();
if (model.SR_Status == 3)
{
row.Cells[5].Value = (EnumPublic.SmsSendStatus.忽略发送).ToString();
}
row.Cells[6].Value = model.SR_SendReport;
row.Cells[7].Value = model.SR_SMSSendSender;
row.Cells[8].Value = model.SR_CreateDatetime.ToString("yyyy-MM-dd HH:mm:ss");
row.Tag = model;
this.dgvMicroletter.Rows.Add(row);
}
dgvMicroletter.ClearSelection();
}
try
{
this.ucPagerEx2.TbDataSource = dt;
}
catch { }
return pageData.TotalCount;
}
///
/// 邦定微信模板消息发送记录
///
public void bindMicro()
{
this.ucPagerEx2.PageCurrent = 1;
this.ucPagerEx2.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize; //3;分页条数
this.ucPagerEx2.Bind();
}
void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (dgv.Rows.Count > 0 && dgv.CurrentRow != null && e.ColumnIndex>=0&&e.RowIndex>=0)
{
LYFZ.Software.MainBusiness.SMSManagement.SendRecords.FrmSMSContent set = new SendRecords.FrmSMSContent();
if (e.ColumnIndex == 6)
{
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)dgv.CurrentRow.Tag;
set.Text = "短信发送日志";
set.Content =model.SR_SendReport+"\r\n" +model.SR_SendLogs;
}
else {
string Smsr_Content = dgv.CurrentRow.Cells["Smsr_Content"].Value.ToString();
set.Text = "短信内容";
set.Content = Smsr_Content;
}
set.ShowDialog();
}
}
void btnNewSend_Click(object sender, EventArgs e)
{
try
{
if (this.dgv.SelectedRows.Count <= 0)
{
MessageBoxCustom.Show("请选中你要重发的短信记录!");
return;
}
if (MessageBoxCustom.Show("你确定要重发选中的短信记录吗?", "重发提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
List modelList = new List();
foreach (DataGridViewRow row in this.dgv.SelectedRows)
{
if (row.Tag != null)
{
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)row.Tag;
if (model.SR_Status != 100 && model.SR_Status != 0)
{
modelList.Add(model);
}
}
}
bool sendOK = true;
if (modelList.Count <= 0)
{
MessageBoxCustom.Show("您选中的短信记录没有需要重新发送的记录!发送中 和 等待发送的短信不需要重新发送");
return;
}
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
foreach (LYFZ.Model.Model_SMSRecord model in modelList)
{
model.SR_Status = (int)EnumPublic.SmsSendStatus.等待发送;
model.SR_SendReport = "手动重发中...";
model.SR_SendLogs = "手动重发/" + model.SR_SendLogs;
model.SR_StartSendDatetime = SDateTime.Now;
if (!this.bllSR.Update(model)) {
sendOK = false;
return;
}
}
});
if (sendOK)
{
MessageBoxCustom.Show("已标记为重发,稍后系统将重新发送短信");
this.Invoke(new UpdateControl(delegate()
{
bind();
}));
}
else {
MessageBoxCustom.Show("标记为重发失败,请重启软件后重试。");
}
}
}
catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
}
#region 加载
protected void FrmSendRecords_Shown(object sender, EventArgs e)
{
List hideControl = new List();
//LYFZSS.SystemSpecterPossessed.ISystemSpecterPossessed.GetMySystemSpecter = LYFZSS.SystemSpecterType.SST_D;
bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.BindVersionShowHideControl(
VersionControl.VersionFunctionEnum.短信管理微信短信推送, hideControl, null, null);
if (!b)
{
if (tabControlEx1.TabPages.Count > 1)
{
tabControlEx1.TabPages.Remove(tabControlEx1.TabPages[1]);
}
}
try
{
bind();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
public void bind()
{
this.ucPagerEx1.PageCurrent = 1;
this.ucPagerEx1.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize; //3;分页条数
this.ucPagerEx1.Bind();
}
#endregion
#region 刷新
protected void btnRefresh_Click(object sender, EventArgs e)
{
try
{
bind();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 关闭
protected void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
LYFZ.BLL.BLL_SMSRecord bllSR = new BLL.BLL_SMSRecord();
#region 删除
protected void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (this.dgv.SelectedRows.Count <= 0)
{
MessageBoxCustom.Show("请选中你要删除的数据!");
return;
}
if (MessageBoxCustom.Show("你确定要删除选择的短信记录吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string delSmsIDStr = "";
foreach (DataGridViewRow row in this.dgv.SelectedRows)
{
if (row.Tag != null)
{
LYFZ.Model.Model_SMSRecord model = (LYFZ.Model.Model_SMSRecord)row.Tag;
if (model.SR_Status != 100)
{
delSmsIDStr += model.ID.ToString() + ",";
}
else {
MessageBoxCustom.Show(EnumPublic.SmsSendStatus.发送中.ToString()+"的短信不能删除!");
return;
}
}
}
int delCount = this.dgv.SelectedRows.Count;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
if (bllSR.DeleteList(delSmsIDStr.Trim().Trim(',')))
{
#region 写入操作日志
LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除短信记录, "删除" + delCount.ToString() + "条短信记录 ", LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
#endregion
MessageBoxCustom.Show("删除成功!");
bind();
}
else { MessageBoxCustom.Show("删除失败!"); }
});
}
}
catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
}
#endregion
#region 导出
protected void btnExport_Click(object sender, EventArgs e)
{
this.dgv.ExportDataTable();
}
#endregion
#region 画分页
///
/// 画分页
///
///
///
private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
{
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
dgv.DataSource = null;
DataTable dt = new DataTable();
string whereStr = " [SR_SendChannel]=0 ";
if (txtKeyword.Text.Trim().Length > 0) {
whereStr = " [SR_SendChannel]=0 and ([SR_RecipientNumber] like '%" + txtKeyword.Text.Trim() + "%' or [SR_Content] like '%" + txtKeyword.Text.Trim() + "%') ";
}
this.dgv.Rows.Clear();
List modelList=new List();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
pageData.TableName = "tb_SMSRecords";
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = this.ucPagerEx1.PageSize;
pageData.QueryCondition = whereStr + " and SR_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID.Trim() + "'";
pageData.QueryFieldName = "[id]"
+" ,[SR_SendChannel]"
+" ,[SR_Type]"
+" ,[SR_SendEvent]"
+" ,[SR_SMSGenerateIdentity]"
+" ,[SR_SMSSendIdentity]"
+" ,[SR_RecipientNumber]"
+" ,[SR_Content]"
+" ,[SR_StartSendDatetime]"
+" ,[SR_SendSumCount]"
+" ,[SR_Status]"
+" ,[SR_SendLogs]"
+" ,[SR_SendReport]"
+" ,[SR_CreateDatetime]"
+" ,[SR_SendDatetime]"
+" ,[SR_SMSSendSender]";
pageData.OrderStr = " ID desc ";
DataSet da = pageData.QueryDataTable();
dt = da.Tables[0];
if (dt.Rows.Count > 0)
{
for (int t = 0; t < dt.Rows.Count; t++)
{
modelList.Add(bllSR.DataRowToModel(dt.Rows[t]));
}
}
});
if (dt.Rows.Count > 0)
{
foreach (LYFZ.Model.Model_SMSRecord model in modelList)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dgv);
row.Cells[0].Value = model.SR_RecipientNumber;
row.Cells[1].Value = model.SR_Content;
row.Cells[2].Value = model.SR_StartSendDatetime.ToString("yyyy-MM-dd HH:mm");
if (model.SR_SendDatetime > LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime())
{
row.Cells[3].Value = model.SR_SendDatetime.ToString("yyyy-MM-dd HH:mm");
}
row.Cells[4].Value = model.SR_SendSumCount.ToString();
row.Cells[5].Value = ((EnumPublic.SmsSendStatus)model.SR_Status).ToString();
row.Cells[6].Value = model.SR_SendReport;
row.Cells[7].Value = model.SR_SMSSendSender;
row.Cells[8].Value = model.SR_CreateDatetime.ToString("yyyy-MM-dd HH:mm:ss");
this.dgv.Rows.Add(row);
row.Tag = model;
}
dgv.ClearSelection();
}
try
{
this.ucPagerEx1.TbDataSource = dt;
}
catch { }
return pageData.TotalCount;
}
#endregion
}
}