private async void DownLoad_Click(object sender, EventArgs e) //下载配额表 { if(this.CategoryId.SelectedItem == null) { MessageBox.Show("请选择希望下载的会签单类别信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Search search = new Search { Year = int.Parse(this.IdYear.Text), CategoryId = int.Parse(((ComboboxItem)this.CategoryId.SelectedItem).Value), }; SaveFileDialog sfd = new SaveFileDialog(); //设置文件类型 sfd.Filter = "Microsoft Excel(*.xls) | *.xls"; // 设置默认文件类型显示顺序 //sfd.FilterIndex = 1; //保存对话框是否记忆上次打开的目录 sfd.RestoreDirectory = true; sfd.FileName = this.CategoryId.Text + "计划费用分配表"; if (sfd.ShowDialog() == DialogResult.OK) { MainWindow mw = (MainWindow)this.MdiParent; cmd.ShowOpaqueLayer(this.ReportAnalysis, 125, true, true, "正在下载中,请稍候"); mw.treeView1.Enabled = false; string filepath = sfd.FileName.ToString(); await _sc.DownloadRegularload(search, filepath); cmd.HideOpaqueLayer(); MessageBox.Show("下载完成!"); mw.treeView1.Enabled = true; } this.UpLoad.Visible = true; }
private async void UpLoad_Click(object sender, EventArgs e) //上传配额表 { Search search = new Search { Year = int.Parse(this.IdYear.Text), CategoryId = int.Parse(((ComboboxItem)this.CategoryId.SelectedItem).Value), }; OpenFileDialog ofd = new OpenFileDialog(); //设置文件类型 ofd.Filter = "Microsoft Excel(*.xls) | *.xls"; // 设置默认文件类型显示顺序 //sfd.FilterIndex = 1; //保存对话框是否记忆上次打开的目录 ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { MainWindow mw = (MainWindow)this.MdiParent; cmd.ShowOpaqueLayer(this.ReportAnalysis, 125, true, true, "正在上传中,请稍候"); mw.treeView1.Enabled = false; string filepath = ofd.FileName.ToString(); var result = await _sc.UploadRegularload(search, filepath); cmd.HideOpaqueLayer(); mw.treeView1.Enabled = true; if (result) { MessageBox.Show("上传成功!"); } else { MessageBox.Show("上传失败, 请重新上传!"); } } this.UpLoad.Visible = false; }
/// <summary> /// 条件查询已办列表 /// </summary> /// <param name="s"></param> /// <returns></returns> public List<SHDJContract> SearchSignedHDJConstract(Search s) { //return Task.Factory.StartNew(() => { try { SocketMessage sm = new SocketMessage(Request.SEARCH_SIGNED_HDJCONTRACT_REQUEST, s); ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package)); recLength = ClientSocket.Receive(recivebuffer); string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength); string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR); if (Msg[0] == Response.SEARCH_SIGNED_HDJCONTRACT_SUCCESS.ToString()) { List<SHDJContract> list = new List<SHDJContract>(); list = JsonConvert.DeserializeObject<List<SHDJContract>>(Msg[2]); return list; } else { Logging.AddLog("条件查询已通过方案列表失败!"); return null; } } catch { Logging.AddLog("条件查询已通过方案列表失败(服务器连接中断)!"); return null; } //}); } }
/// <summary> /// /// </summary> /// <param name="isFlush"></param> private void BindContractItem(bool isFlush) { if (UserHelper.ContractItemList == null || isFlush == true) { string categoryName = this.Column1Info.Text.ToString(); string projectName = this.Column2Info.Text.ToString(); Search search = new Search { CategoryName = categoryName, ProjectName = projectName, }; List<ContractItem> list = _sc.QueryContractItemByName(search); UserHelper.ContractItemList = list; } }
private void button3_Click(object sender, EventArgs e) { string ContractId = this.ContractID.Text; string projectName = this.ProgramName.Text; DateTime start = this.AgreeStartDate.Value; DateTime end = this.AgreeEndDate.Value; if (start > end) { MessageBox.Show("开始日期必须小于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (this.Downloadable.Checked == true) { Search s = new Search(); s.EmployeeId = UserHelper.UserInfo.Id; s.ConId = ContractId; s.ProjectName = projectName; s.DateBegin = start; s.DateEnd = end; s.Downloadable = 1; List<SHDJContract> list = new List<SHDJContract>(); list = _sc.SearchSignedHDJConstract(s); this.DoneListView.AutoGenerateColumns = false; this.DoneListView.DataSource = list; DataGridViewLinkColumn download = new DataGridViewLinkColumn(); download.Text = "下载签单附件"; download.Name = "LinkDownLoad"; download.HeaderText = "下载签单附件"; download.Width = 150; download.UseColumnTextForLinkValue = true; this.DoneListView.Columns.Add(download); } else { Search s = new Search(); s.EmployeeId = UserHelper.UserInfo.Id; s.ConId = ContractId; s.ProjectName = projectName; s.DateBegin = start; s.DateEnd = end; s.Downloadable = 0; List<SHDJContract> list = new List<SHDJContract>(); list = _sc.SearchSignedHDJConstract(s); this.DoneListView.AutoGenerateColumns = false; this.DoneListView.DataSource = list; } } }
private void button3_Click(object sender, EventArgs e) { string ContractId = this.ContractID.Text; string projectName = this.ProgramName.Text; DateTime start = this.AgreeStartDate.Value; DateTime end = this.AgreeEndDate.Value; if (start > end) { MessageBox.Show("开始日期必须小于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Search s = new Search(); s.EmployeeId = UserHelper.UserInfo.Id; s.ConId = ContractId; s.ProjectName = projectName; s.DateBegin = start; s.DateEnd = end; List<SHDJContract> list = new List<SHDJContract>(); list = _sc.SearchAgreeHDJConstract(s); this.SignAgree.DataSource = list; } }
private void BindDepartmentYearCategoryCount() { if (this.IdDepartShortCall.SelectedValue == null || this.IdCategory.SelectedValue == null || (ComboboxItem)this.IdYear.SelectedItem == null || (ComboboxItem)this.IdYear.SelectedItem == null) { //MessageBox.Show("请将编号填写完整!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //MessageBox.Show(this.IdDepartShortCall.Text); Search search = new Search { SDepartmentShortlCall = this.IdDepartShortCall.Text, CategoryShortCall = this.IdCategory.Text, Year = int.Parse(this.IdYear.Text), }; int count = _sc.GetDepartmentCategoryYearContractCount(search); // modigy by gatieme @2016-02-26 // 编号应该是2位,因此最后两位都是编号的信息 if (count + 1 >= 100) // 编号超出3位 { if (UserHelper.UserInfo.CanStatistic == 0) { MessageBox.Show("系统中编号限制为两位, 当前编号的会签单数目已达上限\n如有需要, 请找管理员\n当然您也可以换个部门审批", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.IdNo.Text = ""; return; } } else if (count + 1 < 10) { this.IdNo.Text = "0" + (count + 1).ToString(); } else { this.IdNo.Text = (count + 1).ToString(); } }
private void BindContractCategoryCount(bool isFlush) { if (UserHelper.ContractProjectList == null || isFlush == true) { //MessageBox.Show(this.IdDepartShortCall.Text); Search search = new Search { CategoryShortCall = this.IdDepartShortCall.Text, Year = int.Parse(this.IdYear.Text), }; int count = _sc.GetCategoryYearContractCount(search); this.IdNo.Text = count.ToString(); } }
private void Column4Info_TextChanged(object sender, EventArgs e) { if (this.Column4Info.Text.Trim() == "") { this.Column5Info.Text = ""; return; } //MessageBox.Show(this.Column4Info.Text.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); /// modify by gatieme @2016-04-05 21:16 /// 需求变动 /// 会签单中累计申请额度, /// 从原来 当前部门当前小项目Project的累计申请额度 /// -=> /// 变更为 当前部门当前大类别Category的累计申请额度 try { double currExpense = double.Parse(this.Column4Info.Text.ToString()); Search search = new Search { SDepartmentShortlCall = this.IdDepartShortCall.Text, //ProjectId = Convert.ToInt32(this.xmName.SelectedValue), CategoryShortCall = this.IdCategory.Text, Year = int.Parse(this.IdYear.Text), }; //double totlaExpense = _sc.StatisticDepartmentYearProjectExpense(search); double totlaExpense = _sc.StatisticDepartmentYearCategoryExpense(search); this.Column5Info.Text = (totlaExpense + currExpense).ToString(); } catch (Exception ex) { throw; } }
public double StatisticDepartmentYearCategoryExpense(Search search) { ContractWorkload workload = null; try { SocketMessage sm = new SocketMessage(Request.STATISTIC_DEP_YEAR_CATEGORY_REQUEST, search); //scoket发送请求信息 ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package)); //scoket接收请求信息 recLength = ClientSocket.Receive(recivebuffer); string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength); string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR); if (Msg[0] == Response.STATISTIC_DEP_YEAR_CATEGORY_SUCCESS.ToString()) { workload = JsonConvert.DeserializeObject<ContractWorkload>(Msg[2]); Logging.AddLog("获取当前部门" + search.SDepartmentShortlCall.ToString() + search.Year.ToString() + search.CategoryId.ToString() + "成功!"); } else { Logging.AddLog("获取当前部门" + search.SDepartmentShortlCall.ToString() + search.Year.ToString() + search.CategoryId.ToString() + "失败!"); } } catch { Logging.AddLog("获取总计申请额度(服务器连接中断)!"); return 0; } return workload.Expense; }
//GET_DEP_CATE_YEAR_CON_COUNT_REQUEST public int GetDepartmentCategoryYearContractCount(Search search) { int count = -1; try { SocketMessage sm = new SocketMessage(Request.GET_DEP_CATE_YEAR_CON_COUNT_REQUEST, search); ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package)); recLength = ClientSocket.Receive(recivebuffer); string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength); string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR); if (Msg[0] == Response.GET_DEP_CATE_YEAR_CON_COUNT_SUCCESS.ToString()) { count = JsonConvert.DeserializeObject<int>(Msg[2]); return count; } else { Logging.AddLog("获取当年已经签署的CATEGORY的会签单数目失败"); return -1; } } catch { Logging.AddLog("项目名称查询失败(服务器连接中断)!"); return -1; } }
public List<ContractItem> QueryContractItemByName(Search search) { List<ContractItem> items = new List<ContractItem>(); try { SocketMessage sm = new SocketMessage(Request.QUERY_PROJECT_ITEM_BY_NAME_REQUEST, search); ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package)); recLength = ClientSocket.Receive(recivebuffer); string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength); string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR); if (Msg[0] == Response.QUERY_PROJECT_ITEM_BY_NAME_SUCCESS.ToString()) { items = JsonConvert.DeserializeObject<List<ContractItem>>(Msg[2]); return items; } else { Logging.AddLog("子项目名称查询失败!"); return null; } } catch { Logging.AddLog("子项目名称查询失败(服务器连接中断)!"); return null; } }
/// <summary> /// 下载统计表 /// </summary> /// <param name="search"></param> /// <param name="filepath"></param> /// <returns></returns> public async Task DownloadStatistic(Search search, string filepath) { await Task.Factory.StartNew(() => { try { SocketMessage sm = new SocketMessage(Request.DOWNLOAD_STATISTIC_REQUEST, search); Socket download = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); download.Connect(new IPEndPoint(IP, 6060)); download.Send(Encoding.UTF8.GetBytes(sm.Package + "~")); FileStream fs = new FileStream(filepath, FileMode.Create); int len = 0; int size = 0; byte[] buffer = new byte[1024 * 1024]; //从终端不停的接受数据,然后写入文件里面,只到接受到的数据为0为止,则中断连接 while ((size = download.Receive(buffer, 0, buffer.Length, SocketFlags.None)) > 0) { fs.Write(buffer, 0, size); len += size; } fs.Flush(); fs.Close(); download.Close(); } catch { } }); }
/// <summary> /// 上传计划配额表 /// </summary> /// <param name="search"></param> /// <param name="filepath"></param> /// <returns></returns> public async Task<bool> UploadRegularload(Search search, string filepath) { return await Task.Factory.StartNew(() => { try { /*FileInfo fileinfo = new FileInfo(filepath); FileStream filestream = fileinfo.OpenRead(); //包的大小 int packetSize = 100000; //包的数量 int packetCount = (int)(filestream.Length / ((long)packetSize)); //最后一个包的大小 int LastDataPacket = (int)(filestream.Length - ((long)(packetSize * packetCount))); SocketMessage sm = new SocketMessage(Request.UPLOAD_REGULARLOAD_REQUEST, search); Socket upload = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); upload.Connect(new IPEndPoint(IP, 6060)); upload.Send(Encoding.UTF8.GetBytes((sm.Package + "~").PadRight(300, '0'))); byte[] data = new byte[packetSize]; for (int i = 0; i < packetCount; i++) { filestream.Read(data, 0, data.Length); SendVarData(upload, data); } if (LastDataPacket != 0) { data = new byte[LastDataPacket]; filestream.Read(data, 0, data.Length); SendVarData(upload, data); }*/ SocketMessage sm = new SocketMessage(Request.UPLOAD_REGULARLOAD_REQUEST, search); Socket upload = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); upload.Connect(new IPEndPoint(IP, 6060)); FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Read); byte[] fssize = new byte[fs.Length]; BinaryReader reader = new BinaryReader(fs); reader.Read(fssize, 0, fssize.Length - 1); upload.Send(Encoding.UTF8.GetBytes((sm.Package + "~").PadRight(300, '0'))); upload.Send(fssize); fs.Close(); upload.Shutdown(System.Net.Sockets.SocketShutdown.Send); upload.Close(); return true; } catch { return false; } }); }