Example #1
0
        static public List <WeightSortData> GetListWeightSortData(bool bForceReread)
        {
            if (lstWeightSort != null && !bForceReread)
            {
                return(lstWeightSort);
            }
            else
            {
                lstWeightSort = new List <WeightSortData>();
            }

            string strFileFolder = strPath + "weightCategory";

            if (Directory.Exists(strFileFolder))
            {
                string[] strArrayFolder = Directory.GetDirectories(strFileFolder);

                if (strArrayFolder != null && strArrayFolder.Length > 0)
                {
                    for (int i = 0; i < strArrayFolder.Length; i++)
                    {
                        int      index        = strArrayFolder[i].LastIndexOf("\\");
                        string   strSortName  = strArrayFolder[i].Substring(index + 1, strArrayFolder[i].Length - index - 1);
                        string[] strArrayFile = Directory.GetFiles(strArrayFolder[i], strSortName + ".hcc");

                        if (strArrayFile.Length > 0)
                        {
                            lstWeightSort.Add(WeightSortData.GetSortData(strArrayFile[0]).Clone());
                        }
                    }
                }
            }

            return(lstWeightSort);
        }
Example #2
0
        static public bool SaveHccFile(WeightSortData ws, bool bOverWritePrompt)
        {
            string filepath = strPath + "weightCategory\\" + ws.sortName + "\\" + ws.sortName + ".hcc";

            if (bOverWritePrompt)
            {
                if (System.IO.File.Exists(filepath))
                {
                    string msg = "文件\"" + ws.sortName + ".hcc\"" + "已存在,是否继续并覆盖该文件?\r\n如果覆盖可能会导致该分类下的算法文件不可用!";
                    if (MessageBox.Show(msg, "分类文件已存在", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            string strWeightSortFolder = strPath + "weightCategory\\" + ws.sortName;

            if (!System.IO.Directory.Exists(strWeightSortFolder))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(strWeightSortFolder);
                }
                catch
                {
                    MessageBox.Show("创建分类目录失败!");
                    return(false);
                }
            }

            return(SaveHccFile(ws, filepath, false));
        }
Example #3
0
        /// <summary>
        /// 确认按钮单击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (this.weightResultTree.SelectedNode == null)
            {
                return;
            }
            int i = Convert.ToInt16(this.weightResultTree.SelectedNode.ToolTipText);

            if (flag == 0)
            {
                WeightArithmetic wa = mainForm.designProjectData.lstWeightArithmetic[i];
                ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(wa.ExportDataToWeightSort(), 1);
            }
            else if (flag == 1)
            {
                WeightAdjustmentResultData ward = mainForm.designProjectData.lstAdjustmentResultData[i];
                ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(ward.weightAdjustData, 1);
            }
            else if (flag == 2)
            {
                WeightSortData wsd = WeightSortData.clsStringToWeightSortData(lstTypeWeight[i].MainSystem_Name);
                ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(wsd, 1);
            }
            else if (flag == 3)
            {
                WeightSortData wsd = WeightSortData.clsStringToWeightSortData(lstWeightDesign[i].MainSystem_Name);
                ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(wsd, 1);
            }
            this.Close();
        }
        private WeightDesignData GetWeightDesignData()
        {
            if (dataForm == null)
            {
                dataForm = new WeightDataMangeForm();
            }

            WeightDesignData data = new WeightDesignData();

            data.Id = bllWeightDesign.GetMaxId();
            data.DesignData_Name      = txtDesignDataName.Text;
            data.DesignData_Submitter = txtDesignDataSumlieter.Text;
            data.Helicopter_Name      = txtHelicopterName.Text;
            data.DataRemark           = txtDagtaRemark.Text;
            data.LastModify_Time      = DateTime.Now.ToString();
            data.DesignTaking_Weight  = (txtDesignTakingWeight.Text == string.Empty ? 0 : Convert.ToDouble(txtDesignTakingWeight.Text));
            data.MainSystem_Name      = string.Empty;
            if (weightArithmetic != null)
            {
                WeightSortData sortData = weightArithmetic.ExportDataToWeightSort();
                data.MainSystem_Name = WeightDataMangeForm.GetMainSystemWeight(sortData);
            }
            if (adjustData != null)
            {
                WeightSortData sortData = adjustData.weightAdjustData;
                data.MainSystem_Name = WeightDataMangeForm.GetMainSystemWeight(sortData);
            }
            return(data);
        }
Example #5
0
        /// <summary>
        ///xls文件转换成WeightSortData类型
        /// </summary>
        /// <param name="strFilePath">文件路径</param>
        /// <returns>返回WeightSortData类型</returns>
        public static WeightSortData GetXlsImportSortData(string strFilePath)
        {
            WeightSortData sortData = null;

            try
            {
                if (File.Exists(strFilePath))
                {
                    ExcelLib OpExcel = new ExcelLib();
                    //指定操作的文件
                    OpExcel.OpenFileName = strFilePath;
                    //打开文件
                    if (OpExcel.OpenExcelFile() == false)
                    {
                        return(sortData);
                    }
                    //取得所有的工作表名称
                    string[] strSheetsName = OpExcel.getWorkSheetsName();

                    //默认操作第一张表
                    OpExcel.SetActiveWorkSheet(1);
                    System.Data.DataTable table;
                    table = OpExcel.getAllCellsValue();
                    OpExcel.CloseExcelApplication();

                    int count = table.Rows.Count;
                    if (count > 0)
                    {
                        sortData          = new WeightSortData();
                        sortData.sortName = table.Rows[0][0].ToString();

                        List <WeightData> lstWeightData = new List <WeightData>();
                        for (int i = 0; i < count; i++)
                        {
                            WeightData data = new WeightData();

                            data.nID         = Convert.ToInt32(table.Rows[i][1].ToString());
                            data.weightName  = table.Rows[i][2].ToString();
                            data.weightValue = Convert.ToDouble(table.Rows[i][4].ToString());
                            data.strRemark   = table.Rows[i][5].ToString();
                            data.nParentID   = Convert.ToInt32(table.Rows[i][6].ToString());

                            lstWeightData.Add(data);
                        }
                        sortData.lstWeightData = lstWeightData;
                    }
                }
            }
            catch
            {
                XLog.Write("导入文件\"" + strFilePath + "\"格式错误");
                MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误");
                return(null);
            }
            return(sortData);
        }
        /// <summary>
        /// 获取重量分类
        /// </summary>
        /// <returns></returns>
        private WeightSortData GetWeightSortData()
        {
            WeightSortData sortData = null;

            //当前重量设计数据

            if (selNode.Parent.Text == "重量设计结果列表")
            {
                for (int i = 0; i < designProject.lstWeightArithmetic.Count; i++)
                {
                    if (selNode.ToolTipText == i.ToString())
                    {
                        sortData = designProject.lstWeightArithmetic[i].ExportDataToWeightSort();
                    }
                }
            }

            //重量调整结果数据
            if (selNode.Parent.Text == "重量调整结果列表")
            {
                for (int i = 0; i < designProject.lstAdjustmentResultData.Count; i++)
                {
                    if (selNode.ToolTipText == i.ToString())
                    {
                        sortData = designProject.lstAdjustmentResultData[i].weightAdjustData;
                    }
                }
            }

            //型号重量数据库
            if (selNode.Parent.Text == "型号重量数据列表")
            {
                for (int i = 0; i < lstTypeWeight.Count; i++)
                {
                    if (selNode.Name == lstTypeWeight[i].Id.ToString())
                    {
                        sortData = WeightSortData.clsStringToWeightSortData(lstTypeWeight[i].MainSystem_Name);
                    }
                }
            }

            //重量设计数据库
            if (selNode.Parent.Text == "重量设计数据列表")
            {
                for (int i = 0; i < lstWeightDesign.Count; i++)
                {
                    if (selNode.Name == lstWeightDesign[i].Id.ToString())
                    {
                        sortData = WeightSortData.clsStringToWeightSortData(lstWeightDesign[i].MainSystem_Name);
                    }
                }
            }

            return(sortData);
        }
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, WeightSortData _weightSort, string str_Type)
        {
            InitializeComponent();
            weightSort = _weightSort;
            strType = str_Type;

            btnAddNode.Text = "添加子节点(&N)";

            SetPageData();
            IntiSettingButton();
        }
        /// <summary>
        /// 绑定重量结构树数据子节点
        /// </summary>
        private static void BindTreeNode(TreeNode ParentNode, int nParentID, WeightSortData wsd)
        {
            IEnumerable<WeightData> selection = from wd in wsd.lstWeightData where wd.nParentID == nParentID select wd;
            foreach (WeightData wd in selection)
            {
                TreeNode node = ParentNode.Nodes.Add(ParentNode.Name + "\\" + wd.weightName, wd.weightName);
                node.ToolTipText = wd.strRemark;

                BindTreeNode(node, wd.nID, wsd);
            }
        }
Example #9
0
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, WeightSortData _weightSort, string str_Type)
        {
            InitializeComponent();
            weightSort = _weightSort;
            strType    = str_Type;


            btnAddNode.Text = "添加子节点(&N)";

            SetPageData();
            IntiSettingButton();
        }
Example #10
0
        /// <summary>
        /// 绑定重量结构树数据子节点
        /// </summary>
        static private void BindTreeNode(TreeNode ParentNode, int nParentID, WeightSortData wsd)
        {
            IEnumerable <WeightData> selection = from wd in wsd.lstWeightData where wd.nParentID == nParentID select wd;

            foreach (WeightData wd in selection)
            {
                TreeNode node = ParentNode.Nodes.Add(ParentNode.Name + "\\" + wd.weightName, wd.weightName);
                node.ToolTipText = wd.strRemark;

                BindTreeNode(node, wd.nID, wsd);
            }
        }
