/// </summary> private void SaveWork() { string content = null; string status = ""; string processor = ""; string compor = ""; string estimate = ""; ProcessBarStart(); //loadpc.Visible = true; content = ContentRTB.Text.Replace("\'", "\\\'"); estimate = estimateDate.Text; btnsave.Enabled = false; status = cbstatus.SelectedValue.ToString(); processor = cbprocessor.SelectedValue.ToString(); compor = txtcompor.Text.ToString(); string filename = txtfilename.Text; string title = txttitle.Text; string hour = txthour.Text.ToString(); if (hour.Length == 0) { hour = "0"; } string remark = txtremark.Text; string id = txtid.Text; string relor = txtrelor.Text; if (string.IsNullOrEmpty(id)) { filename = NewFileName(filename, relor, title, remark); } ContentRTB.SaveFile(FilePath + "\\" + filename + ".rtf", RichTextBoxStreamType.RichText); txtfilename.Text = filename; //上传文件到服务器 try { FileUploadItem receive = new FileUploadItem(); receive.Address = UpFileAdrees; receive.FileNamePath = FilePath + "\\" + filename + ".rtf"; receive.SaveName = filename; FileUploadUtilEvent fileUploadUtilEvent = new FileUploadUtilEvent(receive); fileUploadUtilEvent.OnProgressChanged += new EventHandler <ProgressChangedEventArgs>((object sender, ProgressChangedEventArgs e) => { FileUploadUtilChange message = (FileUploadUtilChange)e.UserState; lbtip.Text = "已用时:" + message.Second.ToString("F2") + "秒"; if (message.Second > 0.001) { lbtip.Text += " 平均速度:" + (message.Offset / 1024 / message.Second).ToString("0.00") + "KB/秒"; } else { lbtip.Text += " 正在连接…"; } lbtip.Text += "已上传:" + (message.Offset * 100.0 / message.Length).ToString("F2") + "%"; lbtip.Text += (message.Offset / 1048576.0).ToString("F2") + "M/" + (message.FileLength / 1048576.0).ToString("F2") + "M"; }); fileUploadUtilEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object sender, RunWorkerCompletedEventArgs e) => { int count = (int)e.Result; if (count == 0) { ShowMessageDialog("上传文件服务器失败!,文件只保存在本地"); } FileInfo fi = new FileInfo(FilePath + "\\" + filename + ".rtf"); DateTime dt = fi.LastWriteTime; string sql = " "; if (string.IsNullOrEmpty(id)) { sql += @"insert pasn(title,BizDate,CreateDate,Creator,relor,Remark,Status,Content,filename,lastwritetime,processor,compor,hour,estimate) values('" + title + "',now(),now(),'" + Login.Name + "','" + relor + "','" + remark + "','" + status + "','" + content + "','" + filename + "','" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "','" + processor + "','" + compor + "','" + hour + "','" + estimate + "'); set @id=@@IDENTITY; "; } else { sql += @"update pasn set relor='" + relor + "',estimate='" + estimate + "',modiDate=now(),modior='" + Login.Name + "', title='" + title + "',Remark='" + remark + "',Status='" + status + "'," + (status == "1" ? "compDate=now()," : "") + "Content='" + content + "',lastwritetime='" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "' ,processor='" + processor + "',compor='" + compor + "',hour='" + hour + "' where id=" + id + "; "; sql += "set @id=" + id + ";"; } sql += "select * from pasn where id=@id;"; try { //新增单据的时候,列表刷新一下。但少了一个选中怎么办 SQLUtilEvent sQLUtilSaveEvent = new SQLUtilEvent(sql); sQLUtilSaveEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object sendObj, RunWorkerCompletedEventArgs arg) => { DataSet dataSave = (DataSet)arg.Result; txtid.Text = dataSave.Tables[0].Rows[0]["id"].ToString(); lbtip.Text = "save success"; //前端新增一行 if (string.IsNullOrEmpty(id)) { //新增单据的时候,列表刷新一下。但少了一个选中怎么办 SQLUtilEvent sQLUtilEvent = new SQLUtilEvent(GetPlanListData()); sQLUtilEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object senders, RunWorkerCompletedEventArgs es) => { DataSet dataSet = (DataSet)es.Result; CreateListView(dataSet.Tables[0]); listStatus.Text = "总记录数:" + dataSet.Tables[0].Rows.Count; foreach (Record dr in Records) { if (dr.Id == int.Parse(txtid.Text)) { uiDataGridView1.ClearSelection(); uiDataGridView1.CurrentCell = uiDataGridView1.Rows[Records.IndexOf(dr)].Cells[0]; uiDataGridView1.SelectedIndex = Records.IndexOf(dr); } } //for (int i = 0; i < planlist.Items.Count; i++) //{ // DataRow dr = (DataRow)planlist.Items[i].Tag; // if (dr["id"].ToString() == txtid.Text) // { // planlist.Items[i].Selected = true;//选中 // planlist.Items[i].Focused = true; //焦点 // planlist.Items[i].EnsureVisible();//滚动显示 // } //} //loadpc.Visible = false; ProcessBarStop(); btnsearch.Enabled = true; //前端新增一行end btnsave.Enabled = true; //ShowMessageDialog("save success"); }); sQLUtilEvent.Run("sql"); } else { //DataRow item = (DataRow)(planlist.SelectedItems[0]).Tag; //planlist.SelectedItems[0].Tag = dataSave.Tables[0].Rows[0]; //foreach (ListColumn l in PlanListColumn) //{ // planlist.SelectedItems[0].SubItems[PlanListColumn.IndexOf(l)].Text = dataSave.Tables[0].Rows[0][l.Key].ToString(); //} Record data = new Record(); DataRow dr = dataSave.Tables[0].Rows[0]; data.BizDate = strToDateTime(dr["BizDate"].ToString()); data.Title = dr["title"].ToString(); data.Relor = dr["relor"].ToString(); data.Estimate = strToDateTime(dr["estimate"].ToString()); data.Status = dr["Status"].ToString(); data.Content = dr["Content"].ToString(); data.Compor = dr["compor"].ToString(); data.CompDate = strToDateTime(dr["compDate"].ToString()); data.Modior = dr["modior"].ToString(); data.Modidate = strToDateTime(dr["modidate"].ToString()); data.Filename = dr["filename"].ToString(); data.Creator = dr["creator"].ToString(); data.Remark = dr["remark"].ToString(); data.Id = int.Parse(dr["id"].ToString()); data.Hour = decimal.Parse(dr["hour"].ToString()); data.Processor = dr["processor"].ToString(); Records.Add(data); for (int j = 0; j < uiDataGridView1.Columns.Count; j++) { string colName = uiDataGridView1.Columns[j].DataPropertyName; uiDataGridView1.SelectedRows[0].Cells[colName].Value = data.GetType().GetProperty(colName, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance).GetValue(data, null); } //前端新增一行end //this.loadpc.Visible = false; ProcessBarStop(); btnsave.Enabled = true; //ShowMessageDialog("save success"); } }); sQLUtilSaveEvent.Run("sql"); } catch (Exception ex) { //loadpc.Visible = false; ProcessBarStop(); btnsave.Enabled = true; lbtip.Text = "erroe"; ShowMessageDialog(ex.GetBaseException().ToString()); } }); fileUploadUtilEvent.Run(); } catch (Exception ex) { ShowMessageDialog(ex.GetBaseException().ToString()); } //上传文件到服务器end }
/// <summary> /// 保存 /// </summary> private void SaveWork() { string content = null; string status = ""; string processor = ""; string compor = ""; string estimate = ""; loadpc.Visible = true; content = ContentRTB.Text.Replace("\'", "\\\'"); estimate = estimateDate.Text; btnsave.Enabled = false; status = cbstatus.SelectedValue.ToString(); processor = cbprocessor.SelectedValue.ToString(); compor = txtcompor.Text.ToString(); string filename = txtfilename.Text; string title = txttitle.Text; string hour = txthour.Text.ToString(); if (hour.Length == 0) { hour = "0"; } string remark = txtremark.Text; string id = txtid.Text; string relor = txtrelor.Text; if (string.IsNullOrEmpty(id)) { filename = NewFileName(filename, relor, title, remark); } ContentRTB.SaveFile(FilePath + "\\" + filename + ".rtf", RichTextBoxStreamType.RichText); txtfilename.Text = filename; //上传文件到服务器 try { FileUploadItem receive = new FileUploadItem(); receive.Address = UpFileAdrees; receive.FileNamePath = FilePath + "\\" + filename + ".rtf"; receive.SaveName = filename; FileUploadUtilEvent fileUploadUtilEvent = new FileUploadUtilEvent(receive); fileUploadUtilEvent.OnProgressChanged += new EventHandler <ProgressChangedEventArgs>((object sender, ProgressChangedEventArgs e) => { FileUploadUtilChange message = (FileUploadUtilChange)e.UserState; lbtip.Text = "已用时:" + message.Second.ToString("F2") + "秒"; if (message.Second > 0.001) { lbtip.Text += " 平均速度:" + (message.Offset / 1024 / message.Second).ToString("0.00") + "KB/秒"; } else { lbtip.Text += " 正在连接…"; } lbtip.Text += "已上传:" + (message.Offset * 100.0 / message.Length).ToString("F2") + "%"; lbtip.Text += (message.Offset / 1048576.0).ToString("F2") + "M/" + (message.FileLength / 1048576.0).ToString("F2") + "M"; }); fileUploadUtilEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object sender, RunWorkerCompletedEventArgs e) => { int count = (int)e.Result; if (count == 0) { MessageBoxEx.Show(this, "上传文件服务器失败!,文件只保存在本地"); } FileInfo fi = new FileInfo(FilePath + "\\" + filename + ".rtf"); DateTime dt = fi.LastWriteTime; string sql = " "; if (string.IsNullOrEmpty(id)) { sql += @"insert pasn(title,BizDate,CreateDate,Creator,relor,Remark,Status,Content,filename,lastwritetime,processor,compor,hour,estimate) values('" + title + "',now(),now(),'" + name + "','" + relor + "','" + remark + "','" + status + "','" + content + "','" + filename + "','" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "','" + processor + "','" + compor + "','" + hour + "','" + estimate + "'); set @id=@@IDENTITY; "; } else { sql += @"update pasn set relor='" + relor + "',estimate='" + estimate + "',modiDate=now(),modior='" + name + "', title='" + title + "',Remark='" + remark + "',Status='" + status + "'," + (status == "1" ? "compDate=now()," : "") + "Content='" + content + "',lastwritetime='" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "' ,processor='" + processor + "',compor='" + compor + "',hour='" + hour + "' where id=" + id + "; "; sql += "set @id=" + id + ";"; } sql += "select * from pasn where id=@id;"; try { //新增单据的时候,列表刷新一下。但少了一个选中怎么办 SQLUtilEvent sQLUtilSaveEvent = new SQLUtilEvent(sql); sQLUtilSaveEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object sendObj, RunWorkerCompletedEventArgs arg) => { DataSet dataSave = (DataSet)arg.Result; txtid.Text = dataSave.Tables[0].Rows[0]["id"].ToString(); //前端新增一行 if (string.IsNullOrEmpty(id)) { //新增单据的时候,列表刷新一下。但少了一个选中怎么办 SQLUtilEvent sQLUtilEvent = new SQLUtilEvent(GetPlanListData()); sQLUtilEvent.OnRunWorkerCompleted += new EventHandler <RunWorkerCompletedEventArgs>((object senders, RunWorkerCompletedEventArgs es) => { DataSet dataSet = (DataSet)es.Result; CreateListView(dataSet.Tables[0]); listStatus.Text = "总记录数:" + dataSet.Tables[0].Rows.Count; for (int i = 0; i < planlist.Items.Count; i++) { DataRow dr = (DataRow)planlist.Items[i].Tag; if (dr["id"].ToString() == txtid.Text) { planlist.Items[i].Selected = true; //选中 planlist.Items[i].Focused = true; //焦点 planlist.Items[i].EnsureVisible(); //滚动显示 } } loadpc.Visible = false; btnsearch.Enabled = true; lbtip.Text = "refresh success"; //前端新增一行end btnsave.Enabled = true; MessageBoxEx.Show(this, "save success"); }); sQLUtilEvent.Run(); } else { DataRow item = (DataRow)(planlist.SelectedItems[0]).Tag; planlist.SelectedItems[0].Tag = dataSave.Tables[0].Rows[0]; foreach (ListColumn l in PlanListColumn) { planlist.SelectedItems[0].SubItems[PlanListColumn.IndexOf(l)].Text = dataSave.Tables[0].Rows[0][l.Key].ToString(); } //前端新增一行end this.loadpc.Visible = false; btnsave.Enabled = true; lbtip.Text = "save success"; MessageBoxEx.Show(this, "save success"); } }); sQLUtilSaveEvent.Run(); } catch (Exception ex) { loadpc.Visible = false; btnsave.Enabled = true; lbtip.Text = "erroe"; MessageBoxEx.Show(this, "" + ex.GetBaseException()); } }); fileUploadUtilEvent.Run(); } catch (Exception ex) { MessageBoxEx.Show(this, "" + ex.GetBaseException()); } //上传文件到服务器end }