using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Collections; using System.Windows.Forms; using CoreFS.CA06; namespace Core.LZMes.Client.UIM { public partial class UIM010180 : FrmBase { private int selectedIndex1 = -1; private int selectedIndex2 = -1; private int selectedIndex3 = -1; private bool rowClick1 = false; private bool rowClick2 = false; private bool rowClick3 = false; private ArrayList moveList = new ArrayList(); public UIM010180() { InitializeComponent(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": this.DoQuery(); break; case "Save": this.DoSave(); break; case "Export": this.DoExport(); break; case "Exit": this.Close(); break; } } private void DoQuery() { ultraComboEditor1_ValueChanged(null, null); ultraComboEditor2_ValueChanged(null, null); ultraComboEditor3_ValueChanged(null, null); } private void DoSave() { //移垛时间 string moveDate = ""; if (this.ultraDateTimeEditor1.Value != null) { moveDate = this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMddHHmmss"); } string regId = this.UserInfo.GetUserID(); string moveOrder = this.UserInfo.GetUserOrder();//班次 string moverGroup = this.UserInfo.GetUserGroup();//班组 CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "moveColdCoil"; ccp.ServerParams = new object[] { moveList, regId, moveOrder, moverGroup, moveDate }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.DoQuery(); } private void DoExport() { Microsoft.Office.Interop.Excel.Application excel = null; ET.Application et = null; int row = 0; try { if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK) { System.Reflection.Missing oMissing = System.Reflection.Missing.Value; string filePath = saveFileDialog1.FileName; int[] idxs = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; if (isExcelInstalled()) { excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = excel.Application.Workbooks.Add(oMissing); //excel.Visible = true; Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.get_Item(1); foreach (DataRow dr in yardDS.Tables[0].Rows) { row = Convert.ToInt32(dr["VROW"]); row = row%10 != 0 ? row%10 : 10; ws.Cells[idxs[row - 1], row] = dr["YARD"].ToString(); idxs[row - 1]++; } workbook.SaveAs(filePath, oMissing, oMissing, oMissing, oMissing, oMissing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, oMissing, oMissing, oMissing, oMissing, oMissing); workbook.Close(oMissing, oMissing, oMissing); excel.Quit(); } else { et = new ET.Application(); ET._Workbook ewb = et.Workbooks.Add(oMissing); ET.Worksheet ews = (ET.Worksheet)ewb.Worksheets.get_Item(1); foreach (DataRow dr in yardDS.Tables[0].Rows) { row = Convert.ToInt32(dr["VROW"]); row = row % 10 != 0 ? row % 10 : 10; ews.Cells[idxs[row - 1], row] = dr["YARD"].ToString(); idxs[row - 1]++; } ewb.SaveAs(filePath, oMissing, oMissing, oMissing, oMissing, oMissing, ET.ETSaveAsAccessMode.etShared, oMissing, oMissing, oMissing, oMissing); ewb.Close(oMissing,oMissing,oMissing); et.Quit(); } } } catch (Exception ex) { MessageBox.Show("导出失败!"); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); System.Runtime.InteropServices.Marshal.ReleaseComObject(et); excel = null; et = null; GC.Collect(); } } private void UIM010180_Load(object sender, EventArgs e) { loadYardArea(); } private void loadYardArea() { int areaType = 2; //查询区域信息 CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "queryYardAreas"; ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal); ArrayList list = (ArrayList)ccp.ReturnObject; int listSize = list.Count; Infragistics.Win.ValueListItem[] valueListItems1 = new Infragistics.Win.ValueListItem[listSize]; Infragistics.Win.ValueListItem[] valueListItems2 = new Infragistics.Win.ValueListItem[listSize]; Infragistics.Win.ValueListItem[] valueListItems3 = new Infragistics.Win.ValueListItem[listSize]; for (int i = 0; i < listSize; i++) { Infragistics.Win.ValueListItem item1 = new Infragistics.Win.ValueListItem(); Infragistics.Win.ValueListItem item2 = new Infragistics.Win.ValueListItem(); Infragistics.Win.ValueListItem item3 = new Infragistics.Win.ValueListItem(); Hashtable ht = (Hashtable)list[i]; item1.DataValue = ((Hashtable)(ht["AREA_NO"]))["value"].ToString(); item1.DisplayText = ht["AREA_NAME"].ToString(); item2.DataValue = ((Hashtable)(ht["AREA_NO"]))["value"].ToString(); item2.DisplayText = ht["AREA_NAME"].ToString(); item3.DataValue = ((Hashtable)(ht["AREA_NO"]))["value"].ToString(); item3.DisplayText = ht["AREA_NAME"].ToString(); valueListItems1[i] = item1; valueListItems2[i] = item2; valueListItems3[i] = item3; } this.ultraComboEditor1.Items.AddRange(valueListItems1); this.ultraComboEditor2.Items.AddRange(valueListItems2); this.ultraComboEditor3.Items.AddRange(valueListItems3); } /// /// 根据钢卷号查询垛位 /// private void findLoadLoc() { string coilNo = this.textBox1.Text.Trim(); if ("".Equals(coilNo)) { MessageBox.Show("请输入冷轧钢卷号!"); return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "queryLoadLoc"; ccp.ServerParams = new object[] { coilNo }; ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal); string curLoadLoc = ccp.ReturnObject.ToString(); this.textBox2.Text = curLoadLoc; } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (13 == e.KeyChar) { findLoadLoc(); } } private void button1_Click(object sender, EventArgs e) { findLoadLoc(); } private void ultraComboEditor1_ValueChanged(object sender, EventArgs e) { moveList = new ArrayList(); if (ultraComboEditor1.Value != null) { dataSet1.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "queryYardCoils"; ccp.ServerParams = new object[] { ultraComboEditor1.Text }; ccp.SourceDataTable = dataSet1.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); } //查询空余垛位 yardDS.Tables[0].Clear(); CoreClientParam ccp1 = new CoreClientParam(); ccp1.ServerName = "UIM.UIM010180"; ccp1.MethodName = "queryEmptyYards"; ccp1.ServerParams = new object[] { ultraComboEditor1.Text }; ccp1.SourceDataTable = yardDS.Tables[0]; this.ExecuteQueryToDataTable(ccp1, CoreInvokeType.Internal); if (sender == null) { return; } ultraComboEditor2_ValueChanged(null, null); ultraComboEditor3_ValueChanged(null, null); } private void ultraComboEditor2_ValueChanged(object sender, EventArgs e) { if (ultraComboEditor2.Value != null) { dataSet2.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "queryYardCoils"; ccp.ServerParams = new object[] { ultraComboEditor2.Text }; ccp.SourceDataTable = dataSet2.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); } if (sender == null) { return; } ultraComboEditor1_ValueChanged(null, null); ultraComboEditor3_ValueChanged(null, null); } private void ultraComboEditor3_ValueChanged(object sender, EventArgs e) { if (ultraComboEditor3.Value != null) { dataSet3.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM010180"; ccp.MethodName = "queryYardCoils"; ccp.ServerParams = new object[] { ultraComboEditor3.Text }; ccp.SourceDataTable = dataSet3.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); } if (sender == null) { return; } ultraComboEditor1_ValueChanged(null, null); ultraComboEditor2_ValueChanged(null, null); } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { if (e == null) { rowClick1 = true; } if (rowClick1 && e != null) { rowClick1 = false; return; } if (ultraGrid1.ActiveRow != null) { if (selectedIndex1 > -1 && ultraGrid1.ActiveRow.Index != selectedIndex1) { ultraGrid1.Rows[selectedIndex1].Cells["CHK"].Value = "FALSE"; } ultraGrid1.Rows[ultraGrid1.ActiveRow.Index].Cells["CHK"].Value = ultraGrid1.Rows[ultraGrid1.ActiveRow.Index].Cells["CHK"].Value.ToString().Equals("TRUE") ? "FALSE" : "TRUE"; selectedIndex1 = ultraGrid1.ActiveRow.Index; } } private void ultraGrid2_AfterRowActivate(object sender, EventArgs e) { if (e == null) { rowClick2 = true; } if (rowClick2 && e != null) { rowClick2 = false; return; } if (ultraGrid2.ActiveRow != null) { if (selectedIndex2 > -1 && ultraGrid2.ActiveRow.Index != selectedIndex2) { ultraGrid2.Rows[selectedIndex2].Cells["CHK"].Value = "FALSE"; } ultraGrid2.Rows[ultraGrid2.ActiveRow.Index].Cells["CHK"].Value = ultraGrid2.Rows[ultraGrid2.ActiveRow.Index].Cells["CHK"].Value.ToString().Equals("TRUE") ? "FALSE" : "TRUE"; selectedIndex2 = ultraGrid2.ActiveRow.Index; } } private void ultraGrid3_AfterRowActivate(object sender, EventArgs e) { if (e == null) { rowClick3 = true; } if (rowClick3 && e != null) { rowClick3 = false; return; } if (ultraGrid3.ActiveRow != null) { if (selectedIndex3 > -1 && ultraGrid3.ActiveRow.Index != selectedIndex3) { ultraGrid3.Rows[selectedIndex3].Cells["CHK"].Value = "FALSE"; } ultraGrid3.Rows[ultraGrid3.ActiveRow.Index].Cells["CHK"].Value = ultraGrid3.Rows[ultraGrid3.ActiveRow.Index].Cells["CHK"].Value.ToString().Equals("TRUE") ? "FALSE" : "TRUE"; selectedIndex3 = ultraGrid3.ActiveRow.Index; } } //private void ultraGrid1_MouseClick(object sender, MouseEventArgs e) //{ // ultraGrid1_AfterRowActivate(null, null); //} //private void ultraGrid2_MouseClick(object sender, MouseEventArgs e) //{ // ultraGrid2_AfterRowActivate(null, null); //} //private void ultraGrid3_MouseClick(object sender, MouseEventArgs e) //{ // ultraGrid3_AfterRowActivate(null, null); //} private void pictureBox1_MouseEnter(object sender, EventArgs e) { this.toolTip1.Show("从原堆放位置->临时堆放位置", this.pictureBox1); } private void pictureBox2_MouseEnter(object sender, EventArgs e) { this.toolTip1.Show("从到堆放位置->原堆放位置或从临时堆放位置->原堆放位置", this.pictureBox2); } private void pictureBox3_MouseEnter(object sender, EventArgs e) { this.toolTip1.Show("从原堆放位置->到堆放位置或从临时堆放位置->到堆放位置", this.pictureBox3); } private void pictureBox4_MouseEnter(object sender, EventArgs e) { this.toolTip1.Show("从到堆放位置->临时堆放位置", this.pictureBox4); } /// /// 从原堆放位置->临时堆放位置 /// /// /// private void pictureBox1_Click(object sender, EventArgs e) { string[] mCoil = null; int fromRowCount = dataSet1.Tables[0].Rows.Count; for (int i = 0; i < fromRowCount; i++) { Infragistics.Win.UltraWinGrid.UltraGridRow fromUGR = ultraGrid1.Rows[i]; if (fromUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (fromUGR.Cells["COIL_NO"].Value == null || fromUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("原堆放位置上没有钢卷,请重新选择!"); return; } int tmpRowCount = dataSet2.Tables[0].Rows.Count; for (int j = 0; j < tmpRowCount; j++) { Infragistics.Win.UltraWinGrid.UltraGridRow tmpUGR = ultraGrid2.Rows[j]; if (tmpUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (tmpUGR.Cells["COIL_NO"].Value != null && !tmpUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("临时堆放位置上存在钢卷,请重新选择!"); return; } mCoil = new string[4]; mCoil[0] = fromUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = fromUGR.Cells["COIL_NO"].Value.ToString(); mCoil[1] = tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[3] = fromUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 moveList.Add(mCoil); fromUGR.Cells["COIL_NO"].Value = ""; tmpUGR.Cells["COIL_NO"].Value = mCoil[2]; break; } } break; } } } /// /// 从到堆放位置->临时堆放位置 /// /// /// private void pictureBox4_Click(object sender, EventArgs e) { string[] mCoil = null; int toRowCount = dataSet3.Tables[0].Rows.Count; for (int i = 0; i < toRowCount; i++) { Infragistics.Win.UltraWinGrid.UltraGridRow toUGR = ultraGrid3.Rows[i]; if (toUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (toUGR.Cells["COIL_NO"].Value == null || toUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("到堆放位置上没有钢卷,请重新选择!"); return; } int tmpRowCount = dataSet2.Tables[0].Rows.Count; for (int j = 0; j < tmpRowCount; j++) { Infragistics.Win.UltraWinGrid.UltraGridRow tmpUGR = ultraGrid2.Rows[j]; if (tmpUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (tmpUGR.Cells["COIL_NO"].Value != null && !tmpUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("临时堆放位置上存在钢卷,请重新选择!"); return; } mCoil = new string[4]; mCoil[0] = toUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = toUGR.Cells["COIL_NO"].Value.ToString(); mCoil[1] = tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[3] = toUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 moveList.Add(mCoil); toUGR.Cells["COIL_NO"].Value = ""; tmpUGR.Cells["COIL_NO"].Value = mCoil[2]; break; } } break; } } } /// /// 从原堆放位置->到堆放位置或从临时堆放位置->到堆放位置 /// /// /// private void pictureBox3_Click(object sender, EventArgs e) { string[] mCoil = new string[4]; int fromRowCount = dataSet1.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow fromUGR = null; for (int i = 0; i < fromRowCount; i++) { fromUGR = ultraGrid1.Rows[i]; if (fromUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (fromUGR.Cells["CUR_LOAD_LOC"].Value != null && !fromUGR.Cells["CUR_LOAD_LOC"].Value.ToString().Equals("")) { mCoil[0] = fromUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = fromUGR.Cells["COIL_NO"].Value.ToString(); mCoil[3] = fromUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 } break; } } int tmpRowCount = dataSet2.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow tmpUGR = null; for (int i = 0; i < tmpRowCount; i++) { tmpUGR = ultraGrid2.Rows[i]; if (tmpUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (tmpUGR.Cells["CUR_LOAD_LOC"].Value != null && !tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString().Equals("")) { if (mCoil[0] != null && !mCoil[0].Equals("")) { MessageBox.Show("原堆放位置和临时堆放位置不能同时选中,请确认后再重新选择!"); return; } mCoil[0] = tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = tmpUGR.Cells["COIL_NO"].Value.ToString(); mCoil[3] = tmpUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 } break; } } int toRowCount = dataSet3.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow toUGR = null; for (int i = 0; i < toRowCount; i++) { toUGR = ultraGrid3.Rows[i]; if (toUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (toUGR.Cells["COIL_NO"].Value != null && !toUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("到堆放位置上存在钢卷,请确认后再重新选择!"); return; } mCoil[1] = toUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); break; } } if (mCoil[1] == null || mCoil[1].Equals("")) { MessageBox.Show("原堆放位置或临时堆放位置没有选中的钢卷,请确认后再重新选择!"); return; } if (mCoil[2] == null || mCoil[2].Equals("")) { MessageBox.Show("没有选择到堆放位置,请确认后再重新选择!"); return; } moveList.Add(mCoil); if (fromUGR != null && fromUGR.Cells["COIL_NO"].Value != null && !fromUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { fromUGR.Cells["COIL_NO"].Value = ""; } else { tmpUGR.Cells["COIL_NO"].Value = ""; } toUGR.Cells["COIL_NO"].Value = mCoil[2]; } /// /// 从到堆放位置->原堆放位置或从临时堆放位置->原堆放位置 /// /// /// private void pictureBox2_Click(object sender, EventArgs e) { string[] mCoil = new string[4]; int toRowCount = dataSet3.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow toUGR = null; for (int i = 0; i < toRowCount; i++) { toUGR = ultraGrid3.Rows[i]; if (toUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (toUGR.Cells["CUR_LOAD_LOC"].Value != null && !toUGR.Cells["CUR_LOAD_LOC"].Value.ToString().Equals("")) { mCoil[0] = toUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = toUGR.Cells["COIL_NO"].Value.ToString(); mCoil[3] = toUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 } break; } } int tmpRowCount = dataSet2.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow tmpUGR = null; for (int i = 0; i < tmpRowCount; i++) { tmpUGR = ultraGrid2.Rows[i]; if (tmpUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (tmpUGR.Cells["CUR_LOAD_LOC"].Value != null && !tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString().Equals("")) { if (mCoil[0] != null && !mCoil[0].Equals("")) { MessageBox.Show("到堆放位置和临时堆放位置不能同时选中,请确认后再重新选择!"); return; } mCoil[0] = tmpUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); mCoil[2] = tmpUGR.Cells["COIL_NO"].Value.ToString(); mCoil[3] = tmpUGR.Cells["IS_REPAIR"].Value.ToString();//IS_REPAIR 是否修复 } break; } } int fromRowCount = dataSet1.Tables[0].Rows.Count; Infragistics.Win.UltraWinGrid.UltraGridRow fromUGR = null; for (int i = 0; i < fromRowCount; i++) { fromUGR = ultraGrid1.Rows[i]; if (fromUGR.Cells["CHK"].Value.ToString().ToUpper().Equals("TRUE")) { if (fromUGR.Cells["COIL_NO"].Value != null && !fromUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { MessageBox.Show("原堆放位置上存在钢卷,请确认后再重新选择!"); return; } mCoil[1] = fromUGR.Cells["CUR_LOAD_LOC"].Value.ToString(); break; } } if (mCoil[2] == null || mCoil[2].Equals("")) { MessageBox.Show("到堆放位置或临时堆放位置没有选中的钢卷,请确认后再重新选择!"); return; } if (mCoil[1] == null || mCoil[1].Equals("")) { MessageBox.Show("没有选择原堆放位置,请确认后再重新选择!"); return; } moveList.Add(mCoil); if (toUGR != null && toUGR.Cells["COIL_NO"].Value != null && !toUGR.Cells["COIL_NO"].Value.ToString().Equals("")) { toUGR.Cells["COIL_NO"].Value = ""; } else { tmpUGR.Cells["COIL_NO"].Value = ""; } fromUGR.Cells["COIL_NO"].Value = mCoil[2]; } private void pictureBox1_MouseLeave(object sender, EventArgs e) { this.toolTip1.Hide(this.pictureBox1); } private void pictureBox2_MouseLeave(object sender, EventArgs e) { this.toolTip1.Hide(this.pictureBox2); } private void pictureBox3_MouseLeave(object sender, EventArgs e) { this.toolTip1.Hide(this.pictureBox3); } private void pictureBox4_MouseLeave(object sender, EventArgs e) { this.toolTip1.Hide(this.pictureBox4); } public bool isExcelInstalled() { Type type = Type.GetTypeFromProgID("Excel.Application"); return type != null; } } }