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;
using LYFZ.Command;
using LYFZ.ComponentLibrary;
namespace LYFZ.Software.MainBusiness.CallerWizard
{
public partial class FrmCustomerCalls : LYFZ.Software.UI.CallerWizard.FrmCustomerCalls
{
LYFZ.BLL.BLL_ErpCallWizard cwbll = new BLL.BLL_ErpCallWizard();
private delegate void UpdateControl();
public FrmCustomerCalls(string StrType = "")
{
this.StrLoadType = StrType;
this.Shown += FrmCustomerCalls_Shown;
this.btnQuery.Click += btnQuery_Click;
this.btnDelete.Click += btnDelete_Click;
this.btnCall.Click += btnCall_Click;
this.btnPlayer.Click += btnPlayer_Click;
this.btnClose.Click += btnClose_Click;
this.ucPager.EventPaging += UcPagerEx1_EventPaging;
this.txtQuery.KeyDown += txtQuery_KeyDown;
this.cmbtreevClientType.ComboBoxTree_NodeMouseClick += cmbtreevClientType_ComboBoxTree_NodeMouseClick;
this.Resize += FrmCustomerCalls_Resize;
this.dgvData.RowsAdded += dgvData_RowsAdded;
}
string GetPhoneColumn()
{
string strColumnName = "来电电话";
switch (StrLoadType)
{
case "已接电话": strColumnName = "来电号码"; break;
case "拨出电话": strColumnName = "拨出号码"; break;
case "未接电话": strColumnName = "来电号码"; break;
}
return strColumnName;
}
string GetDateTimeColumn()
{
string strColumnName = "来电时间";
switch (StrLoadType)
{
case "已接电话": strColumnName = "来电时间"; break;
case "拨出电话": strColumnName = "拨出时间"; break;
case "未接电话": strColumnName = "来电时间"; break;
}
return strColumnName;
}
enum CallClientType
{
全部 = -4,
订单客户 = 0,
老客户 = 1,
意向客户 = 2,
其他客户 = -1,
未知来电 = -2,
员工电话 = -3
}
string StrLoadType;
///
/// 窗体加载事件
///
///
///
void FrmCustomerCalls_Shown(object sender, EventArgs e)
{
this.UcNavigationTool.LabTitle = this.StrLoadType;
this.dtpDateStart.DateValue = SDateTime.Now.ToString("yyyy-MM") + "-01";
this.dtpDateEnd.DateValue = Convert.ToDateTime(this.dtpDateStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.CustomerCallsCompetence, CustomAttributes.OperatingAuthority.Delete);
string[] StrArrayName = Enum.GetNames(typeof(CallClientType));
TreeNode root = null;
for (int i = 0; i < StrArrayName.Length; i++)
{
if (i == 0)
{
root = new TreeNode();
root.Text = "全部";
root.Tag = Convert.ToInt32(Enum.Parse(typeof(CallClientType), "全部"));
root.Name = root.Tag.ToString();
this.cmbtreevClientType.Nodes.Add(root);
}
if (StrArrayName[i].Trim() != "全部")
{
root = new TreeNode();
root.Text = StrArrayName[i].Trim();
root.Tag = Convert.ToInt32(Enum.Parse(typeof(CallClientType), StrArrayName[i].Trim()));
root.Name = root.Tag.ToString();
this.cmbtreevClientType.Nodes.Add(root);
}
}
this.cmbtreevClientType.TextFindTag(CallClientType.全部.ToString());
this.PublicFunctionRows();
bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(
VersionControl.VersionFunctionEnum.来电精灵);
if (!b)
{
this.Close();
return;
}
}
///
/// 查询
///
///
///
void btnQuery_Click(object sender, EventArgs e)
{
this.PublicFunctionRows();
}
///
/// 回车查询
///
///
///
void txtQuery_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{ this.PublicFunctionRows(); }
}
///
/// 客户类型选择
///
///
///
void cmbtreevClientType_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
this.PublicFunctionRows();
}
///
/// 删除
///
///
///
void btnDelete_Click(object sender, EventArgs e)
{
if (this.dgvData.Rows.Count > 0)
{
if (MessageBoxCustom.Show("您确定删除吗?", "温馨提示!", MessageBoxButtons.YesNo) == DialogResult.No)
{ return; }
int deleteCount = 0;
if (this.dgvData.SelectedRows.Count > 0)
{
for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
{
if (!string.IsNullOrEmpty(this.dgvData.SelectedRows[i].Cells["ID"].Value.ToString().Trim()))
{
if (cwbll.Delete(Convert.ToInt32(this.dgvData.SelectedRows[i].Cells["ID"].Value)))
{
deleteCount++;
string StrPath = this.dgvData.SelectedRows[i].Cells["路径"].Value.ToString().Trim();
if (!string.IsNullOrEmpty(StrPath))
{
string StrNewPath = StrPath.Substring(StrPath.IndexOf("ShareDirectory"), StrPath.Length - StrPath.IndexOf("ShareDirectory"));
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
backgroundWorker.ReportProgress(0, "正在连接服务器...");
try
{
string ret = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.TcpClient.DeleteFile(StrNewPath, backgroundWorker);
if (ret.IndexOf("成功") == -1)
{ MessageBoxCustom.Show(ret, backgroundWorker: backgroundWorker); }
}
catch (Exception ex)
{ MessageBoxCustom.Show(ex.Message, backgroundWorker: backgroundWorker); }
});
}
string logsContent = "删除客户来电电话号码:" + this.dgvData.SelectedRows[i].Cells[GetPhoneColumn()].Value.ToString();
LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除电话记录, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
}
}
}
}
if (deleteCount > 0)
{
MessageBoxCustom.Show("删除成功!");
this.PublicFunctionRows();
}
}
}
///
/// 呼叫
///
///
///
void btnCall_Click(object sender, EventArgs e)
{
if (this.dgvData.Rows.Count > 0)
{
if (this.dgvData.CurrentRow == null)
{ MessageBoxCustom.Show("请选中你要录音回放的数据!"); return; }
if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.RowIndex >= 0)
{
if (!string.IsNullOrEmpty(this.dgvData.CurrentRow.Cells[GetPhoneColumn()].Value.ToString().Trim()))
{
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.PhoneCall(this.dgvData.CurrentRow.Cells[GetPhoneColumn()].Value.ToString().Trim());
}
else
{ MessageBoxCustom.Show("选择的通话记录电话号码为空!"); }
}
}
}
///
/// 录音回放
///
///
///
void btnPlayer_Click(object sender, EventArgs e)
{
if (this.dgvData.Rows.Count > 0)
{
if (this.dgvData.CurrentRow == null)
{ MessageBoxCustom.Show("请选中你要录音回放的数据!"); return; }
if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.RowIndex >= 0)
{
string StrPath = this.dgvData.CurrentRow.Cells["路径"].Value.ToString().Trim();
if (!string.IsNullOrEmpty(StrPath))
{
string StrNewPath = StrPath.Substring(StrPath.IndexOf("ShareDirectory"), StrPath.Length - StrPath.IndexOf("ShareDirectory"));
LYFZ.Model.Model_Config mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig();
//播放
FrmPlayer set = new FrmPlayer();
set.Path = "\\\\" + mConfig.ServerHostOrIP + "\\" + StrNewPath;
set.ShowDialog();
}
else
{ MessageBoxCustom.Show("选择的通话记录未录音!"); }
}
}
}
///
/// 关闭
///
///
///
void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 窗体大小发生变化
///
///
///
void FrmCustomerCalls_Resize(object sender, EventArgs e)
{
int ControlsWidth = 0;
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
{
if (this.flowLayoutPanel1.Controls[i].Visible)
{ ControlsWidth += this.flowLayoutPanel1.Controls[i].Width; }
}
int PanlHeightCount = 1;
if (this.flowLayoutPanel1.Width < ControlsWidth)
{
PanlHeightCount = ControlsWidth / this.flowLayoutPanel1.Width;
if ((ControlsWidth / this.flowLayoutPanel1.Width) > 0)
{ PanlHeightCount++; }
}
this.flowLayoutPanel1.Height = 33 * PanlHeightCount;
//this.panelEx2.Height = this.flowLayoutPanel1.Height + 71;
}
///
/// 列表添加行时发生
///
///
///
void dgvData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
/*if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells[this.GetDateTimeColumn()].Value.ToString().Trim()))
{
this.dgvData.Rows[e.RowIndex].Cells[this.GetDateTimeColumn()].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells[this.GetDateTimeColumn()].Value, "yyyy-MM-dd HH:mm");
}*/
}
///
/// 分页前数据,便于展开时用来查询订单的子数据
///
DataTable tblMianSelectData = new DataTable();
///
/// 创建行
///
private void PublicFunctionRows()
{
this.ucPager.EventPaging -= UcPagerEx1_EventPaging;
this.ucPager.EventPaging += UcPagerEx1_EventPaging;
this.ucPager.PageCurrent = 1;
this.ucPager.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
this.ucPager.Bind();
}
///
/// 画分页
///
///
///
int UcPagerEx1_EventPaging(UCPager.EventPagingArg e)
{
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
pageData.TableName = GetTableName_Main();
pageData.PageIndex = this.ucPager.PageCurrent;
pageData.PageSize = this.ucPager.PageSize;
pageData.QueryCondition = GetWhereStr();
pageData.OrderStr = "Callw_DateTime DESC";
pageData.OrderType = 1;
this.dgvData.dgvGuidName = GetGuidName();
this.dgvData.dgvUserEmployeeID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
this.dgvData.dgvFixedHideColumn = "ID";
this.dgvData.dgvCurrentColumnOriginalSet = GetFieldName();
pageData.QueryFieldName = this.dgvData.dgvSetColumnName();
if (string.IsNullOrEmpty(pageData.QueryFieldName))
{ pageData.QueryFieldName = this.dgvData.dgvCurrentColumnOriginalSet; }
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
this.tblMianSelectData = pageData.QueryDataTable().Tables[0];
});
try
{
this.dgvData.DataSource(this.tblMianSelectData, strHideField: this.dgvData.dgvFixedHideColumn, ColumnAsName: this.GetASName());
this.dgvData.FillLastColumn(false);
}
catch
{ }
try
{
this.ucPager.TbDataSource = this.tblMianSelectData;
if (StrLoadType == "拨出电话")
{ this.dgvData.Columns["拨出时间"].Width = 110; }
else
{ this.dgvData.Columns["来电时间"].Width = 110; }
this.dgvData.ColumnHeaderMouseDoubleClick -= dgvData_ColumnHeaderMouseDoubleClick;
this.dgvData.ColumnHeaderMouseDoubleClick += dgvData_ColumnHeaderMouseDoubleClick;
}
catch { }
this.dgvData.ClearSelection();
return pageData.TotalCount;
}
///
/// 列表双击事件
///
///
///
void dgvData_ColumnHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
}
///
/// 查询要获取的字段
///
///
private string GetGuidName()
{
CallClientType calltype = (CallClientType)Enum.Parse(typeof(CallClientType), this.cmbtreevClientType.Text.Trim());
switch (calltype)
{
case CallClientType.订单客户: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0035.ToString().Trim();
case CallClientType.老客户: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0036.ToString().Trim();
case CallClientType.意向客户: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0037.ToString().Trim();
case CallClientType.其他客户: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0038.ToString().Trim();
case CallClientType.未知来电: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0039.ToString().Trim();
case CallClientType.员工电话: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0040.ToString().Trim();
default: return LYFZ.EnumPublic.dgvGuidName.E_FormAll_A0041.ToString().Trim();
}
}
///
/// 查询要获取的字段
///
///
private string GetASName()
{
string StrColumn = "";
if (this.StrLoadType == "已接电话")
{ StrColumn = "来电号码, 来电时间,"; }
else if (this.StrLoadType == "拨出电话")
{ StrColumn = "拨出号码, 拨出时间,"; }
else if (this.StrLoadType == "未接电话")
{ StrColumn = "来电号码, 来电时间,"; }
StrColumn += "路径";
CallClientType calltype = (CallClientType)Enum.Parse(typeof(CallClientType), this.cmbtreevClientType.Text.Trim());
switch (calltype)
{
case CallClientType.订单客户: return "ID, 订单号, 客户姓名, 客户电话," + StrColumn;
case CallClientType.老客户: return "ID, 客户姓名, 客户性别," + StrColumn;
case CallClientType.意向客户: return "ID, 客户姓名, 客户性别," + StrColumn;
case CallClientType.其他客户: return "ID, 客户姓名, 客户性别," + StrColumn;
case CallClientType.未知来电: return "ID," + StrColumn;
case CallClientType.员工电话: return "ID, 员工姓名," + StrColumn;
default: return "ID, 订单号, 客户姓名, 客户电话," + StrColumn;
}
}
///
/// 查询要获取的字段
///
///
private string GetFieldName()
{
CallClientType calltype = (CallClientType)Enum.Parse(typeof(CallClientType), this.cmbtreevClientType.Text.Trim());
switch (calltype)
{
case CallClientType.订单客户: return "ID,GP_OrderNumber,Cus_Name,Cus_Telephone,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
case CallClientType.老客户: return "ID,Cus_Name,Cus_Sex_cs,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
case CallClientType.意向客户: return "ID,Cus_Name,Cus_Sex_cs,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
case CallClientType.其他客户: return "ID,Cus_Name,Cus_Sex_cs,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
case CallClientType.未知来电: return "ID,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
case CallClientType.员工电话: return "ID,Cus_Name,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
default: return "ID,GP_OrderNumber,Cus_Name,Cus_Telephone,Callw_Telephone,Callw_DateTime,Callw_SoundRecording";
}
}
///
/// 返回要操作的条件
///
///
private string GetWhereStr()
{
string StrWhere = " 1=1 ";
if (!string.IsNullOrEmpty(this.cmbtreevClientType.Text.Trim()))
{
CallClientType calltype = (CallClientType)Enum.Parse(typeof(CallClientType), this.cmbtreevClientType.Text.Trim());
switch (calltype)
{
case CallClientType.订单客户: StrWhere += " And GP_GroupType = '0'"; break;
case CallClientType.老客户: StrWhere += " And GP_GroupType = '1'"; break;
case CallClientType.意向客户: StrWhere += " And GP_GroupType = '2'"; break;
case CallClientType.其他客户: break;
case CallClientType.未知来电: break;
case CallClientType.员工电话: break;
default: break;
}
}
StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Callw_DateTime", this.dtpDateStart.DateValue, this.dtpDateEnd.DateValue);
if (this.txtQuery.Text.Trim() != "")
{ StrWhere += " And (Cus_Name like '%" + this.txtQuery.Text.Trim() + "%' or Callw_Telephone like '%" + this.txtQuery.Text.Trim() + "%')"; }
StrWhere += " And Callw_Status = '" + this.StrLoadType + "'";
return StrWhere;
}
///
/// 返回要操作的数据表
///
///
private string GetTableName_Main()
{
CallClientType calltype = (CallClientType)Enum.Parse(typeof(CallClientType), this.cmbtreevClientType.Text.Trim());
switch (calltype)
{
case CallClientType.订单客户: return "BView_CallsElves_OrderClientCalls";
case CallClientType.老客户: return "BView_CallsElves_OrderClientCalls";
case CallClientType.意向客户: return "BView_CallsElves_OrderClientCalls";
case CallClientType.其他客户: return "BView_CallsElves_OtherClientCalls";
case CallClientType.未知来电: return "BView_CallsElves_NotClientCalls";
case CallClientType.员工电话: return "BView_CallsElves_UserCalls";
default: return "BView_CallsElves_ClientCalls";
}
}
}
}