📄 protracemanage.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace PSMS
{
/// <summary>
/// 项目跟踪管理类
/// </summary>
public class protraceManage
{
/// <summary>
/// 新增项目跟踪
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void addprotrace(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid, int Popedom, string[] proID)
{
trace t_add = new trace();
t_add.ShowDialog();
if(t_add.tsubmit.BackColor == Color.GreenYellow)
{
if(Popedom == 2)
{
int i=0;
for(i=0; i<proID.Length; i++)
if(t_add.ProjectID.Text == proID[i]) break;
if(i >= proID.Length)
{
MessageBox.Show("The ProjectID is not in your charge!");
return;
}
}
try
{
ada_protrace.InsertCommand.CommandText =
"INSERT INTO Protrace (TraceID,TraceMethod,MainContent,TNote,ProjectID,"+
"ProjectStatus,LinkmanID,TTime" +
" ) VALUES ( '" +
t_add.TraceID.Text + "','" +
t_add.TraceMethod.Text + "','" +
t_add.MainContent.Text + "','" +
t_add.TNote.Text + "','" +
t_add.ProjectID.Text + "','" +
t_add.ProjectStatus.Text + "','" +
t_add.LinkmanID.Text + "','" +
t_add.TTime.Text + "')";
ada_protrace.InsertCommand.ExecuteNonQuery(); //执行Insert语句
dset.Clear();
ada_protrace.Fill(dset);
dgrid.DataSource=dset.Tables["Protrace"];
if(Popedom == 2) this.searchprotrace2(ada_protrace, dset, dgrid, proID);
}
catch(System.Exception ie)
{
MessageBox.Show(ie.Message);
}
}
}
/// <summary>
/// 查询项目跟踪
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void searchprotrace(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid)
{
trace t_search = new trace();
t_search.MainContent.Enabled = false;
t_search.TNote.Enabled = false;
t_search.TTime.Enabled = false;
t_search.ShowDialog();
if(t_search.tsubmit.BackColor == Color.GreenYellow)
{
try
{
if(t_search.TraceID.Text == "" && t_search.TraceMethod.Text == "" && t_search.ProjectID.Text
== "" && t_search.ProjectStatus.Text == "" && t_search.LinkmanID.Text == "")
ada_protrace.SelectCommand.CommandText = "SELECT * FROM Protrace";
else
{
int i = 0;
String cmdstr = "SELECT * FROM Protrace WHERE ";
if(t_search.TraceID.Text != "")
{
i++;
cmdstr += "TraceID='"+t_search.TraceID.Text +"'";
}
if(t_search.TraceMethod.Text != "")
{
if( i>0 ) cmdstr += " AND ";
i++;
cmdstr += "TraceMethod='"+t_search.TraceMethod.Text +"'";
}
if(t_search.ProjectID.Text != "")
{
if( i>0 ) cmdstr += " AND ";
i++;
cmdstr += "ProjectID='"+t_search.ProjectID.Text +"'";
}
if(t_search.ProjectStatus.Text != "")
{
if( i>0 ) cmdstr += " AND ";
i++;
cmdstr += "ProjectStatus='"+t_search.ProjectStatus.Text +"'";
}
if(t_search.LinkmanID.Text != "")
{
if( i>0 ) cmdstr += " AND ";
i++;
cmdstr += "LinkmanID='"+t_search.LinkmanID.Text +"'";
}
ada_protrace.SelectCommand.CommandText = cmdstr;
}
ada_protrace.SelectCommand.ExecuteNonQuery(); //执行Insert语句
dset.Clear();
ada_protrace.Fill(dset);
dgrid.DataSource=dset.Tables["Protrace"];
}
catch(System.Exception ie)
{
MessageBox.Show(ie.Message);
}
}
}
/// <summary>
/// 查询项目跟踪子函数(供销售经理用)
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void searchprotrace2(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid, string[] proID)
{
int i=0;
int j=0;
try
{
while(dset.Tables["Protrace"].Rows[i]["TraceID"] != null)
{
for(j=0; j<proID.Length; j++)
{
if(""+dset.Tables["Protrace"].Rows[i]["ProjectID"] == proID[j]) break;
}
if(j >= proID.Length) dset.Tables["Protrace"].Rows[i].Delete();
i++;
}
}
catch(System.IndexOutOfRangeException){}
}
/// <summary>
/// 删除项目跟踪
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void deleteprotrace(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid)
{
try
{
int i = dgrid.CurrentCell.RowNumber;
int id = (int)dset.Tables["Protrace"].Rows[i]["TraceID"];
DialogResult Result;
Result = MessageBox.Show("确定要删除ID号为"+id+"的项目跟踪吗?",
"警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2);
if(Result == DialogResult.Yes)
{
ada_protrace.DeleteCommand.CommandText="DELETE FROM Protrace WHERE TraceID = '"+id+"'";
ada_protrace.DeleteCommand.ExecuteNonQuery();
dset.Clear();
ada_protrace.Fill(dset);
dgrid.DataSource=dset.Tables["Protrace"];
}
}
catch(System.Exception ie)
{
MessageBox.Show(ie.Message);
}
}
/// <summary>
/// 修改项目跟踪
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void modifyprotrace(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid)
{
int i = dgrid.CurrentCell.RowNumber;
trace t_modify = new trace();
t_modify.TraceID.Text = ""+(int)dset.Tables["Protrace"].Rows[i]["TraceID"];
t_modify.TraceID.Enabled = false;
t_modify.treset.Enabled = false;
t_modify.TraceMethod.Text = ""+dset.Tables["Protrace"].Rows[i]["TraceMethod"];
t_modify.MainContent.Text = ""+dset.Tables["Protrace"].Rows[i]["MainContent"];
t_modify.TNote.Text = ""+dset.Tables["Protrace"].Rows[i]["TNote"];
t_modify.ProjectID.Text = ""+dset.Tables["Protrace"].Rows[i]["ProjectID"];
t_modify.ProjectStatus.Text = ""+dset.Tables["Protrace"].Rows[i]["ProjectStatus"];
t_modify.LinkmanID.Text = ""+dset.Tables["Protrace"].Rows[i]["LinkmanID"];
t_modify.TTime.Text = ""+dset.Tables["Protrace"].Rows[i]["TTime"];
t_modify.ShowDialog();
if(t_modify.tsubmit.BackColor == Color.GreenYellow)
{
try
{
ada_protrace.UpdateCommand.CommandText = "UPDATE Protrace SET " +
"TraceMethod = '"+t_modify.TraceMethod.Text +
"',MainContent = '"+t_modify.MainContent.Text +
"',TNote = '"+t_modify.TNote.Text +
"',ProjectID = '"+t_modify.ProjectID.Text +
"',ProjectStatus = '"+t_modify.ProjectStatus.Text +
"',LinkmanID = '"+t_modify.LinkmanID.Text +
"',TTime = '"+t_modify.TTime.Text +
"' WHERE TraceID = "+t_modify.TraceID.Text;
ada_protrace.UpdateCommand.ExecuteNonQuery();
dset.Clear();
ada_protrace.Fill(dset);
dgrid.DataSource=dset.Tables["Protrace"];
}
catch(System.Exception ie)
{
MessageBox.Show(ie.Message);
}
}
}
/// <summary>
/// 屏蔽项目
/// </summary>
/// <param name="ada_protrace"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
public void shieldprotrace(System.Data.OleDb.OleDbDataAdapter ada_protrace,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid)
{
int i = 0;
int count = 0;
string[] shshID = new string [50000];
DateTime today = new DateTime ();
today = DateTime.Now;
try
{
while(dset.Tables["Project"].Rows[i]["ProjectID"] != null)
{
if((DateTime)dset.Tables["Project"].Rows[i]["SignTime"] > today ||
(DateTime)dset.Tables["Project"].Rows[i]["OverTime"] > today)
shshID[count++] = ""+ dset.Tables["Project"].Rows[i]["ProjectID"];
i++;
}
}
catch(System.IndexOutOfRangeException)
{
i = 0;
try
{
while(dset.Tables["Protrace"].Rows[i]["TraceID"] != null)
{
for(int j=0; j<count; j++)
{
if( ""+dset.Tables["Protrace"].Rows[i]["ProjectID"] == shshID[j] )
{
dset.Tables["Protrace"].Rows[i].Delete();
j = count;
}
}
i++;
}
}
catch(System.IndexOutOfRangeException)
{
dgrid.DataSource = dset.Tables["Protrace"];
}
}
}
/// <summary>
/// 部门经理统计项目跟踪记录
/// </summary>
/// <param name="ada_depmanstat"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
/// <param name="starttime"></param>
/// <param name="endtime"></param>
public void depstatprotrace(System.Data.OleDb.OleDbDataAdapter ada_depmanstat,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid, string starttime,string endtime)
{
string[] ManagerID = new string [50000]; //销售经理ID
int[] ClientNum = new int [50000]; //对应的客户数
int[] LinkTimes = new int [50000]; //对应的联系次数
int[] SignProjects = new int [50000]; //对应的签约(定单)数
for(int tt=0; tt<50000; tt++)
{
ClientNum[tt] = 0;
LinkTimes[tt] = 0;
SignProjects[tt] = 0;
}
int count = 0; //销售经理人数
int i=0, ii=0, j;
bool cancntcnum; //可以再数客户个数么(相同客户(项目)只算一次)
DateTime start = DateTime.Parse(starttime);
DateTime end = DateTime.Parse(endtime);
try
{
while(dset.Tables["Project"].Rows[i]["ProjectID"] != null)
{
for( j=0; j<count; j++ )
{
if( ""+dset.Tables["Project"].Rows[i]["ManagerID"] == ManagerID[j])
{
break;
}
}
if(j < count) //已存在此经理ID
{
if((DateTime)dset.Tables["Project"].Rows[i]["SignTime"] >= start &&
(DateTime)dset.Tables["Project"].Rows[i]["SignTime"] <= end)
{
SignProjects[j] ++; //签约项目++
//MessageBox.Show("" + SignProjects[j] );
}
string ProjectID = ""+dset.Tables["Project"].Rows[i]["ProjectID"];
try
{
cancntcnum = true;
ii = 0; //扫描项目跟踪表所用下标
while(dset.Tables["Protrace"].Rows[ii]["TraceID"] != null)
{ //找到此项目ID对应的项目跟踪记录
if(""+dset.Tables["Protrace"].Rows[ii]["ProjectID"] == ProjectID)
{
DateTime trace = (DateTime)(dset.Tables["Protrace"].Rows[ii]["TTime"]);
if(trace >= start && trace <= end) //如果记录时间是合符的
{
LinkTimes[j]++; //联系次数++
//MessageBox.Show("" + LinkTimes[j] );
if(cancntcnum)
{
ClientNum[j]++;
cancntcnum = false;
//MessageBox.Show("" + ClientNum[j] );
}
}
}
ii++;
}
}catch(System.IndexOutOfRangeException)
{
//MessageBox.Show(""+ ii );//+"**"+ count);
}
}
else
{ //加入新经理ID
ManagerID[count++] = ""+dset.Tables["Project"].Rows[i]["ManagerID"];
//MessageBox.Show(ManagerID[count-1]);
i--; //在本行再运行一次
}
i++;
}
}
catch(System.IndexOutOfRangeException)
{
dset.Clear();
ada_depmanstat.Fill(dset);
for(i=0; i<count; i++)
{
DataRow row = dset.Tables["DepManStat"].NewRow();
row["ManagerID"] = ManagerID[i];
row["ClientNum"] = ClientNum[i];
row["LinkTimes"] = LinkTimes[i];
row["SignProjects"] = SignProjects[i];
dset.Tables["DepManStat"].Rows.Add(row);
}
dgrid.DataSource = dset.Tables["DepManStat"];
}
}
/// <summary>
/// 销售经理统计项目跟踪记录
/// </summary>
/// <param name="ada_salmanstat"></param>
/// <param name="dset"></param>
/// <param name="dgrid"></param>
/// <param name="starttime"></param>
/// <param name="endtime"></param>
/// <param name="ManagerID"></param>
public void salstatprotrace(System.Data.OleDb.OleDbDataAdapter ada_salmanstat,
System.Data.DataSet dset, System.Windows.Forms.DataGrid dgrid, string starttime,string endtime, string ManagerID)
{
string[] ProjectID = new string [50000];
int[] LinkTimes = new int [50000];
bool[] Signed = new bool [50000];
int Signcount = 0;
int i=0, count=0;
for(int tt=0; tt<50000; tt++)
{
LinkTimes[tt] = 0;
Signed[tt] = false;
}
DateTime start = DateTime.Parse(starttime);
DateTime end = DateTime.Parse(endtime);
try
{
while(dset.Tables["Project"].Rows[i]["ProjectID"] != null)
{
if(""+dset.Tables["Project"].Rows[i]["ManagerID"] == ManagerID)
{
ProjectID[count++] = ""+dset.Tables["Project"].Rows[i]["ProjectID"];
if((DateTime)dset.Tables["Project"].Rows[i]["SignTime"] >= start &&
(DateTime)dset.Tables["Project"].Rows[i]["SignTime"] <= end)
{
Signed[count-1] = true;
Signcount++;
}
try
{
int ii=0;
while(dset.Tables["Protrace"].Rows[ii]["TraceID"] != null)
{
if(""+dset.Tables["Protrace"].Rows[ii]["ProjectID"] == ProjectID[count-1])
LinkTimes[count-1]++;
ii++;
}
}
catch(System.IndexOutOfRangeException){}
}
i++;
}
}
catch(System.IndexOutOfRangeException)
{
dset.Clear();
ada_salmanstat.Fill(dset);
for(i=0; i<count; i++)
{
DataRow row = dset.Tables["SalManStat"].NewRow();
row["ProjectID"] = ProjectID[i];
row["LinkTimes"] = LinkTimes[i];
row["Signed"] = Signed[i];
dset.Tables["SalManStat"].Rows.Add(row);
}
dgrid.DataSource = dset.Tables["SalManStat"];
MessageBox.Show("在 "+starttime+" ~ "+endtime+" 期间一共签约 "+Signcount+" 个项目");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -