|
|
using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; using ICSSoft.Entity.PU_AppVouch; using System.Configuration; using Newtonsoft.Json; using System.Text; using System.Net; using System.IO; using ICSSoft.Frame.Data.Entity.WWModel; using ICSSoft.Frame.Data.DAL; using System.Linq;
namespace ICSSoft.Frame.APP { public partial class FormICSIntSupCalLog : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; private DataTable body = null; private DataSet ds = new DataSet(); static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString(); //static string APIURL = "http://localhost:51182/api/";
static string DataCollectWW = APIURL + "APICreateInventory_PU_AppVouchNB";
#region 构造函数
public FormICSIntSupCalLog() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #endregion
#region 操作权限
public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有)
DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow);
List<Control> ControlList = new List<Control>(); ControlList.Add(btnFilter); ControlList.Add(btnSelectAll); ControlList.Add(btnCancelAll); ControlList.Add(btnCreate); ControlList.Add(btnOutPut); ControlList.Add(btnRefresh); foreach (Control ctr in ControlList) { if (ctr.GetType() == typeof(SimpleButton)) { DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } } rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限
{ DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption"); rData.AcceptChanges(); return rData; } #endregion
#region 退出
private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); }
private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); }
#endregion
#region 移动窗体
private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
//重写窗体,使窗体可以不通过自带标题栏实现移动
protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息
if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion
#region 列表
private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion
#region 过滤
private string tempTableName = ""; private void btnFilter_Click(object sender, EventArgs e) { FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); filter.OldTempTableName = tempTableName; if (filter.ShowDialog() == DialogResult.OK) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); ds.Reset(); dataSource = null; body = null; tempTableName = filter.NewTempTableName; sqltxt = filter.SqlText; sqlconn = filter.FilterConnectString; dataSource = filter.FilterData.Tables[0]; dataSource.TableName = "Hand"; ds.Tables.Add(dataSource.Copy()); grdDetail.DataSource = ds.Tables["Hand"]; grvDetail.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageSize = 499; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 500; rptPage.PageIndex = 1; //rptPage.ReLoad();
_wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } } #endregion
#region 绑定数据源
private void btnConfig_Click(object sender, EventArgs e) { if (AppConfig.UserCode.ToLower() != "demo") { ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!"); return; } FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name); fdata.ShowDialog(); } #endregion
#region 分页
private void rptPage_PageIndexChanged(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy(); ds.Tables.Add(dataSource.Copy()); ds.Tables.Add(body.Copy()); DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables["Hand"].Columns["VouchCode"] }, new DataColumn[] { ds.Tables["Body"].Columns["VouchCode"] }); ds.Relations.Add(dr); grdDetail.DataSource = ds.Tables["Hand"]; //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
grdDetail.DataSource = data; } #endregion
#region 过滤方法
private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); } #endregion
#region 全选
private void btnSelectAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, "Y"); } } #endregion
#region 全消
private void btnCancelAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, ""); } } #endregion
#region 双击
private void grvDetail_DoubleClick(object sender, EventArgs e) { if (grvDetail.FocusedRowHandle < 0) { return; } if (grvDetail.FocusedColumn == colisSelect) { if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "") { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y"); } else { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, ""); } } } #endregion
#region 导出
private void btnOutPut_Click(object sender, EventArgs e) {
try { FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail); foe.ShowDialog(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } //SimpleButton btntemp = (SimpleButton)sender;
//if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
//{
// ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
// return;
//}
//FormOutExcel foe = new FormOutExcel();
//if (foe.ShowDialog() == DialogResult.OK)
//{
// try
// {
// string outtype = foe._OutType;
// string exceltype = foe._ExcelType;
// string filename = foe._FileName;
// string url = foe._Url;
// string sheetname = foe._SheetName;
// if (outtype.ToLower() == "excel")
// {
// DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
// op.SheetName = sheetname;
// grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
// }
// else
// {
// grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
// }
// MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// catch (Exception ex)
// {
// MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
//}
} #endregion
#region 刷新
private void btnRefresh_Click(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); ds.Reset(); dataSource = null; body = null; FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false); filter.OldTempTableName = tempTableName; //tempTableName = filter.NewTempTableName;
//DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
dataSource.TableName = "Hand"; ds.Tables.Add(dataSource.Copy()); grdDetail.DataSource = ds.Tables["Hand"]; grvDetail.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageIndex = 1; //rptPage.ReLoad();
_wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } }
#endregion
private void FormICSMO_Load(object sender, EventArgs e) { btnFilter_Click(sender, e); }
private void btnCreate_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; }
List<DataRowView> row = new List<DataRowView>(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); string moseq = grvDetail.GetRowCellValue(i, Colmoseq).ToString(); string eqpcode = grvDetail.GetRowCellValue(i, Coleqpcode).ToString(); string opcode = grvDetail.GetRowCellValue(i, COlopcode).ToString(); string invcode = grvDetail.GetRowCellValue(i, ColInvcode).ToString(); if (Convert.ToDecimal(grvDetail.GetRowCellValue(i, ColCanUpqty)) <= 0) { ICSBaseSimpleCode.AppshowMessageBox("生产订单号:" + mocode + ",行号:" + moseq + ",设备编码:" + eqpcode + ",工序编码:" + opcode + "无可上传数量,请确认!"); return; } if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(i, unitprice).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("物料编码:" + invcode + ",工序编码:" + opcode + "未维护单价,,请确认!"); return; } row.Add(grvDetail.GetRow(i) as DataRowView); } } if (row.Count < 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择要上传的数据!"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定产生委外请购单吗?") != DialogResult.OK) { return; } //新增
FormICSERPVendor vendor = new FormICSERPVendor(); if (vendor.ShowDialog() != DialogResult.OK) { return; }
string vendorcode = vendor.vencode; DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等..."); try { _wait.Show(); //从配置中获取
string _EnumKey = "00010"; string sqlcInvCCode = @"SELECT DISTINCT EnumText from Sys_EnumValues WHERE EnumKey='" + _EnumKey + "' "; DataTable dtcInvCCode = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlcInvCCode).Tables[0]; string _cInvCCode = string.Empty; if (dtcInvCCode != null && dtcInvCCode.Rows.Count > 0) { _cInvCCode = dtcInvCCode.Rows[0][0].ToString(); }
List<PU_AppVouchs> contextsWWList = new List<PU_AppVouchs>(); List<PU_AppVouch> listcontextWW = new List<PU_AppVouch>(); List<string> de = new List<string>(); PU_AppVouch contextWW = new PU_AppVouch(); contextWW.UserCode = AppConfig.UserCode; contextWW.UserName = AppConfig.UserName; contextWW.TargetAccount = ConfigurationManager.AppSettings["TargetAccountU8"]; contextWW.Vencode = vendorcode; string sqladdress = "select '['+DBIPADDRESS+']'+'.'+DBNAME as address from Sys_DataBase where dbsourcename='ERP'"; string ipaddress = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqladdress).Tables[0].Rows[0]["address"].ToString(); //产生ERP请购单
foreach (DataRowView a in row) { string MOCode = a.Row["工单号"].ToString(); string MOSEQ = a.Row["工单行"].ToString(); //查询工单部门
string sqldepart = @"SELECT MDeptCode,b.closetime
FROM " + ipaddress + @".dbo.mom_order a INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "'";
DataTable depart = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqldepart).Tables[0]; if (depart.Rows.Count > 0) { if (!de.Contains(depart.Rows[0]["MDeptCode"].ToString())) { de.Add(depart.Rows[0]["MDeptCode"].ToString()); } if (!String.IsNullOrEmpty(depart.Rows[0]["closetime"].ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单号:"+MOCode+",工单行:"+MOSEQ+"已关闭!"); _wait.Close(); return; } } if (de.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("获取工单部门失败!"); _wait.Close(); return; } if (de.Count > 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择相同部门的数据!"); _wait.Close(); return; } contextWW.cDepCode = depart.Rows[0]["MDeptCode"].ToString();
PU_AppVouchs contextsWW = new PU_AppVouchs(); contextsWW.cInvCCode = _cInvCCode;//物料大类
contextsWW.cInvCode = a.Row["物料编码"].ToString();//料号
contextsWW.cInvName = a.Row["物料名称"].ToString();//料号名称
contextsWW.OPCode = a.Row["工序编码"].ToString();//工序
contextsWW.iQuantity = Decimal.Parse(a.Row["本次可上传数量"].ToString()); contextsWW.iNum = Convert.ToInt32(MOSEQ);// lotinfo.LOTQTY * Convert.ToDecimal(lotinfo.EATTRIBUTE3);
contextsWW.PRLine = a.Row["工序名称"].ToString(); //contextsWW.cBatch = lotinfo.VenderLotNO;
contextsWW.MOCode = MOCode;//工单号
contextsWW.dArriveDate = Convert.ToDateTime(a.Row["MOPLANENDTIME"].ToString()).ToShortDateString(); contextsWW.dRequirDate = DateTime.Now.ToShortDateString(); //contextsWW.LotNo = _dr["LOTNO"].ToString();//产品产品跟踪单号 2020.7.13 delete by summer
contextsWW.LotNo = a.Row["设备编码"].ToString();//报工设备
if (!string.IsNullOrEmpty(a.Row["unitprice"].ToString()))//单价
contextsWW.Price = (decimal)a.Row["unitprice"];
contextsWWList.Add(contextsWW); } contextWW.list = contextsWWList; listcontextWW.Add(contextWW); string WWPR = JsonConvert.SerializeObject(listcontextWW); string iresultMO = HttpPost(DataCollectWW, WWPR); U8Result INVINResultMO = new U8Result(); INVINResultMO = JsonConvert.DeserializeObject<U8Result>(iresultMO);
StringBuilder str = new StringBuilder(); str.AppendLine("创建U8委外请购单接口:" + WWPR); str.AppendLine("接口返回结果:" + INVINResultMO.code); str.AppendLine("接口返回数据:" + INVINResultMO.msg); ICSMO2UserDAL.WriteLogFile(str.ToString(), "创建U8委外请购单接口");
if (INVINResultMO.code != "200") { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox(INVINResultMO.msg); return; } List<PU_AppVouchs> _list = new List<PU_AppVouchs>(); if (!string.IsNullOrWhiteSpace(INVINResultMO.msg)) { _list = JsonConvert.DeserializeObject<List<PU_AppVouchs>>(INVINResultMO.msg.ToString()); } else { _wait.Close(); throw new Exception("未获取到请购单数据!"); } //调用成功插入ICSIntSupCalLog表
foreach (var item in _list) { var qty=contextsWWList.Where(a => a.LotNo == item.LotNo && a.MOCode == item.MOCode && a.iNum == item.iNum && a.OPCode == item.OPCode).Select(a=>a.iQuantity).FirstOrDefault();
string UpdateSql = "insert into ICSIntSupCalLog values(newid(),'"+item.MOCode+"','"+item.iNum+"','"+item.LotNo+"','"+item.OPCode+"','"+item.PRLine+"','"+qty+"',NULL,'false',null,null,null)"; DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, UpdateSql); } _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("产生委外请购单成功!"); btnRefresh_Click(null, null);
} catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox(ex.Message); }
}
public static string HttpPost(string url, string body) { try { System.Text.Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { var res = (HttpWebResponse)ex.Response; StringBuilder sb = new StringBuilder(); StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8); sb.Append(sr.ReadToEnd()); throw new Exception(sb.ToString()); } }
private void grvDetail_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { if (grvDetail.GetFocusedRowCellValue(ColPrline).ToString() != ""&&(grvDetail.FocusedColumn==unitprice|| grvDetail.FocusedColumn == totalprice|| grvDetail.FocusedColumn ==memo)) { e.Cancel = true; } } } }
|