Example #11
0
        /// <summary>
        /// 绑定重量分类数据
        /// </summary>
        public void BindWeightSortData()
        {
            treeViewWeightSort.Nodes.Clear();
            lstWeightSort = GetListWeightSortData();

            TreeNode rootnode1 = treeViewWeightSort.Nodes.Add("重量分类列表", "重量分类列表");

            if (lstWeightSort != null && lstWeightSort.Count > 0)
            {
                foreach (WeightSortData ws in lstWeightSort)
                {
                    TreeNode node = rootnode1.Nodes.Add(ws.sortName, ws.sortName);
                    node.Tag = ws;
                }
                rootnode1.Expand();
            }

            if (mainForm == null)
            {
                return;
            }
            DesignProjectData dpData = mainForm.designProjectData;

            if (dpData == null)
            {
                return;
            }
            if (dpData.lstWeightArithmetic != null)
            {
                TreeNode rootnode2 = treeViewWeightSort.Nodes.Add("设计结果列表", "设计结果列表");
                foreach (WeightArithmetic wa in dpData.lstWeightArithmetic)
                {
                    WeightSortData ws = wa.MakeNewWeightSort(false);
                    lstWeightSortDesignResult.Add(ws);

                    TreeNode node = rootnode2.Nodes.Add(wa.DataName, wa.DataName);
                    node.Tag = ws;
                }
                rootnode2.Expand();
            }
            if (dpData.lstAdjustmentResultData != null)
            {
                TreeNode rootnode3 = treeViewWeightSort.Nodes.Add("调整结果列表", "调整结果列表");
                foreach (WeightAdjustmentResultData wa in dpData.lstAdjustmentResultData)
                {
                    lstWeightSortDesignResult.Add(wa.basicWeightData);

                    TreeNode node = rootnode3.Nodes.Add(wa.WeightAdjustName, wa.WeightAdjustName);
                    node.Tag = wa.basicWeightData;
                }
                rootnode3.Expand();
            }
        }
Example #12
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            TreeNode node = this.WDMTree.SelectedNode;

            if (node == null || node.Level != 1)
            {
                MessageBox.Show("请选择机型");
                return;
            }

            WDMIntegrationModule.Air     air    = airs[Convert.ToInt32(node.Tag)];
            WDMIntegrationModule.TOper[] topers = WDMIntegrationModule.GetOpers(node.Name);
            //Random r = new Random();

            List <WeightData> lstWeightData = new List <WeightData>();
            WeightData        parentWD      = new WeightData();

            parentWD.weightName = air.MC;
            parentWD.nID        = 0;

            parentWD.nParentID = -1;
            lstWeightData.Add(parentWD);

            //int i = r.Next(10);
            double weightValueSum = 0;

            for (int i = 0; i < topers.Length; i++)
            {
                WDMIntegrationModule.TOper toper = topers[i];
                if (node.Name == air.ID)
                {
                    WeightData wd = new WeightData();
                    wd.weightName  = toper.MC;
                    wd.nID         = i + 1;// Convert.ToInt32(toper.ID);
                    wd.weightValue = this.actualDataRadio.Checked ?
                                     (toper.SCW == 0 && this.useTestData.Checked ?
                                      toper.ZTW : toper.SCW) : toper.ZTW;
                    wd.nParentID = 0;

                    // 添加重量数据至重量数据列表
                    lstWeightData.Add(wd);

                    weightValueSum += wd.weightValue;
                }
            }
            parentWD.weightValue = weightValueSum;
            WeightSortData wsd = new WeightSortData();

            wsd.lstWeightData = lstWeightData;
            ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(wsd, 2);

            this.Close();
        }
        /// <summary>
        /// 绑定重量结构树数据
        /// </summary>
        public static void BindTreeList(TreeView tree, WeightSortData wsd)
        {
            tree.Nodes.Clear();

            IEnumerable<WeightData> selection = from wd in wsd.lstWeightData where wd.nParentID == -1 select wd;
            foreach (WeightData wd in selection)
            {
                TreeNode node = tree.Nodes.Add(wd.weightName, wd.weightName);
                node.ToolTipText = wd.strRemark;

                BindTreeNode(node, wd.nID, wsd);
            }
        }
Example #14
0
        /// <summary>
        /// 绑定重量结构树数据
        /// </summary>
        static public void BindTreeList(TreeView tree, WeightSortData wsd)
        {
            tree.Nodes.Clear();

            IEnumerable <WeightData> selection = from wd in wsd.lstWeightData where wd.nParentID == -1 select wd;

            foreach (WeightData wd in selection)
            {
                TreeNode node = tree.Nodes.Add(wd.weightName, wd.weightName);
                node.ToolTipText = wd.strRemark;

                BindTreeNode(node, wd.nID, wsd);
            }
        }
Example #15
0
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string strFloder = strPath + "weightCategory" + "\\" + selNode.Name;

            if (!System.IO.Directory.Exists(strFloder))
            {
                MessageBox.Show("目录\"" + strFloder + "\"" + "不存在!");
                return;
            }

            string[] files = System.IO.Directory.GetFiles(strFloder, "*.WEM");

            if (files.Length > 0)
            {
                DialogResult result = MessageBox.Show("该分类下有算法文件!如果继续将把分类下的所有算法文件一起删除!是否继续?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result != DialogResult.Yes)
                {
                    return;
                }
                else
                {
                    Directory.Delete(strFloder, true);
                }
            }
            else
            {
                DialogResult result = MessageBox.Show("是否删除" + selNode.Name + "?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    Directory.Delete(strFloder, true);
                }
                else
                {
                    return;
                }
            }

            WeightSortData tempSortData = selNode.Tag as WeightSortData;

            if (tempSortData == null)
            {
                return;
            }

            lstWeightSort.Remove(tempSortData);

            treeViewWeightSort.Nodes[0].Nodes.Remove(selNode);

            XLog.Write("删除" + selNode.Name + "成功");
        }
Example #16
0
        /// <summary>
        /// 编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, EventArgs e)
        {
            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }

            string[] files = System.IO.Directory.GetFiles(strPath + "weightCategory" + "\\" + selNode.Name, "*.WEM");

            string strtype = (files.Length > 0) ? "readOnlyEdit" : "edit";

            WeightSortEditForm form = new WeightSortEditForm(this, weightSort, strtype);

            form.ShowDialog();
        }
Example #17
0
        /// <summary>
        /// 导出WeightSortData类型实例至XML/XLS文件
        /// </summary>
        /// <param name="sortData">WeightSortData类型</param>
        public static void ExportDataToDataFile(WeightSortData sortData)
        {
            if (sortData == null)
            {
                XLog.Write("没有数据不能导出");
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter           = "xml文件 (*.xml)|*.xml|Excel文件 (*.xls)|*.xls";
            dlg.OverwritePrompt  = true;
            dlg.FilterIndex      = 0;
            dlg.RestoreDirectory = true;
            dlg.FileName         = sortData.sortName;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string strFilePath = dlg.FileName;

                if (strFilePath.EndsWith(".xml"))
                {
                    List <string> lstContent = MainForm.GetDesignResultFlieContent(sortData);
                    CommonFunction.mWriteListStringToFile(strFilePath, lstContent);
                }

                if (strFilePath.EndsWith(".xls"))
                {
                    DataTable table  = MainForm.GetDesignResultTable(sortData);
                    int       result = XCommon.FileStatus.FileIsOpen(strFilePath);

                    if (result == 1)
                    {
                        MessageBox.Show("请关闭文件" + strFilePath + ",再导出");
                    }
                    else
                    {
                        CommonExcel commonExcel = new CommonExcel();
                        commonExcel.lstColumn = MainForm.GetDesignResultExcleCloumn();
                        commonExcel.CreateExcel("example", strFilePath, "sheet1", table);
                    }
                }

                XLog.Write("导出文件\"" + strFilePath + "\"成功");
            }
        }
        /// <summary>
        /// 判断是否为最后一个节点的重量数据
        /// </summary>
        /// <param name="weight"></param>
        /// <param name="weightSortData"></param>
        /// <returns></returns>
        private bool IsLastWeightNode(WeightData weight, WeightSortData weightSortData)
        {
            bool IsLast = true;

            if (weightSortData.lstWeightData.Count > 0)
            {
                foreach (WeightData data in weightSortData.lstWeightData)
                {
                    if (weight.nID == data.nParentID)
                    {
                        return(false);
                    }
                }
            }

            return(IsLast);
        }
        /// <summary>
        /// WeightSortData
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static WeightSortData clsStringToWeightSortData(string str)
        {
            // 创建临时重量分类数据对象
            WeightSortData tempWeightSortData = null;

            // 创建重量数据列表对象
            List<WeightData> lstWeightData = null;
            //判断是否为空字符串
            if (str == null || str == string.Empty)
            {
                return null;
            }
            // 新重量分类数据
            tempWeightSortData = new WeightSortData();
            lstWeightData = new List<WeightData>();
            string[] tempStrings = str.Split('|');
            foreach (string tempString in tempStrings)
            {
                if (tempString == tempStrings[0])
                {
                    tempWeightSortData.sortName = tempString;
                }
                else
                {
                    // 获取重量数据
                    string[] tempInnerStrings = tempString.Split('、');
                    if (tempInnerStrings.Length > 1)
                    {
                        // 创建重量数据对象
                        WeightData tempWeightData = new WeightData();

                        tempWeightData.weightName = tempInnerStrings[0];
                        tempWeightData.nID = Convert.ToInt32(tempInnerStrings[1]);
                        tempWeightData.weightValue = Convert.ToDouble(tempInnerStrings[3]);
                        tempWeightData.nParentID = Convert.ToInt32(tempInnerStrings[4]);

                        // 添加重量数据至重量数据列表
                        lstWeightData.Add(tempWeightData);
                    }
                }
            }
            // 添加重量数据列表至重量分类
            tempWeightSortData.lstWeightData = lstWeightData;
            return tempWeightSortData;
        }
