private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { DataRow row = gridView1.GetDataRow(e.RowHandle); if (row == null) { return; } LineProductMesEntityu.ProductPlanBodyEntity model = new LineProductMesEntityu.ProductPlanBodyEntity( ); //交货日期 model.PRE006 = Convert.ToDateTime(row ["IBB013"]); //排产数量 model.PRE008 = Convert.ToInt32(row ["IBB010"]); //日产量 model.PRE009 = Convert.ToInt32(row ["IBB009"]); //开始日期 model.PRE005 = Convert.ToDateTime(row ["IBB007"]); if (model.PRE009 == 0) { return; } int days = Convert.ToInt32(model.PRE008 / model.PRE009); if (model.PRE008 % model.PRE009 > 0) { days++; } if ((Convert.ToDateTime(model.PRE006) - Convert.ToDateTime(model.PRE005).AddDays(days)).Days != 0) { row ["U0"] = (Convert.ToDateTime(model.PRE006) - Convert.ToDateTime(model.PRE005).AddDays(days)).Days; } }
/// <summary> /// 复制 /// </summary> /// <param name="table"></param> /// <param name="oddNum"></param> /// <returns></returns> public bool Copy(DataTable table, string oddNum) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); LineProductMesEntityu.ProductPlanHeaderEntity model = new LineProductMesEntityu.ProductPlanHeaderEntity( ); model.PRD001 = getOddNum( ); model.PRD002 = UserInfoMation.sysTime; model.PRD003 = false; AddHeader(SQLString, model); UserInfoMation.oddNum = model.PRD001; LineProductMesEntityu.ProductPlanBodyEntity modelBody = new LineProductMesEntityu.ProductPlanBodyEntity( ); modelBody.PRE001 = model.PRD001; foreach (DataRow row in table.Rows) { modelBody.PRE002 = row ["PRE002"].ToString( ); modelBody.PRE003 = row ["PRE003"].ToString( ); modelBody.PRE004 = row ["PRE004"].ToString( ); modelBody.PRE005 = Convert.ToDateTime(row ["PRE005"].ToString( )); modelBody.PRE006 = Convert.ToDateTime(row ["PRE006"].ToString( )); modelBody.PRE007 = Convert.ToInt32(row ["PRE007"].ToString( )); modelBody.PRE008 = Convert.ToInt32(row ["PRE008"].ToString( )); modelBody.PRE010 = Convert.ToInt32(row ["PRE010"].ToString( )); AddBody(SQLString, modelBody); } StringBuilder strSql = new StringBuilder( ); strSql.AppendFormat("UPDATE MIKPRD SET PRD003=1 WHERE PRD001='{0}'", oddNum); SQLString.Add(strSql, null); return(SqlHelper.ExecuteSqlTranDic(SQLString)); }
void AddBody(Dictionary <object, object> SQLString, LineProductMesEntityu.ProductPlanBodyEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("insert into MIKPRE("); strSql.Append("PRE001,PRE002,PRE003,PRE004,PRE005,PRE006,PRE007,PRE008,PRE010)"); strSql.Append(" values ("); strSql.Append("@PRE001,@PRE002,@PRE003,@PRE004,@PRE005,@PRE006,@PRE007,@PRE008,@PRE010)"); SqlParameter [] parameters = { new SqlParameter("@PRE001", SqlDbType.NVarChar, 20), new SqlParameter("@PRE002", SqlDbType.NVarChar, 20), new SqlParameter("@PRE003", SqlDbType.NVarChar, 20), new SqlParameter("@PRE004", SqlDbType.NVarChar, 20), new SqlParameter("@PRE005", SqlDbType.Date, 3), new SqlParameter("@PRE006", SqlDbType.Date, 3), new SqlParameter("@PRE007", SqlDbType.Int, 4), new SqlParameter("@PRE008", SqlDbType.Int, 4), //new SqlParameter("@PRE009", SqlDbType.Int,4), new SqlParameter("@PRE010", SqlDbType.Int, 4) }; parameters [0].Value = model.PRE001; parameters [1].Value = model.PRE002; parameters [2].Value = model.PRE003; parameters [3].Value = model.PRE004; parameters [4].Value = model.PRE005; parameters [5].Value = model.PRE006; parameters [6].Value = model.PRE007; parameters [7].Value = model.PRE008; //parameters [ 8 ] . Value = model . PRE009; parameters [8].Value = model.PRE010; SQLString.Add(strSql, parameters); }
public FormProductPlan(/*DataRow rowedit*/) { InitializeComponent( ); _header = new LineProductMesEntityu.ProductPlanHeaderEntity( ); _body = new LineProductMesEntityu.ProductPlanBodyEntity( ); _bll = new LineProductMesBll.Bll.ProductPlanBll( ); ToolBarContain.ToolbarsC(barTool, new DevExpress.XtraBars.BarItem [] { toolExport, toolPrint }); GridViewMoHuSelect.SetFilter(new DevExpress.XtraGrid.Views.Grid.GridView [] { gridView1 }); GrivColumnStyle.setColumnStyle(new DevExpress.XtraGrid.Views.Grid.GridView [] { gridView1 }); FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic); fi.SetValue(null, new DrawXPaint( )); //toolExamin . Caption = "弃用"; //toolCancellation . Caption = "复制"; controlUnEnable( ); controlClear( ); dtTime = LineProductMesBll.UserInfoMation.sysTime; toolCancellation.Caption = "生成ERP计划"; layoutControlItem4.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; //if ( rowedit != null ) //{ // this . rows = rowedit; //} }
void AddPlan(Dictionary <object, object> SQLString, LineProductMesEntityu.ProductPlanBodyEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.AppendFormat("UPDATE MIKPRE SET PRE009=ISNULL(PRE009,0)+{0},PRE012='{2}' WHERE idx={1}", model.PRE009, model.idx, model.PRE012); SQLString.Add(strSql, null); }
/// <summary> /// 保存数据 /// </summary> /// <param name="model"></param> /// <param name="table"></param> /// <returns></returns> public bool Save(LineProductMesEntityu.ProductPlanHeaderEntity model, DataTable table) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); model.PRD001 = getOddNum( ); UserInfoMation.oddNum = model.PRD001; AddHeader(SQLString, model); LineProductMesEntityu.ProductPlanBodyEntity modelBody = new LineProductMesEntityu.ProductPlanBodyEntity( ); modelBody.PRE001 = model.PRD001; //StringBuilder strSql = new StringBuilder ( ); //strSql . Append ( "SELECT PRF001,PRF002 FROM MIKPRF " ); //DataTable tableR = SqlHelper . ExecuteDataTable ( strSql . ToString ( ) ); foreach (DataRow row in table.Rows) { modelBody.PRE002 = row ["PRE002"].ToString( ); modelBody.PRE003 = row ["PRE003"].ToString( ); modelBody.PRE004 = row ["PRE004"].ToString( ); modelBody.PRE005 = Convert.ToDateTime(row ["PRE005"].ToString( )); modelBody.PRE006 = Convert.ToDateTime(row ["PRE006"].ToString( )); modelBody.PRE007 = Convert.ToInt32(row ["PRE007"].ToString( )); modelBody.PRE008 = Convert.ToInt32(row ["PRE008"].ToString( )); if (string.IsNullOrEmpty(row ["PRE009"].ToString( ))) { modelBody.PRE009 = null; } else { modelBody.PRE009 = Convert.ToInt32(row ["PRE009"].ToString( )); } modelBody.PRE010 = Convert.ToInt32(row ["PRE010"].ToString( )); if (string.IsNullOrEmpty(row ["PRE011"].ToString( ))) { modelBody.PRE011 = 0; } else { modelBody.PRE011 = Convert.ToInt32(row ["PRE011"].ToString( )); } modelBody.PRE008 = modelBody.PRE008 + modelBody.PRE011; AddBody(SQLString, modelBody); //if ( tableR != null && tableR . Rows . Count > 0 ) //{ // if ( tableR . Select ( "PRF001='" + modelBody . PRE004 + "' AND PRF002='" + modelBody . PRE005 + "'" ) . Length < 1 ) // Addprf ( SQLString ,modelBody ); // else // Editprf ( SQLString ,modelBody ); //} //else // Addprf ( SQLString ,modelBody ); } return(SqlHelper.ExecuteSqlTranDic(SQLString)); }
/// <summary> /// 审核 /// </summary> /// <param name="oddNum"></param> /// <returns></returns> public bool Examine(LineProductMesEntityu.ProductPlanHeaderEntity _header, DataTable table) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); StringBuilder strSql = new StringBuilder( ); strSql.Append("UPDATE MIKPRD SET PRD003=@PRD003 WHERE PRD001=@PRD001"); SqlParameter [] parameter = { new SqlParameter("@PRD001", SqlDbType.NVarChar, 20), new SqlParameter("@PRD003", SqlDbType.Bit) }; parameter [0].Value = _header.PRD001; parameter [1].Value = _header.PRD003; SQLString.Add(strSql, parameter); LineProductMesEntityu.ProductPlanBodyEntity modelBody = new LineProductMesEntityu.ProductPlanBodyEntity( ); strSql = new StringBuilder( ); strSql.Append("SELECT PRF001,PRF002 FROM MIKPRF "); DataTable tableR = SqlHelper.ExecuteDataTable(strSql.ToString( )); foreach (DataRow row in table.Rows) { modelBody.PRE004 = row ["PRE004"].ToString( ); modelBody.PRE005 = Convert.ToDateTime(row ["PRE005"].ToString( )); modelBody.PRE008 = Convert.ToInt32(row ["PRE008"].ToString( )); if (string.IsNullOrEmpty(row ["PRE011"].ToString( ))) { modelBody.PRE011 = 0; } else { modelBody.PRE011 = Convert.ToInt32(row ["PRE011"].ToString( )); } modelBody.PRE008 = modelBody.PRE008 + modelBody.PRE011; if (tableR != null && tableR.Rows.Count > 0) { if (tableR.Select("PRF001='" + modelBody.PRE004 + "' AND PRF002='" + modelBody.PRE005 + "'").Length < 1) { Addprf(SQLString, modelBody); } else { Editprf(SQLString, modelBody); } } else { Addprf(SQLString, modelBody); } } return(SqlHelper.ExecuteSqlTranDic(SQLString)); }
/// <summary> /// 读取排产数据 /// </summary> /// <returns></returns> public bool ReadPlanData( ) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); StringBuilder strSql = new StringBuilder( ); strSql.Append("SELECT PRE004,PRE005,SUM(PRE008) PRE008 FROM MIKPRD A INNER JOIN MIKPRE B ON A.PRD001=B.PRE001 WHERE PRD003=0 GROUP BY PRE004,PRE005 ORDER BY PRE004,PRE005"); DataTable table = SqlHelper.ExecuteDataTable(strSql.ToString( )); if (table == null || table.Rows.Count < 1) { return(true); } strSql = new StringBuilder( ); strSql.Append("SELECT PRF001,PRF002,PRF003 FROM MIKPRF ORDER BY PRF001"); DataTable tableOne = SqlHelper.ExecuteDataTable(strSql.ToString( )); bool result = true; if (tableOne == null || tableOne.Rows.Count < 1) { result = false; } LineProductMesEntityu.ProductPlanBodyEntity model = new LineProductMesEntityu.ProductPlanBodyEntity( ); LineProductMesEntityu.ProductPlanPreviewEntity entity = new LineProductMesEntityu.ProductPlanPreviewEntity( ); foreach (DataRow row in table.Rows) { model.PRE004 = row ["PRE004"].ToString( ); model.PRE005 = Convert.ToDateTime(row ["PRE005"]); model.PRE008 = Convert.ToInt32(row ["PRE008"]); if (result == false) { Addprf(SQLString, model); } else { if (tableOne.Select("PRF001='" + model.PRE004 + "' AND PRF002='" + model.PRE005 + "'").Length < 1) { Addprf(SQLString, model); } else { Editprf(SQLString, model); } } } return(SqlHelper.ExecuteSqlTranDic(SQLString)); }
void Editprf(Dictionary <object, object> SQLString, LineProductMesEntityu.ProductPlanBodyEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("update MIKPRF set "); strSql.Append("PRF003=ISNULL(PRF003,0)+@PRF003 "); strSql.Append("WHERE PRF001=@PRF001 AND PRF002=@PRF002"); SqlParameter [] parameters = { new SqlParameter("@PRF001", SqlDbType.NVarChar, 20), new SqlParameter("@PRF002", SqlDbType.Date, 3), new SqlParameter("@PRF003", SqlDbType.Int, 4) }; parameters [0].Value = model.PRE004; parameters [1].Value = model.PRE005; parameters [2].Value = model.PRE008; SQLString.Add(strSql, parameters); }
void Addprf(Dictionary <object, object> SQLString, LineProductMesEntityu.ProductPlanBodyEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("insert into MIKPRF("); strSql.Append("PRF001,PRF002,PRF003)"); strSql.Append(" values ("); strSql.Append("@PRF001,@PRF002,@PRF003)"); SqlParameter [] parameters = { new SqlParameter("@PRF001", SqlDbType.NVarChar, 20), new SqlParameter("@PRF002", SqlDbType.Date, 3), new SqlParameter("@PRF003", SqlDbType.Int, 4) }; parameters [0].Value = model.PRE004; parameters [1].Value = model.PRE005; parameters [2].Value = model.PRE008; SQLString.Add(strSql, parameters); }
void EditBody(Dictionary <object, object> SQLString, LineProductMesEntityu.ProductPlanBodyEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("update MIKPRE set "); strSql.Append("PRE002=@PRE002,"); strSql.Append("PRE003=@PRE003,"); strSql.Append("PRE004=@PRE004,"); strSql.Append("PRE005=@PRE005,"); strSql.Append("PRE006=@PRE006,"); strSql.Append("PRE007=@PRE007,"); strSql.Append("PRE008=@PRE008,"); //strSql . Append ( "PRE009=@PRE009," ); strSql.Append("PRE010=@PRE010 "); //strSql . Append ( "PRE012=@PRE012 " ); strSql.Append(" where idx=@idx"); SqlParameter [] parameters = { new SqlParameter("@PRE002", SqlDbType.NVarChar, 20), new SqlParameter("@PRE003", SqlDbType.NVarChar, 20), new SqlParameter("@PRE004", SqlDbType.NVarChar, 20), new SqlParameter("@PRE005", SqlDbType.Date, 3), new SqlParameter("@PRE006", SqlDbType.Date, 3), new SqlParameter("@PRE007", SqlDbType.Int, 4), new SqlParameter("@PRE008", SqlDbType.Int, 4), //new SqlParameter("@PRE009", SqlDbType.Int,4), new SqlParameter("@PRE010", SqlDbType.Int, 4), //new SqlParameter("@PRE012", SqlDbType.NVarChar,20), new SqlParameter("@idx", SqlDbType.Int, 4) }; parameters [0].Value = model.PRE002; parameters [1].Value = model.PRE003; parameters [2].Value = model.PRE004; parameters [3].Value = model.PRE005; parameters [4].Value = model.PRE006; parameters [5].Value = model.PRE007; parameters [6].Value = model.PRE008; //parameters [ 7 ] . Value = model . PRE009; parameters [7].Value = model.PRE010; //parameters [ 9 ] . Value = model . PRE012; parameters [8].Value = model.idx; SQLString.Add(strSql, parameters); }
/// <summary> /// 生成ERP计划 /// </summary> /// <param name="oddNum"></param> /// <returns></returns> public bool AddPlan(string oddNum) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); LineProductMesEntityu.SGMSAAEntity saa = new LineProductMesEntityu.SGMSAAEntity( ); saa.SAA001 = getCodeForPlan( ); saa.SAA002 = string.Empty; saa.SAA003 = UserInfoMation.sysTime.ToString("yyyyMMdd"); saa.SAA004 = UserInfoMation.userNum; saa.SAA005 = "06"; saa.SAA006 = string.Empty; saa.SAA013 = "F"; saa.SAA014 = string.Empty; saa.SAA901 = UserInfoMation.userNum; saa.SAA902 = saa.SAA003; AddSAA(SQLString, saa); StringBuilder strSql = new StringBuilder( ); strSql.AppendFormat("SELECT PRE004,PRE002,PRE003,DEA002,DEA057,DEA003,SUM(PRE008) PRE008 FROM MIKPRE A INNER JOIN TPADEA B ON A.PRE004=B.DEA001 WHERE PRE001='{0}' AND PRE008-ISNULL(PRE009,0)>0 GROUP BY PRE004,DEA002,DEA057,DEA003,PRE002,PRE003", oddNum); DataTable tableView = SqlHelper.ExecuteDataTable(strSql.ToString( )); if (tableView == null || tableView.Rows.Count < 1) { return(true); } int i = 0; List <LineProductMesEntityu.SGMSABEntity> modelList = new List <LineProductMesEntityu.SGMSABEntity> ( ); foreach (DataRow row in tableView.Rows) { LineProductMesEntityu.SGMSABEntity sab = new LineProductMesEntityu.SGMSABEntity( ); sab.SAB001 = saa.SAA001; i++; sab.SAB002 = i.ToString( ).PadLeft(3, '0'); sab.SAB003 = row ["PRE004"].ToString( ); sab.SAB004 = row ["DEA002"].ToString( ); sab.SAB005 = row ["DEA057"].ToString( ); sab.SAB006 = row ["DEA003"].ToString( ); sab.SAB007 = Convert.ToDecimal(row ["PRE008"].ToString( )); sab.SAB009 = UserInfoMation.sysTime.ToString("yyyyMMdd"); sab.SAB010 = sab.SAB009; sab.SAB011 = "F"; sab.SAB019 = "F"; sab.SAB020 = "32"; sab.SAB021 = row ["PRE002"].ToString( ); sab.SAB022 = row ["PRE003"].ToString( ); sab.SAB901 = UserInfoMation.userNum; sab.SAB902 = UserInfoMation.sysTime.ToString("yyyyMMdd"); modelList.Add(sab); ADDSAB(SQLString, sab); } if (modelList.Count > 0) { foreach (LineProductMesEntityu.SGMSABEntity list in modelList) { strSql = new StringBuilder( ); strSql.AppendFormat("SELECT QAB003,DEA002,DEA057,DEA003,DEA008,CONVERT(FLOAT,QAB005/QAB006) QAB005 FROM SGMQAB A INNER JOIN TPADEA B ON A.QAB003=B.DEA001 WHERE QAB001='{0}'", list.SAB003); DataTable table = SqlHelper.ExecuteDataTable(strSql.ToString( )); if (table == null || table.Rows.Count < 1) { continue; } i = 0; LineProductMesEntityu.SGMSACEntity entity = new LineProductMesEntityu.SGMSACEntity( ); entity.SAC001 = saa.SAA001; entity.SAC002 = list.SAB002; foreach (DataRow row in table.Rows) { i++; entity.SAC003 = i.ToString( ).PadLeft(3, '0'); entity.SAC004 = row ["QAB003"].ToString( ); entity.SAC005 = row ["DEA002"].ToString( ); entity.SAC006 = row ["DEA057"].ToString( ); entity.SAC007 = row ["DEA003"].ToString( ); entity.SAC008 = row ["DEA008"].ToString( ); entity.SAC009 = string.IsNullOrEmpty(row ["QAB005"].ToString( )) == true ? 0 : Convert.ToDecimal(row ["QAB005"]) * list.SAB007; ADDSAC(SQLString, entity); } } } strSql = new StringBuilder( ); strSql.AppendFormat("SELECT idx,PRE008-ISNULL(PRE009,0) PRE008 FROM MIKPRE WHERE PRE001='{0}' AND PRE008-ISNULL(PRE009,0)>0", oddNum); tableView = SqlHelper.ExecuteDataTable(strSql.ToString( )); LineProductMesEntityu.ProductPlanBodyEntity model = new LineProductMesEntityu.ProductPlanBodyEntity( ); model.PRE012 = saa.SAA001; foreach (DataRow row in tableView.Rows) { model.idx = Convert.ToInt32(row ["idx"].ToString( )); model.PRE009 = Convert.ToInt32(row ["PRE008"].ToString( )); AddPlan(SQLString, model); } return(SqlHelper.ExecuteSqlTranDic(SQLString)); }
/// <summary> /// 编辑数据 /// </summary> /// <param name="model"></param> /// <param name="table"></param> /// <param name="idxList"></param> /// <returns></returns> public bool Edit(LineProductMesEntityu.ProductPlanHeaderEntity model, DataTable table, List <string> idxList) { Dictionary <object, object> SQLString = new Dictionary <object, object> ( ); LineProductMesEntityu.ProductPlanBodyEntity modelBody = new LineProductMesEntityu.ProductPlanBodyEntity( ); modelBody.PRE001 = model.PRD001; //StringBuilder strSql = new StringBuilder ( ); //strSql . Append ( "SELECT PRF001,PRF002 FROM MIKPRF " ); //DataTable tableR = SqlHelper . ExecuteDataTable ( strSql . ToString ( ) ); foreach (DataRow row in table.Rows) { modelBody.idx = string.IsNullOrEmpty(row ["idx"].ToString( )) == true ? 0 : Convert.ToInt32(row ["idx"]); modelBody.PRE002 = row ["PRE002"].ToString( ); modelBody.PRE003 = row ["PRE003"].ToString( ); modelBody.PRE004 = row ["PRE004"].ToString( ); modelBody.PRE005 = Convert.ToDateTime(row ["PRE005"].ToString( )); modelBody.PRE006 = Convert.ToDateTime(row ["PRE006"].ToString( )); modelBody.PRE007 = Convert.ToInt32(row ["PRE007"].ToString( )); modelBody.PRE008 = string.IsNullOrEmpty(row ["PRE008"].ToString( )) == true ? 0 : Convert.ToInt32(row ["PRE008"].ToString( )); //modelBody . PRE009 = string . IsNullOrEmpty ( row [ "PRE009" ] . ToString ( ) ) == true ? 0 : Convert . ToInt32 ( row [ "PRE009" ] . ToString ( ) ); modelBody.PRE010 = Convert.ToInt32(row ["PRE010"].ToString( )); //modelBody . PRE012 = modelBody . PRE009 == 0 ? string . Empty : row [ "PRE012" ] . ToString ( ); if (string.IsNullOrEmpty(row ["PRE011"].ToString( ))) { modelBody.PRE011 = 0; } else { modelBody.PRE011 = Convert.ToInt32(row ["PRE011"].ToString( )); } modelBody.PRE008 = modelBody.PRE008 + modelBody.PRE011; if (modelBody.idx < 1) { AddBody(SQLString, modelBody); //if ( tableR != null && tableR . Rows . Count > 0 ) //{ // if ( tableR . Select ( "PRF001='" + modelBody . PRE004 + "' AND PRF002='" + modelBody . PRE005 + "'" ) . Length < 1 ) // Addprf ( SQLString ,modelBody ); // else // { // if ( modelBody . PRE011 != 0 ) // { // modelBody . PRE008 = modelBody . PRE011; // Editprf ( SQLString ,modelBody ); // } // } //} //else // Addprf ( SQLString ,modelBody ); } else { EditBody(SQLString, modelBody); //if ( modelBody . PRE011 != 0 ) //{ // modelBody . PRE008 = modelBody . PRE011; // Editprf ( SQLString ,modelBody ); //} } } foreach (string s in idxList) { DeleteBody(SQLString, s); } return(SqlHelper.ExecuteSqlTranDic(SQLString)); }