using System; using System.Collections.Generic; using System.Text; using DBUtility; using System.Data; namespace SCM { public class Cls_S_Xt_BaseBill { public string mvarReportTitle; public string mvarItemKey; public string ViewName = ""; public string sCondtion = ""; public string sOrderSql = ""; public string sKeyCol = ""; public string sShowItemSql = ""; //================================ public string mvarReportTitle2; public string mvarItemKey2; public string ViewName2 = ""; public string sCondtion2 = ""; public string sOrderSql2 = ""; public string sKeyCol2 = ""; public string sShowItemSql2 = ""; public frmHlpBillList oFrm; //public frmHlpBillList oFrm = new frmHlpBillList(); public List oBillSelectColl = new List(); //public List oBillSelectColl2 = new List(); // public SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1(); public Cls_S_Xt_BaseBill() { //--- } ////导出选中列 //public static void Data2Excel(string sText, DataGridView grdMain, string KeyItem) //{ // string saveFileName = ""; // bool fileSaved = false; // List hide = GetGridViewHide(grdMain, KeyItem); // if (hide.Count == 0) // { // DataToExcel(sText, grdMain); // return; // } // SaveFileDialog saveDialog = new SaveFileDialog(); // Excel.Application xlApp = new Excel.Application(); // if (xlApp == null) // { // MessageBox.Show("无法创建Excel文件,可能您的电脑未安装Excel", "提示"); // return; // } // string av = xlApp.Version; // if (Convert.ToDouble(xlApp.Version) < 12) // { // saveDialog.DefaultExt = "xls"; // saveDialog.Filter = "Excel文件|*.xls"; // } // else // { // saveDialog.DefaultExt = "xlsx"; // saveDialog.Filter = "Excel文件|*.xlsx"; // } // saveDialog.FileName = sText; // saveDialog.ShowDialog(); // saveFileName = saveDialog.FileName; // if (saveFileName.IndexOf(":") < 0) return; //被点了取消 // Excel.Workbooks workbooks = xlApp.Workbooks; // Excel.Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); // Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1]; //取得sheet1 // //写入 标题 // for (int i = 0; i < hide.Count; i++) // { // worksheet.Cells[1, i + 1] = hide[i]; // } // for (int r = 0; r < grdMain.RowCount; r++) // { // for (int i = 0; i < hide.Count; i++) // { // worksheet.Cells[r + 2, i + 1] = "" + ClsPub.isStrNull(grdMain.Rows[r].Cells[DBUtility.Gy_BaseFun.Fun_GetCol(hide[i], grdMain)].Value); // } // System.Windows.Forms.Application.DoEvents(); // } // //for (int r = 0; r < grdMain.RowCount; r++) // //{ // // for (int i = 0; i < grdMain.ColumnCount; i++) // // { // // worksheet.Cells[r + 2, i + 1] = "'" + ClsPub.isStrNull(grdMain.Rows[r].Cells[i].Value); // // } // // System.Windows.Forms.Application.DoEvents(); // //} // worksheet.Columns.EntireColumn.AutoFit();//列宽自适应。 // if (saveFileName != "") // { // try // { // workbook.Saved = true; // workbook.SaveCopyAs(saveFileName); // fileSaved = true; // } // catch (Exception ex) // { // fileSaved = false; // MessageBox.Show("导出文件时出错,文件可能正被打开!\n" + ex.Message, "提示"); // } // } // else // { // fileSaved = false; // } // xlApp.Quit(); // // // IntPtr t = new IntPtr(xlApp.Hwnd); //得到这个句柄,具体作用是得到这块内存入口 // int k = 0; // GetWindowThreadProcessId(t, out k); //得到本进程唯一标志k // System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k); //得到对进程k的引用 // p.Kill(); //关闭进程k // xlApp = null; // //GC.Collect();//强行销毁 // //if (fileSaved && System.IO.File.Exists(saveFileName)) System.Diagnostics.Process.Start(saveFileName); //打开EXCEL // MessageBox.Show("引出完毕!"); //} /// /// 网格 导出EXCEL 网格,文件名,标题名 /// //public static void DataGridViewToExcel2(DataGridView grdMain, string sText, string sBTText) //{ // SaveFileDialog saveFileDialog = new SaveFileDialog(); // saveFileDialog.Filter = "Execl文件(*.xls)|*.xls"; // saveFileDialog.FilterIndex = 0; // saveFileDialog.RestoreDirectory = true; // saveFileDialog.CreatePrompt = true; // saveFileDialog.Title = "数据视图导出EXCEL文件"; // saveFileDialog.FileName = sText; // //saveFileDialog.ShowDialog(); // if (saveFileDialog.ShowDialog() == DialogResult.OK) // { // Stream myStream; // myStream = saveFileDialog.OpenFile(); // StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312")); // string str = ""; // DateTime start = DateTime.Now; // try // { // if (sBTText != "") // { // sw.WriteLine(sBTText); // } // //写标题 // bool sFirstCol = true; // for (int i = 0; i < grdMain.ColumnCount; i++) // { // if (i > 0 && grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H" && sFirstCol != true) // { // str += "\t"; // } // if (grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H") // { // sFirstCol = false; // str += grdMain.Columns[i].HeaderText; // } // } // str = str.Replace("\n", ""); // sw.WriteLine(str); // //写内容 // for (int j = 0; j < grdMain.Rows.Count; j++) // { // string tempStr = ""; // sFirstCol = true; // for (int k = 0; k < grdMain.Columns.Count; k++) // { // if (k > 0 && grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H" && sFirstCol != true) // { // tempStr += "\t"; // } // if (grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H") // { // sFirstCol = false; // if (grdMain.Rows[j].Cells[k].Value == null) // { // tempStr += string.Empty; // } // else // { // tempStr += grdMain.Rows[j].Cells[k].Value.ToString(); // } // } // } // tempStr = tempStr.Replace("\n", ""); // sw.WriteLine(tempStr); // } // sw.Close(); // myStream.Close(); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // finally // { // sw.Close(); // myStream.Close(); // } // MessageBox.Show("将此工作表导出为excel共耗时:" + DateTime.Now.Subtract(start).TotalMilliseconds.ToString() + "毫秒"); // } //} //显示数据 /// /// 显示数据 /// /// 主SQL /// 过滤条件 /// 排序条件 /// 不可重复列 /// public virtual bool Refresh(string sWhere) { string sErr = ""; int MainIDCol, SubIDCol, BillNoCol; string tSQL; //ClsCN oCn = new ClsCN(); tSQL = sWhere + sCondtion + sOrderSql; try { oFrm = new frmHlpBillList(); oFrm.sPrimaryCol = sKeyCol; oFrm.Text = mvarReportTitle; oFrm.lblCaption.Text = mvarReportTitle; oFrm.tSQL = tSQL; oFrm.ViewName = ViewName; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { //返回数据到集合中 oBillSelectColl.Clear(); MainIDCol = oFrm.Fun_GetCol("hmainid"); SubIDCol = oFrm.Fun_GetCol("hsubid"); BillNoCol = oFrm.Fun_GetCol("单据号"); //循环 选中行 for (int i = 0; i < oFrm.grdMain.SelectedRows.Count; i++) { BillSelect oSelect = new BillSelect(); oSelect.BillNo = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[BillNoCol].Value); oSelect.BillMainID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[MainIDCol].Value); oSelect.BillSubID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[SubIDCol].Value); oSelect.BillTitle = mvarReportTitle; oSelect.BillType = mvarItemKey; oBillSelectColl.Add(oSelect); } } // if (oBillSelectColl.Count > 0) return true; else return false; } catch (Exception e) { sErr = e.Message; } return true; } //根据源单号 模拟查询数据 /// /// 显示数据 /// /// 主SQL /// 过滤条件 /// 排序条件 /// 不可重复列 /// public virtual bool RefreshBySourceBillNo(string sWhere) { string sErr = ""; string tSQL; //ClsCN oCn = new ClsCN(); tSQL = " select hmainid,hsubid,单据号 from " + ViewName + sWhere + sOrderSql; try { oWeb.Url = SCM.ClsPub1.WEBSURL; DataSet ds = oWeb.getDataSetBySQL(tSQL, ViewName, ref DBUtility.ClsPub.sExeReturnInfo); if (ds == null || ds.Tables[0].Rows.Count == 0) { return false; } //返回数据到集合中 oBillSelectColl.Clear(); //循环 选中行 for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { BillSelect oSelect = new BillSelect(); oSelect.BillNo = ClsPub.isStrNull(ds.Tables[0].Rows[i]["单据号"]); oSelect.BillMainID = ClsPub.isLong(ds.Tables[0].Rows[i]["hmainid"]); oSelect.BillSubID = ClsPub.isLong(ds.Tables[0].Rows[i]["hsubid"]); oSelect.BillTitle = mvarReportTitle; oSelect.BillType = mvarItemKey; oBillSelectColl.Add(oSelect); } // if (oBillSelectColl.Count > 0) return true; else return false; } catch (Exception e) { sErr = e.Message; } return true; } //显示数据2 /// /// 显示数据2 /// /// 主SQL /// 过滤条件 /// 排序条件 /// 不可重复列 /// public virtual bool Refresh2(string sWhere) { string sErr = ""; int MainIDCol, SubIDCol, BillNoCol; string tSQL; //ClsCN oCn = new ClsCN(); tSQL = sWhere + sCondtion2 + sOrderSql2; try { oFrm = new frmHlpBillList(); oFrm.sPrimaryCol = sKeyCol2; oFrm.Text = mvarReportTitle2; oFrm.lblCaption.Text = mvarReportTitle2; oFrm.tSQL = tSQL; oFrm.ViewName = ViewName2; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { //返回数据到集合中 oBillSelectColl.Clear(); MainIDCol = oFrm.Fun_GetCol("hmainid"); SubIDCol = oFrm.Fun_GetCol("hsubid"); BillNoCol = oFrm.Fun_GetCol("单据号"); //循环 选中行 for (int i = 0; i < oFrm.grdMain.SelectedRows.Count; i++) { BillSelect oSelect = new BillSelect(); oSelect.BillNo = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[BillNoCol].Value); oSelect.BillMainID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[MainIDCol].Value); oSelect.BillSubID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[SubIDCol].Value); oSelect.BillTitle = mvarReportTitle2; oSelect.BillType = mvarItemKey2; oBillSelectColl.Add(oSelect); } } // if (oBillSelectColl.Count > 0) return true; else return false; } catch (Exception e) { sErr = e.Message; } return true; } ////显示数据3 ///// ///// 显示数据3 ///// ///// 主SQL ///// 过滤条件 ///// 排序条件 ///// 不可重复列 ///// //public virtual bool Refresh_A3(string sWhere) //{ // string sErr = ""; // int MainIDCol, SubIDCol, BillNoCol; // string tSQL; // ClsCN oCn = new ClsCN(); // tSQL = sWhere + sCondtion2 + sOrderSql2; // try // { // oFrm.sPrimaryCol = sKeyCol2; // oFrm.Text = mvarReportTitle2; // oFrm.lblCaption.Text = mvarReportTitle2; // oFrm.tSQL = tSQL; // oFrm.ViewName = ViewName2; // oFrm.ShowDialog(); // if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) // { // //返回数据到集合中 // oBillSelectColl2.Clear(); // MainIDCol = oFrm.Fun_GetCol("hmainid"); // SubIDCol = oFrm.Fun_GetCol("hsubid"); // BillNoCol = oFrm.Fun_GetCol("单据号"); // //循环 选中行 // for (int i = 0; i < oFrm.grdMain.SelectedRows.Count; i++) // { // BillSelect_A3 oSelect = new BillSelect_A3(); // oSelect.BillNo = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[BillNoCol].Value); // oSelect.BillMainID = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[MainIDCol].Value); // oSelect.BillSubID = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[SubIDCol].Value); // oSelect.BillTitle = mvarReportTitle2; // oSelect.BillType = mvarItemKey2; // oBillSelectColl2.Add(oSelect); // } // } // // // if (oBillSelectColl2.Count > 0) // return true; // else // return false; // } // catch (Exception e) // { // sErr = e.Message; // } // return true; //} //返回单据列表 /// /// 返回单据列表 /// /// 过滤条件 public DataSet DisSourceBillList(string sWhere) { try { //ClsCN oCn = new ClsCN(); oWeb.Url = ClsPub1.WEBSURL; return oWeb.getDataSetBySQL("select " + sShowItemSql + " from " + ViewName + " " + sWhere + sCondtion + sOrderSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo); //oCn.RunProcReturn("select "+sShowItemSql+" from " + ViewName + " " + sWhere + sCondtion + sOrderSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo); } catch (Exception e) { DBUtility.ClsPub.sExeReturnInfo += "返回单据列表失败!" + e.Message; return null; } } //返回单据列表 /// /// 返回单据列表 /// /// 过滤条件 public DataSet DisSourceBillList2(string sWhere) { try { //ClsCN oCn = new ClsCN(); oWeb.Url = ClsPub1.WEBSURL; return oWeb.getDataSetBySQL("select " + sShowItemSql2 + " from " + ViewName2 + " " + sWhere + sCondtion2 + sOrderSql2, ViewName2, ref DBUtility.ClsPub.sExeReturnInfo); //oCn.RunProcReturn("select " + sShowItemSql2 + " from " + ViewName2 + " " + sWhere + sCondtion2 + sOrderSql2, ViewName2, ref DBUtility.ClsPub.sExeReturnInfo); } catch (Exception e) { DBUtility.ClsPub.sExeReturnInfo += "返回单据列表失败!" + e.Message; return null; } } public virtual bool Refresh3(string sWhere) { string sErr = ""; int MainIDCol, SubIDCol, BillNoCol; string tSQL; //ClsCN oCn = new ClsCN(); tSQL = sWhere + sCondtion + sOrderSql; try { oFrm = new frmHlpBillList(); oFrm.sPrimaryCol = sKeyCol; oFrm.Text = mvarReportTitle; oFrm.lblCaption.Text = mvarReportTitle; oFrm.tSQL = tSQL; oFrm.ViewName = ViewName; oFrm.ShowDialog(); //返回数据到集合中 oBillSelectColl.Clear(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { MainIDCol = oFrm.Fun_GetCol("HMaterID"); //SubIDCol = oFrm.Fun_GetCol("hsubid"); //BillNoCol = oFrm.Fun_GetCol("单据号"); //循环 选中行 for (int i = 0; i < oFrm.grdMain.SelectedRows.Count; i++) { BillSelect oSelect = new BillSelect(); //oSelect.BillNo = ClsPub.isStrNull(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[BillNoCol].Value); oSelect.BillMainID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[MainIDCol].Value); //oSelect.BillSubID = ClsPub.isLong(oFrm.grdMain.Rows[oFrm.grdMain.SelectedRows[i].Index].Cells[SubIDCol].Value); oSelect.BillTitle = mvarReportTitle; oSelect.BillType = mvarItemKey; oBillSelectColl.Add(oSelect); } } // if (oBillSelectColl.Count > 0) return true; else return false; } catch (Exception e) { sErr = e.Message; } return true; } } }