Example #20
0
        /// <summary>
        /// 导入事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.RestoreDirectory = true;
            fileDialog.Filter           = "hcc文件 (*.hcc)|*.hcc";
            if (fileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            WeightSortData sortData = WeightSortData.GetSortData(fileDialog.FileName);

            if (sortData == null)
            {
                MessageBox.Show("错误的分类文件!");
                return;
            }

            bool boverwrite = treeViewWeightSort.Nodes[0].Nodes.ContainsKey(sortData.sortName);

            if (!SaveHccFile(sortData, boverwrite))
            {
                XLog.Write("导入失败!");
                return;
            }

            lstWeightSort.Add(sortData);
            if (!boverwrite)
            {
                RefreshTreeViewData();
            }

            XLog.Write("导入成功");

            foreach (TreeNode node in treeViewWeightSort.Nodes[0].Nodes)
            {
                if (node.Text == sortData.sortName)
                {
                    treeViewWeightSort.SelectedNode = node;
                }
            }
        }
        /// <summary>
        /// 获取基层节点的重量数据列表
        /// </summary>
        public List <WeightData> GetListWeightData(WeightSortData sortData)
        {
            List <WeightData> lstWeightData = null;

            if (sortData != null && sortData.lstWeightData != null && sortData.lstWeightData.Count > 0)
            {
                lstWeightData = new List <WeightData>();

                foreach (WeightData data in sortData.lstWeightData)
                {
                    if (IsLastWeightNode(data, sortData))
                    {
                        lstWeightData.Add(data);
                    }
                }
            }

            return(lstWeightData);
        }
        /// <summary>
        /// 设置修正因子数据
        /// </summary>
        private void SetCalculateRatioData(string strRatioType)
        {
            ratioType = strRatioType;

            List <ParaData> lstPara = WeightSortData.GetlstCalculateRatio(strRatioType, importSortData1, importSortData2);

            lstCalculateRatio = lstPara;
            if (gridWeightData.Rows.Count > 0 && lstPara != null && lstPara.Count > 0)
            {
                for (int i = 0; i < gridWeightData.Rows.Count; i++)
                {
                    gridWeightData.Rows[i].Cells[3].Value = Math.Round(lstPara[i].paraValue, digit);
                    if (lstPara[i].paraValue < 0)
                    {
                        gridWeightData.Rows[i].Cells[3].Style.ForeColor = Color.Red;
                    }
                }
            }
        }
Example #23
0
        /// <summary>
        /// 导出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (selNode == null || selNode.Level == 0)
            {
                XLog.Write("请选择重量分类");
                return;
            }

            //WeightSortData weightSortData = new WeightSortData();

            //foreach (WeightSortData sortData in lstWeightSort)
            //{
            //    if (selNode.Text == sortData.sortName)
            //    {
            //        weightSortData = sortData;
            //    }
            //}

            WeightSortData weightSortData = selNode.Tag as WeightSortData;

            if (weightSortData == null)
            {
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter           = "hcc文件 (*.hcc)|*.hcc";
            dlg.OverwritePrompt  = false;
            dlg.FilterIndex      = 0;
            dlg.RestoreDirectory = true;
            dlg.FileName         = weightSortData.sortName;// selNode.Text;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string strFilePath = dlg.FileName;
                if (SaveHccFile(weightSortData, strFilePath, true))
                {
                    XLog.Write("导出成功");
                }
            }
        }
Example #24
0
        /// <summary>
        /// 基于新建
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnJYNew_Click(object sender, EventArgs e)
        {
            if (selNode == null || selNode.Level == 0)
            {
                XCommon.XLog.Write("请选择重量分类");
                return;
            }

            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }

            WeightSortEditForm form = new WeightSortEditForm(this, weightSort, "JYNew");

            if (form.ShowDialog() == DialogResult.OK)
            {
                RefreshTreeViewData();
            }
        }
Example #25
0
        /// <summary>
        /// 导入基准/评估重量数据文件,根据ToolStripMenuItem.Tag值判断类型(1:基准重量;2评估重量)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImportWeightDataFileMenuItem_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt16(((ToolStripMenuItem)sender).Tag);

            if (weightDataGridView.Rows.Count == 0 && i == 2)
            {
                MessageBox.Show("请先加载基准重量");
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c://"; //对话框的初始目录
            //要在对话框中显示的文件筛选器,例如,"文本文件(*.txt)|*.txt|所有文件(*.*)||*.*"
            openFileDialog.Filter = "XML文件|*.xml|Excel文件|*.xls";
            //在对话框中选择的文件筛选器的索引,如果选第一项就设为1
            openFileDialog.FilterIndex = 1;
            //控制对话框在关闭之前是否恢复当前目录
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog.FilterIndex == 1)
                {
                    this.weightSortData = CommonUtil.GetXmlImporSortData(openFileDialog.FileName);
                }
                else
                {
                    this.weightSortData = CommonUtil.GetXlsImportSortData(openFileDialog.FileName);
                }

                //if (i==1||(i==2&&InspectWeightName(weightSortData.lstWeightData))||MessageBox.Show("评估重量分类名称与基准重量分类名称不匹配,确认是否继续加载评估重量,不匹配值以0代替?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //{
                if (weightSortData != null)
                {
                    this.saveWeightDataGridView(weightSortData, i);
                }
                //}
            }
        }
        /// <summary>
        /// 修改重量数据2
        /// </summary>
        private void UpdataSortData2()
        {
            if (importSortData2 != null && importSortData2.lstWeightData.Count > 0)
            {
                for (int i = 0; i < gridWeightData.RowCount; i++)
                {
                    foreach (WeightData data in importSortData2.lstWeightData)
                    {
                        if (gridWeightData.Rows[i].Cells[2].ToolTipText == data.nID.ToString())
                        {
                            data.weightValue = Convert.ToDouble(gridWeightData.Rows[i].Cells[2].Value.ToString());
                        }
                    }
                }

                //求和
                foreach (WeightData data in importSortData2.lstWeightData)
                {
                    WeightSortData.GetSortDataTotal(data, importSortData2);
                }
            }
        }
Example #27
0
        /// <summary>
        /// 双击节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewWeightSort_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }
            string strFolderPath = strPath + "weightCategory" + "\\" + selNode.Name;

            if (Directory.Exists(strFolderPath))
            {
                string[] files   = System.IO.Directory.GetFiles(strFolderPath, "*.WEM");
                string   strtype = (files.Length > 0) ? "readOnlyEdit" : "edit";

                WeightSortEditForm form = new WeightSortEditForm(this, weightSort, strtype);
                form.ShowDialog();
            }
            else
            {
                XLog.Write("文件\"" + strFolderPath + "\"不存在");
            }
        }
        /// <summary>
        /// 导出基准重量数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportDatumFileMenuItem_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt16(((ToolStripMenuItem)sender).Tag);

            //WeightSortData wsd = new WeightSortData();
            //wsd.sortName = i == 1 ? "基准重量" : "评估重量";
            //wsd.lstWeightData = new List<WeightData>();
            //foreach (DataGridViewRow row in this.weightDataGridView.Rows)
            //{

            //    WeightData wd = new WeightData();
            //    wd.weightName = row.Cells[0].Value.ToString();
            //    wd.weightValue=Convert.ToDouble(row.Cells[i].Value);
            //    wsd.lstWeightData.Add(wd);
            //}
            if (this.weightSortData == null)
            {
                this.weightSortData = new WeightSortData();
                this.weightSortData.lstWeightData = i == 1 ? this.weightAssessResult.datumWeightDataList :
                                                    this.weightAssessResult.assessWeightDataList;
            }
            this.weightSortData.sortName = i == 1 ? "基准重量" : "评估重量";
            CommonUtil.ExportDataToDataFile(this.weightSortData);
        }
        public static bool SaveHccFile(WeightSortData ws, bool bOverWritePrompt)
        {
            string filepath = strPath + "weightCategory\\" + ws.sortName + "\\" + ws.sortName + ".hcc";

            if (bOverWritePrompt)
            {
                if (System.IO.File.Exists(filepath))
                {
                    string msg = "文件\"" + ws.sortName + ".hcc\"" + "已存在,是否继续并覆盖该文件?\r\n如果覆盖可能会导致该分类下的算法文件不可用!";
                    if (MessageBox.Show(msg, "分类文件已存在", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return false;
                    }
                }
            }

            string strWeightSortFolder = strPath + "weightCategory\\" + ws.sortName;
            if (!System.IO.Directory.Exists(strWeightSortFolder))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(strWeightSortFolder);
                }
                catch
                {
                    MessageBox.Show("创建分类目录失败!");
                    return false;
                }
            }

            return SaveHccFile(ws, filepath, false);
        }
 /// <summary>
 /// 获取与列表相同的重量分类
 /// </summary>
 /// <param name="sortData"></param>
 /// <returns></returns>
 private WeightSortData GetSameWeightSort(WeightSortData sortData)
 {
     WeightSortData sort = null;
     if (lstWeightSortData != null && lstWeightSortData.Count > 0 && sortData != null)
     {
         foreach (WeightSortData data in lstWeightSortData)
         {
             if (WeightSortData.blIsSame(sortData, data))
             {
                 sort = new WeightSortData();
                 sort = data;
                 return sort;
             }
         }
     }
     return sort;
 }
