public loadConfFileCtrl() { InitializeComponent(); Label lbNum = new Label(); lbNum.Foreground = Brushes.White; cvsValueLst.Children.Add(lbNum); for (int i = 0; i < 88; i++) { loadFileItemCtrl valueItem = new loadFileItemCtrl(); cvsValueLst.Children.Add(valueItem); Canvas.SetTop(valueItem, (cvsValueLst.Children.Count - 1) * 20); } dtLoad.Interval = new TimeSpan(0, 0, 0, 0, 10); dtLoad.Tick += new EventHandler(dtLoad_Tick); dtShow.Interval = new TimeSpan(0, 0, 0, 0, 10); dtShow.Tick += new EventHandler(dtShow_Tick); this.Visibility = Visibility.Hidden; }
private void loadParams() { try { int addr_int = 0; if (curFocusNr < itemLst.Count) { if (curItem != null) curItem.focusState = false; curItem = cvsValueLst.Children[curFocusNr] as loadFileItemCtrl; curItem.focusState = true; string[] strtmp = curItem.addr.Split('.'); if (strtmp.Length == 2) { addr_int = -1; if (!LinkMgr.getObjPlcAddr(curItem.addr, ref addr_int, strtmp[0])) { curItem.flagLoadOk = false; throw new Exception("get " + curItem.addr + " addr_int error!"); } if (addr_int == -1 || addr_int == 0) { curItem.flagLoadOk = false; } int newValue = -1; if (Lasal32.LslReadFromSvr(addr_int,ref newValue)) { curItem.value = newValue.ToString(); curItem.flagLoadOk = true; loadNrCount++; } } //curLstNr++; curFocusNr++; if (curFocusNr > 85) { double newTop = Canvas.GetTop(cvsValueLst) - 20; Canvas.SetTop(cvsValueLst, newTop); lbCurPage.Content = ((int)(newTop / -85 / 20 + 1)).ToString() + "/" + pageNr; } } else { if (curItem != null) curItem.focusState = false; curItem = null; curFocusNr = 0; dtLoad.Stop(); string fileName = lbNewFilename.Content.ToString(); FileStream fsNew = null; //if (valmoWin.sUsbPath != null) //{ // if (!Directory.Exists(valmoWin.sUsbPath.FullName + "\\conf")) // Directory.CreateDirectory(valmoWin.sUsbPath.FullName + "\\conf"); // fsNew = new FileStream(valmoWin.sUsbPath.FullName + "\\conf" + fileName, FileMode.OpenOrCreate); //} //else fsNew = new FileStream(fileName, FileMode.Create); if (fsNew != null) { StreamWriter sw = new StreamWriter(fsNew); foreach (loadFileItemCtrl item in cvsValueLst.Children) { sw.WriteLine(item.addr + "\t" + item.value); } sw.Close(); fsNew.Close(); MessageBox.Show("Save OK! Save " + loadNrCount + "values"); Canvas.SetTop(cvsValueLst, 0); lbCurPage.Content = "1/" + pageNr; } } } catch (Exception ex) { if (curItem != null) curItem.focusState = false; //curLstNr = 0; //curItem = null; dtLoad.Stop(); //pageStartNr = 1; //pageEndNr = 0; curFocusNr = 0; string fileName = lbNewFilename.Content.ToString(); if (fileName.Substring(fileName.Length - fileType.Length, fileType.Length) != fileType) { fileName += "." + fileType; } FileStream fsNew = new FileStream("./conf/" + fileName, FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fsNew); foreach (loadFileItemCtrl item in cvsValueLst.Children) { sw.WriteLine(item.addr + "\t" + item.value); } sw.Close(); fsNew.Close(); MessageBox.Show("Save error! Save " + loadNrCount + "values"); Canvas.SetTop(cvsValueLst, 0); lbCurPage.Content = "1/" + pageNr; loadNrCount = 0; vm.perror("[saveConfFileCtrl.loadParams]" + ex.ToString()); } finally { } }
void itemAdd() { if(fileItemNr < itemLst.Count) { string str = itemLst[fileItemNr]; string[] strTmp = str.Split('\t'); if (strTmp.Length == 2) { loadFileItemCtrl item = new loadFileItemCtrl((fileItemNr + 1).ToString(), strTmp[0], "--"); itemCtrlLst.Add(item); cvsValueLst.Children.Add(item); Canvas.SetTop(item, (cvsValueLst.Children.Count - 1) * 20); } else { loadFileItemCtrl item = new loadFileItemCtrl(cvsValueLst.Children.Count.ToString(), str, "--"); itemCtrlLst.Add(item); cvsValueLst.Children.Add(item); Canvas.SetTop(item, (cvsValueLst.Children.Count - 1) * 20); } if (fileItemNr > 85) { double newTop = Canvas.GetTop(cvsValueLst) - 20; Canvas.SetTop(cvsValueLst, newTop); lbCurPage.Content = ((int)(newTop / -85 / 20 + 1)).ToString() + "/" + pageNr; } fileItemNr++; progressBarShow.Value = fileItemNr * 100.0 / itemLst.Count; lbPerShow.Content = progressBarShow.Value.ToString("00.0") + "%"; } else { dtShow.Stop(); progressBarShow.Visibility = Visibility.Hidden; lbPerShow.Visibility = Visibility.Hidden; lbPerShow.Content = "0%"; cvsValueLst.Height = fileItemNr * 20; Canvas.SetTop(cvsValueLst, 0); lbCurPage.Content = "1/" + pageNr; } }
private void loadParams() { try { int addr_int = 0; if (curFocusNr < itemLst.Count) { if (curItem != null) curItem.focusState = false; curItem = cvsValueLst.Children[curFocusNr] as loadFileItemCtrl; progressLoad.Value = (curFocusNr + 1) * 100.0 / itemLst.Count; lbPer.Content = progressLoad.Value.ToString("0.0") + "%"; curItem.focusState = true; string[] strtmp = curItem.addr.Split('.'); if (strtmp.Length == 2) { addr_int = -1; if (!LinkMgr.getObjPlcAddr(curItem.addr, ref addr_int, strtmp[0])) { curItem.flagLoadOk = false; throw new Exception("get " + curItem.addr + " addr_int error!"); } if (addr_int == -1 || addr_int == 0) { curItem.flagLoadOk = false; } if (curItem.value != "--") { if (Lasal32.LslWriteToSvr(addr_int, Int32.Parse(curItem.value))) { int tmp = 2; if (Lasal32.LslReadFromSvr(addr_int, ref tmp)) { if (tmp == -1) { curItem.flagLoadOk = false; throw new Exception("write " + curItem.addr + " error!"); } curItem.flagLoadOk = true; loadNrCount++; if (curFocusNr > 85) { double newTop = Canvas.GetTop(cvsValueLst) - 20; Canvas.SetTop(cvsValueLst, newTop); lbCurPage.Content = ((int)(newTop / -85 / 20 + 1)).ToString() + "/" + pageNr; } //vm.debug((pageStartNr + curFocusNr) + " : " + addrLst[pageStartNr + curFocusNr]); } else { curItem.flagLoadOk = false; throw new Exception("get " + curItem.addr + " value error!"); } } } else { curItem.flagLoadOk = false; } } curLstNr++; curFocusNr++; } else { if (curItem != null) curItem.focusState = false; curItem = null; curFocusNr = 0; curStep = 2; } } catch (Exception ex) { if (curItem != null) curItem.focusState = false; curLstNr = 0; curItem = null; dtLoad.Stop(); MessageBox.Show("Load error! load " + loadNrCount + "values"); Canvas.SetTop(cvsValueLst, 0); lbCurPage.Content = "1/" + pageNr; loadNrCount = 0; vm.perror("[loadConfFileCtrl.loadParams]" + ex.ToString()); } }