Example #31
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            TreeNode node = this.WDMTree.SelectedNode;
            if (node==null||node.Level != 1)
            {
                MessageBox.Show("请选择机型");
                return;
            }

            WDMIntegrationModule.Air air = airs[Convert.ToInt32(node.Tag)];
            WDMIntegrationModule.TOper[] topers = WDMIntegrationModule.GetOpers(node.Name);
            //Random r = new Random();

            List<WeightData> lstWeightData = new List<WeightData>();
            WeightData parentWD = new WeightData();
            parentWD.weightName = air.MC;
            parentWD.nID = 0;

            parentWD.nParentID = -1;
            lstWeightData.Add(parentWD);

            //int i = r.Next(10);
            double weightValueSum = 0;
            for(int i=0;i<topers.Length;i++)
            {
                WDMIntegrationModule.TOper toper = topers[i];
                if (node.Name == air.ID)
                {
                    WeightData wd = new WeightData();
                    wd.weightName = toper.MC;
                    wd.nID = i+1;// Convert.ToInt32(toper.ID);
                    wd.weightValue = this.actualDataRadio.Checked ?
                        (toper.SCW == 0 && this.useTestData.Checked ?
                        toper.ZTW : toper.SCW) : toper.ZTW;
                    wd.nParentID = 0;

                    // 添加重量数据至重量数据列表
                    lstWeightData.Add(wd);

                    weightValueSum += wd.weightValue;
                }
            }
            parentWD.weightValue = weightValueSum;
            WeightSortData wsd = new WeightSortData();
            wsd.lstWeightData = lstWeightData;
            ((WeightAssessmentForm)this.Owner).saveWeightDataGridView(wsd, 2);

            this.Close();
        }
        /// <summary>
        /// 导入事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_ImptCrtWghtDsgnRst_Click(object sender, EventArgs e)
        {
            if (selNode == null || selNode.Level == 0)
            {
                MessageBox.Show("请选择数据");
                return;
            }

            //绑定列表数据
            WeightSortData sortData = GetWeightSortData();

            if (sortData == null || sortData.lstWeightData.Count == 0)
            {
                MessageBox.Show("没有重量数据,不能导入");
                return;
            }


            if ((form.lstJHRatio != null && form.lstJHRatio.Count > 0) ||
                (form.lstTeachRatio != null && form.lstTeachRatio.Count > 0))
            {
                //判断导入基础重量分类一致
                if (WeightSortData.blIsSame(form.basicWeightData, sortData) == false)
                {
                    DialogResult result = MessageBox.Show("当前选择会清空当前数据?", "继续提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (result == DialogResult.Yes)
                    {
                        form.InitializeData();

                        form.BindWeightData(sortData);

                        List <WeightData> lstBasicWeightData = WeightSortData.GetListWeightData(form.basicWeightData);
                        form.SetBasicWeightData(lstBasicWeightData);
                        form.SetRatioGridView(lstBasicWeightData);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    form.InitializeData();
                    form.BindWeightData(sortData);
                    List <WeightData> lstWeightData = WeightSortData.GetListWeightData(sortData);
                    form.SetBasicWeightData(lstWeightData);
                    form.SetRatioGridView(lstWeightData);
                }
            }
            else
            {
                //设置基础重量数据
                form.BindWeightData(sortData);
                List <WeightData> lstWeightData = WeightSortData.GetListWeightData(sortData);
                form.SetBasicWeightData(lstWeightData);
                form.SetRatioGridView(lstWeightData);
            }

            this.Close();
        }
Example #33
0
        /// <summary>
        /// Xml文件转换成WeightSortData类型
        /// </summary>
        /// <param name="strPath">文件路径</param>
        /// <returns>返回WeightSortData类型</returns>
        public static WeightSortData GetXmlImporSortData(string strPath)
        {
            WeightSortData sortData = null;

            try
            {
                if (!File.Exists(strPath))
                {
                    return sortData;
                }
                sortData = new WeightSortData();

                string path = string.Empty;
                XmlNode node = null;

                XmlDocument doc = new XmlDocument();
                doc.Load(strPath);

                //重量分类名称
                path = "重量分类/重量分类名称";
                node = doc.SelectSingleNode(path);
                sortData.sortName = (node == null ? string.Empty : node.InnerText);

                //重量分类备注
                path = "重量分类/重量分类备注";
                node = doc.SelectSingleNode(path);
                sortData.strRemark = (node == null ? string.Empty : node.InnerText);

                //重量列表
                path = "重量分类/重量数据列表";
                node = doc.SelectSingleNode(path);

                XmlNodeList nodelist = (node == null ? null : node.ChildNodes);

                if (nodelist != null && nodelist.Count > 0)
                {
                    List<WeightData> lstWeightData = new List<WeightData>();
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        WeightData data = new WeightData();

                        data.nID = Convert.ToInt32(childNode.ChildNodes[0].InnerText);
                        data.weightName = childNode.ChildNodes[1].InnerText;
                        data.weightValue = Convert.ToDouble(childNode.ChildNodes[3].InnerText);
                        data.strRemark = childNode.ChildNodes[4].InnerText;
                        data.nParentID = Convert.ToInt32(childNode.ChildNodes[5].InnerText);

                        lstWeightData.Add(data);
                    }
                    sortData.lstWeightData = lstWeightData;
                }
            }
            catch
            {
                XLog.Write("导入文件\"" + strPath + "\"格式错误");
                MessageBox.Show("导入文件\"" + strPath + "\"格式错误");
                return null;
            }
            return sortData;
        }
Example #34
0
        /// <summary>
        /// 导出WeightSortData类型实例至XML/XLS文件
        /// </summary>
        /// <param name="sortData">WeightSortData类型</param>
        public static void ExportDataToDataFile(WeightSortData sortData)
        {
            if (sortData == null)
            {
                XLog.Write("没有数据不能导出");
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "xml文件 (*.xml)|*.xml|Excel文件 (*.xls)|*.xls";
            dlg.OverwritePrompt = true;
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.FileName = sortData.sortName;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string strFilePath = dlg.FileName;

                if (strFilePath.EndsWith(".xml"))
                {
                    List<string> lstContent = MainForm.GetDesignResultFlieContent(sortData);
                    CommonFunction.mWriteListStringToFile(strFilePath, lstContent);
                }

                if (strFilePath.EndsWith(".xls"))
                {
                    DataTable table = MainForm.GetDesignResultTable(sortData);
                    int result = XCommon.FileStatus.FileIsOpen(strFilePath);

                    if (result == 1)
                    {
                        MessageBox.Show("请关闭文件" + strFilePath + ",再导出");
                    }
                    else
                    {
                        CommonExcel commonExcel = new CommonExcel();
                        commonExcel.lstColumn = MainForm.GetDesignResultExcleCloumn();
                        commonExcel.CreateExcel("example", strFilePath, "sheet1", table);
                    }
                }

                XLog.Write("导出文件\"" + strFilePath + "\"成功");
            }
        }
        /// <summary>
        /// 导入基准/评估重量数据文件,根据ToolStripMenuItem.Tag值判断类型(1:基准重量;2评估重量)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImportWeightDataFileMenuItem_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt16(((ToolStripMenuItem)sender).Tag);
            if (weightDataGridView.Rows.Count == 0 && i == 2)
            {
                MessageBox.Show("请先加载基准重量");
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "c://"; //对话框的初始目录
            //要在对话框中显示的文件筛选器,例如,"文本文件(*.txt)|*.txt|所有文件(*.*)||*.*"
            openFileDialog.Filter = "XML文件|*.xml|Excel文件|*.xls";
            //在对话框中选择的文件筛选器的索引,如果选第一项就设为1
            openFileDialog.FilterIndex = 1;
            //控制对话框在关闭之前是否恢复当前目录
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog.FilterIndex == 1)
                {
                    this.weightSortData = CommonUtil.GetXmlImporSortData(openFileDialog.FileName);
                }
                else
                {
                    this.weightSortData = CommonUtil.GetXlsImportSortData(openFileDialog.FileName);
                }

                //if (i==1||(i==2&&InspectWeightName(weightSortData.lstWeightData))||MessageBox.Show("评估重量分类名称与基准重量分类名称不匹配,确认是否继续加载评估重量,不匹配值以0代替?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //{
                if (weightSortData != null)
                {
                    this.saveWeightDataGridView(weightSortData, i);
                }
                //}
            }
        }
        /// <summary>
        /// 保存基准/评估重量数据
        /// </summary>
        /// <param name="wsd"></param>
        /// <param name="i">1:基准重量;2:评估重量</param>
        public void saveWeightDataGridView(WeightSortData wsd, int i)
        {
            this.weightSortData = wsd;//临时存储,方便数据导出.

            if (i == 1)
            {
                for (int k = 0; k < wsd.lstWeightData.Count; k++)
                {
                    if (wsd.lstWeightData[k].weightValue == 0)
                    {
                        MessageBox.Show("基准数据中不能存在为0的重量值!");
                        return;
                    }
                }
            }

            if (wsd == null)
            {
                return;
            }

            if (!InspectWeightName(wsd.lstWeightData))
            {
                if (i == 1 && this.weightDataGridView.Rows.Count != 0)
                {
                    //对已生成的评估结果上重新导入基准重量
                    if (MessageBox.Show("待导入的基准重量分类名称与已导入表格的名称不匹配,确认是否继续,并清空评估重量及相关参数?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.weightDataGridView.Rows.Clear();
                        if (this.weightAssessResult == null)
                        {
                            this.weightAssessResult = new WeightAssessResult();
                        }
                        this.btnPreferences.Enabled = false;
                    }
                    else
                    {
                        return;
                    }
                }
                else if (i == 2)
                {
                    MessageBox.Show("待导入的评估重量不匹配");
                    return;
                }

            }

            //判断是否首次加载重量数据.(判断重量分类"节点名称"是否加载完成,否则进行加载节点名称.)
            if (weightDataGridView.Rows.Count == 0)
            {
                this.weightAssessResult.weightAssessParamList = new List<WeightAssessParameter>();
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {

                        int index = this.weightDataGridView.Rows.Add();
                        this.weightDataGridView.Rows[index].Cells[0].Value = wd.weightName;

                        WeightAssessParameter wa = new WeightAssessParameter();
                        this.weightAssessResult.weightAssessParamList.Add(wa);
                        wa.weightName = wd.weightName;
                        wa.minValue = 0.8;//初始化最小值
                        wa.maxValue = 1.2;//初始化最大值
                    }
                }
            }

            //加载基准重量数据或评估重量数据
            for (int j = 0; j < this.weightDataGridView.Rows.Count; j++)
            {
                DataGridViewRow row = this.weightDataGridView.Rows[j];
                foreach (WeightData wd in wsd.lstWeightData)
                {
                    if (wd.nParentID == 0 && wd.weightName != null)
                    {
                        if (row.Cells[0].Value.Equals(wd.weightName))
                        {
                            row.Cells[i].Value = Math.Round(wd.weightValue, 6);

                            WeightAssessParameter wa = this.weightAssessResult.weightAssessParamList[j];
                            wa.weightUnit = wd.weightUnit;
                            if (i == 1)
                            {
                                wa.datumWeight = Math.Round(wd.weightValue, 6);

                                //当i==1(赋值基准重量)时,计算初始化权重值.
                                wa.weightedValue = Math.Round(wd.weightValue / weightAssessResult.datumWeightTotal, 6);
                            }
                            else if (i == 2)
                            {
                                wa.assessWeight = Math.Round(wd.weightValue, 6);
                            }
                            break;
                        }
                        else
                        {
                            row.Cells[i].Value = 0;
                        }
                    }
                    else if (wd.nParentID == -1 && i == 1)
                    {
                        //存储基准重量数据对象
                        this.weightAssessResult.datumWeightDataList = wsd.lstWeightData;

                        //计算基准重量总值
                        this.weightAssessResult.datumWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启基准重量导出菜单
                        this.ExportDatumFileMenuItem.Enabled = true;

                        //开启评估重量菜单
                        this.AssessWeightMenuItem.Enabled = true;
                    }
                    else if (wd.nParentID == -1 && i == 2)
                    {

                        ////评估数据对象进行排序
                        List<WeightData> temList = new List<WeightData>();
                        foreach (WeightData datumWD in this.weightAssessResult.datumWeightDataList)
                        {
                            for (int k = 0; k < wsd.lstWeightData.Count; k++)
                            {
                                WeightData assessWD = wsd.lstWeightData[k];
                                if (datumWD.weightName == assessWD.weightName && assessWD.nParentID != -1)
                                {
                                    temList.Add(assessWD);
                                    break;
                                }
                                else if (datumWD.nParentID == -1 && assessWD.nParentID == -1)
                                {
                                    temList.Add(assessWD);
                                    break;
                                }
                            }
                        }
                        wsd.lstWeightData = temList;

                        //存储评估数据重量对象
                        this.weightAssessResult.assessWeightDataList = wsd.lstWeightData;

                        //计算评估重量总值
                        this.weightAssessResult.assessWeightTotal = Math.Round(wd.weightValue, 6);

                        //开启评估重量导出菜单
                        this.ExprotAssessFileMenuItem.Enabled = true;

                        //开启重量评估参数配置按钮菜单
                        this.btnPreferences.Enabled = true;
                    }
                }
            }
        }
        public static bool SaveHccFile(WeightSortData ws, string filepath, bool bOverWritePrompt)
        {
            if (bOverWritePrompt)
            {
                if (System.IO.File.Exists(filepath))
                {
                    string msg = "文件\"" + ws.sortName + ".hcc\"" + "已存在,是否继续并覆盖该文件?";
                    if (MessageBox.Show(msg, "分类文件已存在", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return false;
                    }
                }
            }

            XmlTextWriter writeXml = null;
            try
            {
                writeXml = new XmlTextWriter(filepath, Encoding.GetEncoding("gb2312"));
            }
            catch
            {
                MessageBox.Show("创建或写入文件失败!");
                return false;
            }

            writeXml.Formatting = Formatting.Indented;
            writeXml.Indentation = 5;
            writeXml.WriteStartDocument();

            writeXml.WriteStartElement("重量分类");
            {
                writeXml.WriteStartElement("重量分类名称");
                writeXml.WriteString(ws.sortName);
                writeXml.WriteEndElement();
                writeXml.WriteStartElement("重量分类备注");
                writeXml.WriteString("");
                writeXml.WriteEndElement();

                writeXml.WriteStartElement("重量数据列表");
                {
                    foreach (WeightData wd in ws.lstWeightData)
                    {
                        writeXml.WriteStartElement("重量数据");
                        {
                            writeXml.WriteStartElement("ID");
                            writeXml.WriteValue(wd.nID);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量名称");
                            writeXml.WriteString(wd.weightName);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量单位");
                            writeXml.WriteString(wd.weightUnit);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量数值");
                            writeXml.WriteValue(wd.weightValue);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("备注");
                            writeXml.WriteString(wd.strRemark);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("PARENTID");
                            writeXml.WriteValue(wd.nParentID);
                            writeXml.WriteEndElement();
                        }
                        writeXml.WriteEndElement();
                    }
                }
                writeXml.WriteEndElement();
            }
            writeXml.WriteEndElement();
            writeXml.Close();

            return true;
        }
        /// <summary>
        /// 确定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            string strSortName = txtWeightSortName.Text.Trim();

            if (strSortName.Length == 0)
            {
                MessageBox.Show("重量分类名称为空!");
                return;
            }
            else
            {
                if (Verification.IsCheckString(strSortName))
                {
                    MessageBox.Show("重量分类名称含有非法字符!");
                    return;
                }
            }

            if (treeViewWeightStructure.Nodes.Count == 0)
            {
                MessageBox.Show("重量分类必须有根节点!");
                return;
            }

            WeightSortData ws = null;
            if (strType == "edit" || strType == "readOnlyEdit")
            {
                foreach (WeightSortData tempwsd in WeightSortManageForm.GetListWeightSortData())
                {
                    if (tempwsd.sortName == strSortName)
                    {
                        ws = tempwsd;
                        ws.lstWeightData.Clear();
                    }
                }
                if (ws == null)
                {
                    MessageBox.Show("未知错误!");
                    return;
                }
            }
            else
            {
                ws = new WeightSortData();
            }
            ws.sortName = strSortName;

            int nNodeID = -1;
            for (int k = 0; k < treeViewWeightStructure.Nodes.Count; k++)
            {
                TreeNode subnode = treeViewWeightStructure.Nodes[k];
                List<WeightData> lstWeightData = ws.lstWeightData;

                //添加根节点
                WeightData rootWeightData = new WeightData();
                rootWeightData.nID = ++nNodeID;
                rootWeightData.weightName = subnode.Text;
                rootWeightData.strRemark = subnode.ToolTipText;
                rootWeightData.nParentID = -1;

                lstWeightData.Add(rootWeightData);

                WriteTreeDataToList(subnode, ref lstWeightData, ref nNodeID);
            }

            if (WeightSortManageForm.SaveHccFile(ws, strType != "edit" && strType != "readOnlyEdit"))
            {
                if (strType == "edit" || strType == "readOnlyEdit")
                {
                    XLog.Write("编辑重量分类成功");
                }
                else
                {
                    if (strType == "new")
                    {
                        XLog.Write("新建重量分类成功");
                    }
                    if (strType == "JYNew")
                    {
                        XLog.Write("基于新建重量分类成功");
                    }
                    WeightSortManageForm.GetListWeightSortData().Add(ws);
                }
                DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        /// <summary>
        /// 编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, EventArgs e)
        {
            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }

            string[] files = System.IO.Directory.GetFiles(strPath + "weightCategory" + "\\" + selNode.Name, "*.WEM");

            string strtype = (files.Length > 0) ? "readOnlyEdit" : "edit";

            WeightSortEditForm form = new WeightSortEditForm(this, weightSort, strtype);
            form.ShowDialog();
        }
 public void BindWeightData(WeightSortData sortData)
 {
     treeViewSort.Nodes.Clear();
     MainForm.BindWeightDesignSortNoValue(sortData, treeViewSort);
 }
        /// <summary>
        /// 求重量分类的和
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sortData"></param>
        /// <returns></returns>
        public static void GetSortDataTotal(WeightData data, WeightSortData sortData)
        {
            IEnumerable<WeightData> selection = from wd in sortData.lstWeightData where wd.nParentID == data.nID select wd;

            if (selection.Count() > 0)
            {
                foreach (WeightData weight in selection)
                {
                    GetSortDataTotal(weight, sortData);
                }
            }
            else
            {
                IEnumerable<WeightData> parentSelection = from wd in sortData.lstWeightData where wd.nID == data.nParentID select wd;
                IEnumerable<WeightData> childSelection = from wd in sortData.lstWeightData where wd.nParentID == data.nParentID select wd;

                double childValue = 0;
                foreach (WeightData weight in childSelection)
                {
                    childValue += weight.weightValue;
                }

                if (parentSelection.Count() > 0)
                {
                    foreach (WeightData weight in sortData.lstWeightData)
                    {
                        if (weight.nID == parentSelection.ToList()[0].nID)
                        {
                            weight.weightValue = childValue;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 导出基准重量数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportDatumFileMenuItem_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt16(((ToolStripMenuItem)sender).Tag);
            //WeightSortData wsd = new WeightSortData();
            //wsd.sortName = i == 1 ? "基准重量" : "评估重量";
            //wsd.lstWeightData = new List<WeightData>();
            //foreach (DataGridViewRow row in this.weightDataGridView.Rows)
            //{

            //    WeightData wd = new WeightData();
            //    wd.weightName = row.Cells[0].Value.ToString();
            //    wd.weightValue=Convert.ToDouble(row.Cells[i].Value);
            //    wsd.lstWeightData.Add(wd);
            //}
            if (this.weightSortData == null)
            {
                this.weightSortData = new WeightSortData();
                this.weightSortData.lstWeightData = i == 1 ? this.weightAssessResult.datumWeightDataList :
                    this.weightAssessResult.assessWeightDataList;
            }
            this.weightSortData.sortName = i == 1 ? "基准重量" : "评估重量";
            CommonUtil.ExportDataToDataFile(this.weightSortData);
        }
        /// <summary>
        /// 获取修正后的重量数据
        /// </summary>
        /// <param name="jHSortData"></param>
        /// <param name="techSortData"></param>
        private WeightSortData GetModifyWeightData(WeightSortData jHSortData, WeightSortData techSortData)
        {
            WeightSortData sortData = null;
            if (jHSortData != null && jHSortData.lstWeightData.Count > 0
                && techSortData != null && techSortData.lstWeightData.Count > 0)
            {
                sortData = basicWeightData.Clone();

                List<WeightData> lstJHWeightData = WeightSortData.GetListWeightData(jHSortData);
                List<WeightData> lstTeachWeightData = WeightSortData.GetListWeightData(techSortData);

                List<WeightData> lstModifyWeightData = new List<WeightData>();

                foreach (WeightData data in lstJHWeightData)
                {
                    foreach (WeightData weight in lstTeachWeightData)
                    {
                        if (data.nID == weight.nID)
                        {
                            WeightData newWeight = new WeightData();

                            newWeight.nID = data.nID;
                            newWeight.nParentID = data.nParentID;
                            newWeight.weightName = data.weightName;
                            newWeight.weightValue = data.weightValue * weight.weightValue;
                            newWeight.strRemark = data.strRemark;
                            lstModifyWeightData.Add(newWeight);

                            break;
                        }
                    }
                }

                if (sortData != null && lstModifyWeightData.Count > 0)
                {
                    foreach (WeightData data in sortData.lstWeightData)
                    {
                        foreach (WeightData weight in lstModifyWeightData)
                        {
                            if (data.nID == weight.nID)
                            {
                                data.weightValue = weight.weightValue;
                                break;
                            }
                        }
                    }

                    //求和
                    foreach (WeightData data in sortData.lstWeightData)
                    {
                        WeightSortData.GetSortDataTotal(data, sortData);
                    }
                }

            }

            return sortData;
        }
Example #44
0
        static public bool SaveHccFile(WeightSortData ws, string filepath, bool bOverWritePrompt)
        {
            if (bOverWritePrompt)
            {
                if (System.IO.File.Exists(filepath))
                {
                    string msg = "文件\"" + ws.sortName + ".hcc\"" + "已存在,是否继续并覆盖该文件?";
                    if (MessageBox.Show(msg, "分类文件已存在", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            XmlTextWriter writeXml = null;

            try
            {
                writeXml = new XmlTextWriter(filepath, Encoding.GetEncoding("gb2312"));
            }
            catch
            {
                MessageBox.Show("创建或写入文件失败!");
                return(false);
            }

            writeXml.Formatting  = Formatting.Indented;
            writeXml.Indentation = 5;
            writeXml.WriteStartDocument();

            writeXml.WriteStartElement("重量分类");
            {
                writeXml.WriteStartElement("重量分类名称");
                writeXml.WriteString(ws.sortName);
                writeXml.WriteEndElement();
                writeXml.WriteStartElement("重量分类备注");
                writeXml.WriteString("");
                writeXml.WriteEndElement();

                writeXml.WriteStartElement("重量数据列表");
                {
                    foreach (WeightData wd in ws.lstWeightData)
                    {
                        writeXml.WriteStartElement("重量数据");
                        {
                            writeXml.WriteStartElement("ID");
                            writeXml.WriteValue(wd.nID);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量名称");
                            writeXml.WriteString(wd.weightName);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量单位");
                            writeXml.WriteString(wd.weightUnit);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("重量数值");
                            writeXml.WriteValue(wd.weightValue);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("备注");
                            writeXml.WriteString(wd.strRemark);
                            writeXml.WriteEndElement();
                            writeXml.WriteStartElement("PARENTID");
                            writeXml.WriteValue(wd.nParentID);
                            writeXml.WriteEndElement();
                        }
                        writeXml.WriteEndElement();
                    }
                }
                writeXml.WriteEndElement();
            }
            writeXml.WriteEndElement();
            writeXml.Close();

            return(true);
        }
        /// <summary>
        /// 双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewWeightData_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (selNode == null || selNode.Level == 0)
            {
                XCommon.XLog.Write("请选择数据");
                MessageBox.Show("请选择数据");
                return;
            }

            WeightSortData    sortData      = GetWeightSortData();
            List <WeightData> lstWeightData = form.GetListWeightData(sortData);

            if (sortData == null || sortData.lstWeightData.Count == 0)
            {
                MessageBox.Show("导入该条数据为空");
                return;
            }

            if (form.strWeightDataType == "data1")
            {
                if (form.importSortData2 != null)
                {
                    DialogResult result = MessageBox.Show("继续导入会清空所有数据?", "继续提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (result == DialogResult.Yes)
                    {
                        form.BindWeightData(sortData);
                        form.SetGridViewData(form.strWeightDataType, lstWeightData, true, false);
                        form.importSortData1   = sortData;
                        form.importSortData2   = null;
                        form.lstCalculateRatio = null;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    form.BindWeightData(sortData);
                    form.SetGridViewData(form.strWeightDataType, lstWeightData, false, false);
                    form.importSortData1 = sortData;
                }
                form.InitializezedGraphControl();
            }

            //重量分类是否一致
            if (form.strWeightDataType == "data2")
            {
                bool IsSame = WeightSortData.blIsSame(form.importSortData1, sortData);

                if (IsSame == false)
                {
                    XLog.Write("导入数据和重量数据1重量分类不一致");
                    MessageBox.Show("导入数据和重量数据1重量分类不一致");
                    return;
                }

                if (form.lstCalculateRatio != null && form.lstCalculateRatio.Count > 0)
                {
                    DialogResult result = MessageBox.Show("继续导入会清空因子数据?", "继续提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (result == DialogResult.Yes)
                    {
                        form.lstCalculateRatio = null;
                        form.importSortData2   = sortData;
                        form.SetGridViewData(form.strWeightDataType, lstWeightData, false, true);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    form.importSortData2 = sortData;
                    form.SetGridViewData(form.strWeightDataType, lstWeightData, false, false);
                }
                form.InitializezedGraphControl();
            }
            XLog.Write("导入数据成功");

            this.Close();
        }
        /// <summary>
        /// 双击节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeViewWeightSort_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }
            string strFolderPath = strPath + "weightCategory" + "\\" + selNode.Name;

            if (Directory.Exists(strFolderPath))
            {
                string[] files = System.IO.Directory.GetFiles(strFolderPath, "*.WEM");
                string strtype = (files.Length > 0) ? "readOnlyEdit" : "edit";

                WeightSortEditForm form = new WeightSortEditForm(this, weightSort, strtype);
                form.ShowDialog();
            }
            else
            {
                XLog.Write("文件\"" + strFolderPath + "\"不存在");
            }
        }
Example #47
0
        /// <summary>
        ///xls文件转换成WeightSortData类型
        /// </summary>
        /// <param name="strFilePath">文件路径</param>
        /// <returns>返回WeightSortData类型</returns>
        public static WeightSortData GetXlsImportSortData(string strFilePath)
        {
            WeightSortData sortData = null;
            try
            {
                if (File.Exists(strFilePath))
                {
                    ExcelLib OpExcel = new ExcelLib();
                    //指定操作的文件
                    OpExcel.OpenFileName = strFilePath;
                    //打开文件
                    if (OpExcel.OpenExcelFile() == false)
                    {
                        return sortData;
                    }
                    //取得所有的工作表名称
                    string[] strSheetsName = OpExcel.getWorkSheetsName();

                    //默认操作第一张表
                    OpExcel.SetActiveWorkSheet(1);
                    System.Data.DataTable table;
                    table = OpExcel.getAllCellsValue();
                    OpExcel.CloseExcelApplication();

                    int count = table.Rows.Count;
                    if (count > 0)
                    {
                        sortData = new WeightSortData();
                        sortData.sortName = table.Rows[0][0].ToString();

                        List<WeightData> lstWeightData = new List<WeightData>();
                        for (int i = 0; i < count; i++)
                        {
                            WeightData data = new WeightData();

                            data.nID = Convert.ToInt32(table.Rows[i][1].ToString());
                            data.weightName = table.Rows[i][2].ToString();
                            data.weightValue = Convert.ToDouble(table.Rows[i][4].ToString());
                            data.strRemark = table.Rows[i][5].ToString();
                            data.nParentID = Convert.ToInt32(table.Rows[i][6].ToString());

                            lstWeightData.Add(data);
                        }
                        sortData.lstWeightData = lstWeightData;
                    }
                }
            }
            catch
            {
                XLog.Write("导入文件\"" + strFilePath + "\"格式错误");
                MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误");
                return null;
            }
            return sortData;
        }
        /// <summary>
        /// 计算
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCalculation_Click(object sender, EventArgs e)
        {
            if (txtAdjustmentDataName.Text == string.Empty)
            {
                MessageBox.Show("请输入调整数据名称");
                return;
            }
            else
            {
                if (Verification.IsCheckString(txtAdjustmentDataName.Text))
                {
                    MessageBox.Show("调整数据名称不能输入非法字符");
                    return;
                }
            }

            if (basicWeightData == null)
            {
                MessageBox.Show("请导入基础重量数据");
                return;
            }
            if (cmbCurrentSel.Text == "校核因子" || cmbCurrentSel.Text == "校核因子和技术因子")
            {
                if (lstJHRatio == null || lstJHRatio.Count == 0)
                {
                    MessageBox.Show("请导入校核因子");
                    return;
                }
            }
            if (cmbCurrentSel.Text == "技术因子" || cmbCurrentSel.Text == "校核因子和技术因子")
            {
                if (lstTeachRatio == null || lstTeachRatio.Count == 0)
                {
                    MessageBox.Show("请导入技术因子");
                    return;
                }
            }

            //调整后的重量数据
            modifyWeightSortData = getWeightModified(basicWeightData, lstRatio);

            //重量调整数据
            if (weightAdjustment == null)
            {
                weightAdjustment = new WeightAdjustmentResultData();
            }
            weightAdjustment.WeightAdjustName = txtAdjustmentDataName.Text;
            weightAdjustment.SortName = basicWeightData.sortName;
            weightAdjustment.basicWeightData = basicWeightData;
            weightAdjustment.weightAdjustData = modifyWeightSortData;
            weightAdjustment.technologyFactor = lstTeachRatio;
            weightAdjustment.checkFactor = lstJHRatio;

            //关联主页面
            if (mainForm.designProjectData == null)
            {
                mainForm.designProjectData = new DesignProjectData();
            }

            if (mainForm.designProjectData.lstAdjustmentResultData == null)
            {
                mainForm.designProjectData.lstAdjustmentResultData = new List<WeightAdjustmentResultData>();
            }

            //重新计算
            if (IsReCal)
            {
                mainForm.SetWeightAdjustmentResult(weightAdjustment);
                XLog.Write("重量调整数据\"" + txtAdjustmentDataName.Text + "\"重新计算完成!");
            }
            else
            {
                mainForm.designProjectData.lstAdjustmentResultData.Add(weightAdjustment);
                mainForm.BindProjectTreeData(mainForm.designProjectData);
                mainForm.SetWeightAdjustTab(weightAdjustment, mainForm.designProjectData.lstAdjustmentResultData.Count - 1);

                XLog.Write("重量调整数据\"" + txtAdjustmentDataName.Text + "\"计算完成!");
            }

            this.Close();
        }
        /// <summary>
        /// 清空数据
        /// </summary>
        public void InitializeData()
        {
            lstJHRatio = null;
            lstTeachRatio = null;
            lstRatio = null;

            //basicWeightData = null;
            modifyWeightSortData = null;

            //修正因子列表清空
            dgvCorrectFactor.Rows.Clear();
            dgvCorrectFactor.Columns.Clear();

            //清空图形
            chartAdjustment.Titles.Clear();
            chartAdjustment.Series.Clear();
            chartAdjustment.ChartAreas.Clear();
            chartAdjustment.Legends.Clear();
            chartAdjustment.ContextMenuStrip = null;
        }
        private bool IsSameWeightSort(WeightSortData sortData)
        {
            bool IsSame = false;

            foreach (WeightSortData data in lstWeightSortData)
            {
                if (WeightSortData.blIsSame(sortData, data))
                {
                    IsSame = true;
                    return IsSame;
                }
            }
            return IsSame;
        }
 public void BindWeightData(WeightSortData sortData)
 {
     basicWeightData = sortData.Clone();
     treeViewWeightData.Nodes.Clear();
     MainForm.BindWeightDesignSort(sortData, treeViewWeightData);
 }
        /// <summary>
        /// 求解调整后的重量分类
        /// </summary>
        /// <param name="_weightSortData"></param>
        /// <param name="_lstPara"></param>
        /// <returns></returns>
        private WeightSortData getWeightModified(WeightSortData _weightSortData, List<ParaData> _lstPara)
        {
            WeightSortData tempWeightSortData = null;
            WeightData tempWeightData = null;
            List<WeightData> lstWeightData = null;

            if (_weightSortData == null || _weightSortData.lstWeightData.Count == 0
                || _lstPara == null || _lstPara.Count == 0)
            {
                return tempWeightSortData;
            }
            else
            {
                // 判断当前的重量分类和修正因子是否合适
                if (WeightSortData.blIsFit(_weightSortData, _lstPara))
                {
                    // 复制重量分类
                    tempWeightSortData = _weightSortData.Clone();
                    // 置零非基层的重量数据
                    lstWeightData = WeightSortData.GetListWeightData(tempWeightSortData);
                    foreach (WeightData _weightData in tempWeightSortData.lstWeightData)
                    {
                        int intCounter = 0;
                        foreach (WeightData _weightData2 in lstWeightData)
                        {
                            if (_weightData.nID != _weightData2.nID)
                            {
                                intCounter = intCounter + 1;
                            }
                            else
                            {
                                break;
                            }
                        }
                        //if (intCounter == lstWeightData.Count - 1)
                        //{
                        //    _weightData.weightValue = 0.0;
                        //}
                    }
                    // 找到相同的重量名称

                    for (int i = 0; i < lstWeightData.Count; i = i + 1)
                    {
                        StringBuilder tempPath = new StringBuilder();

                        for (int j = 0; j < _lstPara.Count; j = j + 1)
                        {
                            // 错误的修正因子名称
                            if (_lstPara[j].paraName.Length < 4)
                            {
                                break;
                            }
                            if (lstWeightData[i].weightName == _lstPara[j].paraName.Substring(5, _lstPara[j].paraName.Length - 5))
                            {
                                tempPath.Append("\\" + lstWeightData[i].weightName);

                                // 获取根
                                bool triger = true;
                                int intInner = lstWeightData[i].nID;
                                while (triger)
                                {
                                    tempWeightData = WeightSortData.getParentNode(tempWeightSortData, intInner);

                                    if (tempWeightData != null && tempWeightData.nParentID != -1)
                                    {
                                        intInner = tempWeightData.nID;
                                        tempPath.Insert(0, "\\" + tempWeightData.weightName);
                                    }
                                    else if (tempWeightData != null && tempWeightData.nParentID == -1)
                                    {
                                        tempPath.Insert(0, tempWeightData.weightName);
                                        triger = false;
                                    }
                                    else
                                    {
                                        triger = false;
                                    }
                                }
                                // 找到对应修正因子
                                if (tempPath.ToString() == _lstPara[j].strRemark)
                                {
                                    foreach (WeightData _weightData in tempWeightSortData.lstWeightData)
                                    {
                                        if (_weightData.nID == lstWeightData[i].nID)
                                        {
                                            _weightData.weightValue = _weightData.weightValue * _lstPara[j].paraValue;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //求和
                foreach (WeightData data in tempWeightSortData.lstWeightData)
                {
                    WeightSortData.GetSortDataTotal(data, tempWeightSortData);
                }
                return tempWeightSortData;
            }
        }
Example #53
0
        private bool QueryWeightSort(WeightArithmetic wa)
        {
            List <WeightSortData> wsDataList = WeightSortManageForm.GetListWeightSortData(false);

            int nindex = -1;

            for (nindex = wsDataList.Count - 1; nindex >= 0; --nindex)
            {
                if (wsDataList[nindex].sortName == wa.SortName)
                {
                    break;
                }
            }

            bool bHasSort = false;
            int  nfit     = 0;

            if (nindex != -1)
            {
                bHasSort = true;

                if (wa.MatchWeightSort(wsDataList[nindex], false))
                {
                    nfit = 1;
                }
            }
            if (nfit == 0)
            {
                for (int i = 0; i < wsDataList.Count; ++i)
                {
                    if (i == nindex)
                    {
                        continue;
                    }

                    if (wa.MatchWeightSort(wsDataList[i], false))
                    {
                        string       Message = bHasSort ? ("算法文件未能和分类\"" + wa.SortName + "\"匹配,但和分类\"") : ("分类\"" + wa.SortName + "\"不存在,但算法文件和分类\"");
                        DialogResult dr      = MessageBox.Show(Message + wsDataList[i].sortName + "\"匹配。是否导入到分类\"" + wsDataList[i].sortName + "\"?", "分类不匹配", MessageBoxButtons.YesNoCancel);
                        if (dr == DialogResult.Cancel)
                        {
                            return(false);
                        }
                        else if (dr == DialogResult.Yes)
                        {
                            wa.SortName = wsDataList[i].sortName;
                            nindex      = i;
                            nfit        = 2;
                            break;
                        }
                        else
                        {
                            nfit = 0;
                        }
                    }
                }

                // 0 建分类
                // 1 符合
                // 2 在其它分类找到

                if (nfit == 0)
                {
                    DialogResult dr = MessageBox.Show("算法未找到匹配分类,是否新建分类?", "是否建分类", MessageBoxButtons.YesNo);
                    if (dr != DialogResult.Yes)
                    {
                        return(false);
                    }
                    // 建分类

                    if (bHasSort)
                    {
                        string strmsg    = "请输入分类名称";
                        bool   bcontinue = true;
                        while (bcontinue)
                        {
                            string sortname = Microsoft.VisualBasic.Interaction.InputBox(strmsg, "输入名称", wa.SortName, -1, -1);
                            sortname = sortname.Trim();
                            if (sortname == "")
                            {
                                return(false);
                            }
                            bcontinue = false;
                            foreach (WeightSortData wsditem in wsDataList)
                            {
                                if (wsditem.sortName == sortname)
                                {
                                    bcontinue = true;
                                    strmsg    = "分类\"" + sortname + "\"已存在!\r\n请重新输入分类名称";
                                }
                            }
                            if (!bcontinue)
                            {
                                wa.SortName = sortname;
                            }
                        }
                    }

                    WeightSortData wsd = wa.MakeNewWeightSort();
                    if (!WeightSortManageForm.SaveHccFile(wsd, false))
                    {
                        return(false);
                    }
                    wsDataList.Add(wsd);

                    treeViewArithmeticList.Nodes[0].Nodes.Add("weightCategory\\" + wa.SortName, wa.SortName, 2, 3);
                }
            }

            return(true);
        }
 private WeightSortData GetZeroWeight(WeightSortData sortData)
 {
     WeightSortData tempWeightSortData = null;
     if (sortData != null)
     {
         tempWeightSortData = new WeightSortData();
         tempWeightSortData = sortData.Clone();
         for (int i = 0; i < tempWeightSortData.lstWeightData.Count; i++)
         {
             tempWeightSortData.lstWeightData[i].weightValue = 0;
         }
     }
     return tempWeightSortData;
 }
        public static List<WeightData> GetAllListWeightData(WeightSortData sortData, DataGridView gridWeightData)
        {
            List<WeightData> lstWeightData = new List<WeightData>();
            double dValue = MainForm.GetDesignResultCount(sortData, gridWeightData);
            dValue = Math.Round(dValue, 6);

            for (int i = 0; i < sortData.lstWeightData.Count; i++)
            {
                if (sortData.lstWeightData[i].nParentID == -1)
                {
                    sortData.lstWeightData[i].weightValue = dValue;
                    lstWeightData.Add(sortData.lstWeightData[i]);
                }

                for (int j = 0; j < gridWeightData.ColumnCount; j++)
                {
                    if (sortData.lstWeightData[i].weightName == gridWeightData.Columns[j].Name)
                    {
                        dValue = gridWeightData.Rows[0].Cells[j].Value is System.DBNull ? 0 : Convert.ToDouble(gridWeightData.Rows[0].Cells[j].Value);
                        sortData.lstWeightData[i].weightValue = dValue;
                        lstWeightData.Add(sortData.lstWeightData[i]);
                    }
                }
            }
            return lstWeightData;
        }
        /// <summary>
        /// 获取tables数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private DataTable GetTableExcleData(WeightDesignData designData, WeightSortData sortData)
        {
            DataTable table = GetTableExcleStruct();

            DataRow drFirst = table.NewRow();

            drFirst["DesignData_Name"] = designData.DesignData_Name;
            drFirst["DesignData_Submitter"] = designData.DesignData_Submitter;
            drFirst["Helicopter_Name"] = designData.Helicopter_Name;
            drFirst["DataRemark"] = designData.DataRemark;
            drFirst["LastModify_Time"] = designData.LastModify_Time;
            drFirst["DesignTaking_Weight"] = designData.DesignTaking_Weight;
            table.Rows.Add(drFirst);

            DataRow dr = null;
            if (sortData != null && sortData.lstWeightData.Count > 0)
            {
                foreach (WeightData data in sortData.lstWeightData)
                {
                    if (data == sortData.lstWeightData.First())
                    {
                        if (table.Rows.Count > 0)
                        {
                            table.Rows[0]["Sort_Name"] = sortData.sortName;

                            table.Rows[0]["ID"] = data.nID;
                            table.Rows[0]["Weight_Name"] = data.weightName;
                            table.Rows[0]["Weight_Unit"] = "千克";
                            table.Rows[0]["Weight_Remark"] = data.strRemark;
                            table.Rows[0]["Prarent_ID"] = data.nParentID;
                            table.Rows[0]["Weight_Value"] = data.weightValue;
                        }
                    }
                    else
                    {
                        dr = table.NewRow();

                        dr["DesignData_Name"] = string.Empty;
                        dr["DesignData_Submitter"] = string.Empty;
                        dr["Helicopter_Name"] = string.Empty;
                        dr["DataRemark"] = string.Empty;
                        dr["LastModify_Time"] = string.Empty;
                        dr["DesignTaking_Weight"] = string.Empty;
                        dr["Sort_Name"] = string.Empty;

                        dr["ID"] = data.nID;
                        dr["Weight_Name"] = data.weightName;
                        dr["Weight_Unit"] = "千克";
                        dr["Weight_Remark"] = data.strRemark;
                        dr["Prarent_ID"] = data.nParentID;
                        dr["Weight_Value"] = data.weightValue;
                        table.Rows.Add(dr);
                    }
                }
            }
            return table;
        }
        /// <summary>
        /// 基于新建
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnJYNew_Click(object sender, EventArgs e)
        {
            if (selNode == null || selNode.Level == 0)
            {
                XCommon.XLog.Write("请选择重量分类");
                return;
            }

            weightSort = selNode.Tag as WeightSortData;
            if (weightSort == null)
            {
                return;
            }

            WeightSortEditForm form = new WeightSortEditForm(this, weightSort, "JYNew");
            if (form.ShowDialog() == DialogResult.OK)
            {
                RefreshTreeViewData();
            }
        }
        /// <summary>
        /// 导出重量数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExportWeightData_Click(object sender, EventArgs e)
        {
            WeightSortData tempWeightSort = new WeightSortData();
            if (strOperType == CommonMessage.operNew || strOperType == CommonMessage.operJYNew || strOperType == CommonMessage.operEdit)
            {
                tempWeightSort = clsStringToWeightSortData(weightDesinData.MainSystem_Name);
                if (tempWeightSort == null)
                {
                    XLog.Write("没有数据不能导出");
                    return;
                }
            }
            else
            {
                if (selNode == null || selNode.Level == 0)
                {
                    XLog.Write("请选择重量设计数据");
                    return;
                }
                WeightDesignData tempWeightDesinData = GetWeightDesignData(Convert.ToInt32(selNode.Name));
                tempWeightSort = clsStringToWeightSortData(tempWeightDesinData.MainSystem_Name);
            }

            if (tempWeightSort == null)
            {
                XLog.Write("没有数据不能导出");
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "xml文件 (*.xml)|*.xml|Excel文件 (*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.FileName = txtDesignDataName.Text;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string strFilePath = dlg.FileName;

                if (strFilePath.EndsWith(".xml"))
                {
                    List<string> lstContent = MainForm.GetDesignResultFlieContent(tempWeightSort);
                    CommonFunction.mWriteListStringToFile(strFilePath, lstContent);
                }

                if (strFilePath.EndsWith(".xls"))
                {
                    DataTable table = MainForm.GetDesignResultTable(tempWeightSort);
                    int result = XCommon.FileStatus.FileIsOpen(strFilePath);

                    if (result == 1)
                    {
                        MessageBox.Show("请关闭文件" + strFilePath + ",再导出");
                    }
                    else
                    {
                        CommonExcel commonExcel = new CommonExcel();
                        commonExcel.lstColumn = MainForm.GetDesignResultExcleCloumn();
                        commonExcel.CreateExcel("example", strFilePath, "sheet1", table);
                    }
                }

                XLog.Write("导出文件\"" + strFilePath + "\"成功");
            }
        }
        private void memu2FromDataFileImport_Click(object sender, EventArgs e)
        {
            if (treeViewSort.Nodes.Count == 0)
            {
                XLog.Write("先导入重量数据1数据");
                MessageBox.Show("先导入重量数据1数据");
                return;
            }

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = "xml文件 (*.xml)|*.xml|Excle文件 (*.xls)|*.xls|All files (*.*)|*.*";
            fileDialog.RestoreDirectory = true;
            fileDialog.FilterIndex      = 1;

            //获取重量分类
            WeightSortData sortData = null;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string strFilePath = fileDialog.FileName;

                //bool IsRight = IsImortWeightDataFileFormat(strFilePath);
                //if (IsRight == false)
                //{
                //    XLog.Write("导入文件\"" + strFilePath + "\"格式错误");
                //    return;
                //}

                if (strFilePath.EndsWith(".xls"))
                {
                    sortData = WeightSortData.GetXlsImportSortData(strFilePath);
                }
                else if (strFilePath.EndsWith(".xml"))
                {
                    sortData = WeightSortData.GetXmlImporSortData(strFilePath);
                }
                else
                {
                    XLog.Write("导入文件\"" + strFilePath + "\"格式错误");
                    MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误");
                    return;
                }

                if (sortData == null)
                {
                    return;
                }
                if (sortData != null && sortData.lstWeightData.Count == 0)
                {
                    MessageBox.Show("导入文件\"" + strFilePath + "\"没有数据");
                    XLog.Write("导入文件\"" + strFilePath + "\"没有数据");
                    return;
                }

                //判断导入重量分类是否一致
                bool IsSame = WeightSortData.blIsSame(importSortData1, sortData);

                if (IsSame == false)
                {
                    XLog.Write("导入数据和重量数据1重量分类不一致");
                    MessageBox.Show("导入数据和重量数据1重量分类不一致");
                    return;
                }
                List <WeightData> lstWeightData = GetListWeightData(sortData);

                strWeightDataType = "data2";
                if (lstCalculateRatio != null && lstCalculateRatio.Count > 0)
                {
                    DialogResult result = MessageBox.Show("继续导入会清空因子数据?", "继续提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (result == DialogResult.Yes)
                    {
                        lstCalculateRatio = null;
                        importSortData2   = sortData;
                        SetGridViewData(strWeightDataType, lstWeightData, false, true);
                        InitializezedGraphControl();
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    importSortData2 = sortData;
                    SetGridViewData(strWeightDataType, lstWeightData, false, false);
                }
            }
        }
 private void weightCategoryTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Node.Level != 1)
     {
         return;
     }
     weightCategoryTreeView.SelectedNode = e.Node;
     //所选的重量分类
     TreeNode selNode = weightCategoryTreeView.SelectedNode;
     this.weightCategory = this.mainForm.designProjectData.lstWeightArithmetic[Convert.ToInt32(selNode.Tag)].ExportDataToWeightSort();
 }