예제 #1
0
        public MapForm(string configPath)
        {
            this.configPath = configPath;
            DataKeep.Serialize(configPath, false, ref param);

            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
        }
예제 #2
0
        /// <summary>
        /// 机加件编码生成
        /// </summary>
        private void MachineCodingBuilds()
        {
            MachineNumberForm        form = new MachineNumberForm();
            Dictionary <string, int> dict = sql.GetNumber_M();

            DataKeep.Serialize(configPath, false, ref param);
            if (form.ShowDialog() == DialogResult.OK)
            {
                DataTable dt         = (DataTable)myDataGridView1.DataSource;
                string    CodingName = "";
                foreach (Map map in param.Maps)
                {
                    if (map.Name.Equals("存货编码"))
                    {
                        CodingName = map.Value;
                    }
                }
                string projectnumber = form.projectNumber.Trim();

                if (dt.Columns.Contains(CodingName))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        int num;
                        if (dict.ContainsKey(projectnumber))
                        {
                            num = dict[projectnumber];
                        }
                        else
                        {
                            dict.Add(projectnumber, 0);
                            num = 0;
                        }
                        string numstr = string.Format("{0:D5}", num + 1);
                        try
                        {
                            string Classstr = projectnumber;
                            row[CodingName]     = Classstr + "." + numstr;
                            dict[projectnumber] = num + 1;
                        }
                        catch (Exception e1)
                        {
                            MessageBox.Show(e1.Message);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("表没有{0}列", CodingName));
                }
                dt.AcceptChanges();
            }
        }
예제 #3
0
        private void 公式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string strPath = Application.StartupPath + "\\Temporary\\" + formulaPath.Split('\\').Last();

            if (!File.Exists(strPath))
            {
                System.IO.File.Copy(formulaPath, strPath, false);
            }
            MapForm mapForm = new MapForm(strPath);

            mapForm.ShowDialog();
            DataKeep.Serialize(strPath, false, ref formulaParaml);
        }
예제 #4
0
        private void EditColnumStyle()
        {
            Param paramStyle = new Param();

            DataKeep.Serialize(colnumStylePath, false, ref paramStyle);
            foreach (Map map in paramStyle.Maps)
            {
                var   name  = map.Name;
                float value = float.Parse(map.Value);
                if (myDataGridView1.Columns[name] != null)
                {
                    myDataGridView1.Columns[name].FillWeight = value;
                }
            }
        }
예제 #5
0
        private void 保存格式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Param      param = new Param();
            List <Map> maps  = new List <Map>();

            for (int i = 0; i < myDataGridView1.Columns.Count; i++)
            {
                Map map = new Map();
                map.Name  = myDataGridView1.Columns[i].Name;
                map.Value = myDataGridView1.Columns[i].FillWeight.ToString();
                maps.Add(map);
            }
            param.Maps = maps.ToArray();
            DataKeep.Serialize(colnumStylePath, true, ref param);
            MessageBox.Show("表格格式保存成功");
        }
예제 #6
0
        private void 还原ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataKeep.Serialize(configPath, false, ref param);
            DataTable dt = new DataTable();

            dt.Columns.Add("Key");
            dt.Columns.Add("Value");
            foreach (Map map in param.Maps)
            {
                DataRow row = dt.NewRow();
                row["Key"]   = map.Name;
                row["Value"] = map.Value;
                dt.Rows.Add(row);
            }
            dt.AcceptChanges();
            myDataGridView1.DataSource = dt;
        }
예제 #7
0
        private void SQLupdate()
        {
            string configPath = Application.StartupPath + "\\配置文件\\Config.xml";
            Param  param      = new Param();

            #region 读取数据,更新数据
            param = new Param();
            DataKeep.Serialize(configPath, false, ref param);
            string sqldata = "";
            foreach (Map map in param.Maps)
            {
                sqldata += map.Name + ",";
            }
            sqldata = sqldata.TrimEnd(',');

            sql.Init();
            #endregion
        }
예제 #8
0
        private void MaterialCreatetForm_Load()
        {
            configPath = Application.StartupPath + "\\配置文件\\Config.xml";

            param = new Param();

            DataKeep.Serialize(configPath, false, ref param);

            dictparam = ToolsBox.ListTODict(param.Maps);

            templatePath = Application.StartupPath + "\\配置文件\\存货档案模板.xls";
            startRow     = int.Parse(ConfigurationManager.AppSettings["StartRow"]);
            startCol     = int.Parse(ConfigurationManager.AppSettings["StartCol"]);


            toolStripComboBox1.Items.Add("机加件");
            toolStripComboBox1.Items.Add("标准件");
            toolStripComboBox1.Text = toolStripComboBox1.Items[1].ToString();
        }
예제 #9
0
        private void 恢复默认ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string strPath = Application.StartupPath + "\\配置文件\\" + configPath.Split('\\').Last();

            System.IO.File.Copy(strPath, configPath, true);
            myDataGridView1.DataSource = null;
            DataKeep.Serialize(configPath, false, ref param);
            DataTable dt = new DataTable();

            dt.Columns.Add("Key");
            dt.Columns.Add("Value");
            foreach (Map map in param.Maps)
            {
                DataRow row = dt.NewRow();
                row["Key"]   = map.Name;
                row["Value"] = map.Value;
                dt.Rows.Add(row);
            }
            dt.AcceptChanges();
            myDataGridView1.DataSource = dt;
        }
예제 #10
0
        public static string GetStrByDataKeep(DataKeep keep)
        {
            string str;

            switch (keep)
            {
            case DataKeep.Enable:
                str = "可保持";
                break;

            case DataKeep.UnEnable:
                str = "不保持";
                break;

            default:
                str = "";
                break;
            }

            return(str);
        }
예제 #11
0
        /// <summary>
        /// DataGridView页面初始化,加载界面
        /// </summary>
        private void InitDataGridView()
        {
            param = new Param();

            DataKeep.Serialize(configPath, false, ref param);
            formulaParaml = new Param();
            DataKeep.Serialize(formulaPath, false, ref formulaParaml);
            dictparam = ToolsBox.ListTODict(param.Maps);

            foreach (Map map in param.Maps)
            {
                toolStripComboBox2.Items.Add(map.Value);
            }

            toolStripComboBox2.Text = toolStripComboBox2.Items[0].ToString();

            DataTable table;

            if (File.Exists(temporaryFilePath))
            {
                useFilePath = temporaryFilePath;
            }
            else
            {
                useFilePath = templateFilePath;
            }
            this.Cursor = Cursors.WaitCursor;
            if (!ExcelOperation.ReadTemplate(startRow, startCol, useFilePath, out table))
            {
                MessageBox.Show("文件保存失败");
            }
            this.Cursor = Cursors.Default;
            ExcelOperation.RemoveEmpty(ref table);

            myDataGridView1.DataSource = null;
            myDataGridView1.DataSource = table;

            EditColnumStyle();
        }
예제 #12
0
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Param      param = new Param();
            List <Map> maps  = new List <Map>();
            DataTable  dt    = (DataTable)myDataGridView1.DataSource;

            foreach (DataRow row in dt.Rows)
            {
                Map map = new Map();

                string name  = row["Key"].ToString();
                string value = row["Value"].ToString();
                if (name != "" && value != "")
                {
                    map.Name  = name;
                    map.Value = value;
                    maps.Add(map);
                }
            }
            param.Maps = maps.ToArray();
            DataKeep.Serialize(configPath, true, ref param);
            MessageBox.Show("配置已成功保存");
        }
예제 #13
0
        private void 合并ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataTable dt      = (DataTable)myDataGridView1.DataSource;
            string    Path    = Application.StartupPath + "\\配置文件\\数据合并配置.xml";
            string    strPath = Application.StartupPath + "\\Temporary\\数据合并配置.xml";

            if (!File.Exists(strPath))
            {
                System.IO.File.Copy(Path, strPath, false);
            }
            Param param = new Param();

            DataKeep.Serialize(strPath, false, ref param);
            List <string>  strList     = new List <string>();
            List <string>  strCol      = new List <string>();
            List <DataRow> removeList  = new List <DataRow>();
            DataTable      removeTable = dt.Copy();

            removeTable.Clear();
            string cInvCCode = dictparam["cInvCCode"];

            foreach (DataColumn col in dt.Columns)
            {
                strCol.Add(col.ColumnName);
            }
            foreach (Map map in param.Maps)
            {
                strList.Add(map.Name);
            }
            var list = strCol.Except(strList);

            foreach (var s in list)
            {
                Console.WriteLine(s);
            }
            bool judge = true;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = i + 1; j < dt.Rows.Count; j++)
                {
                    if (dt.Rows[i][cInvCCode] != DBNull.Value && dt.Rows[j][cInvCCode] != DBNull.Value && dt.Rows[i][cInvCCode].Equals(dt.Rows[j][cInvCCode]))
                    {
                        judge = true;
                        foreach (var value in list)
                        {
                            if (!dt.Rows[i][value].ToString().Trim().Equals(dt.Rows[j][value].ToString().Trim()))
                            {
                                judge = false;
                                break;
                            }
                        }
                        if (judge)
                        {
                            try
                            {
                                removeTable.Rows.Add(dt.Rows[j].ItemArray);
                                dt.Rows.RemoveAt(j);
                                j--;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            DataForm dataForm = new DataForm(sql, removeTable);

            dataForm.ShowDialog();
        }
예제 #14
0
        private void LookForDuplicates()
        {
            DataTable dt      = (DataTable)myDataGridView1.DataSource;
            string    Path    = Application.StartupPath + "\\配置文件\\数据合并配置.xml";
            string    strPath = Application.StartupPath + "\\Temporary\\数据合并配置.xml";

            if (!File.Exists(strPath))
            {
                File.Copy(Path, strPath, false);
            }
            Param param = new Param();

            DataKeep.Serialize(strPath, false, ref param);
            List <string> strList     = new List <string>();
            List <string> strCol      = new List <string>();
            DataTable     removeTable = dt.Copy();

            removeTable.Clear();
            string cInvCCode = dictparam["cInvCCode"];

            foreach (DataColumn col in dt.Columns)
            {
                strCol.Add(col.ColumnName);
            }
            foreach (Map map in param.Maps)
            {
                strList.Add(map.Name);
            }
            var  list  = strCol.Except(strList);
            bool judge = true;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = i + 1; j < dt.Rows.Count; j++)
                {
                    if (dt.Rows[i][cInvCCode] != DBNull.Value && dt.Rows[j][cInvCCode] != DBNull.Value && dt.Rows[i][cInvCCode].Equals(dt.Rows[j][cInvCCode]))
                    {
                        judge = true;
                        foreach (var value in list)
                        {
                            if (!dt.Rows[i][value].ToString().Trim().Equals(dt.Rows[j][value].ToString().Trim()))
                            {
                                judge = false;
                                break;
                            }
                        }
                        if (judge)
                        {
                            try
                            {
                                myDataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
                                myDataGridView1.Rows[j].DefaultCellStyle.BackColor = Color.Yellow;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
        private static void Init()
        {
            string productVersion = "";
            string config         = Application.StartupPath + "\\配置文件\\版本信息.xml";
            string configPath     = Application.StartupPath + "\\配置文件\\Config.xml";
            Param  param          = new Param();
            string url            = "";

            if (false == System.IO.Directory.Exists(Application.StartupPath + "\\Temporary"))
            {
                System.IO.Directory.CreateDirectory(Application.StartupPath + "\\Temporary");
            }
            string path        = Application.StartupPath + "\\Temporary\\" + "版本号.txt";
            string updaterpath = Application.StartupPath + "\\";


            if (File.Exists(config))
            {
                #region 判断软件是否需要更新
                DataKeep.Serialize(config, false, ref param);
                foreach (Map map in param.Maps)
                {
                    if (map.Name.Equals("版本号"))
                    {
                        productVersion = map.Value;
                    }
                    if (map.Name.Equals("url"))
                    {
                        url = map.Value;
                    }
                    if (map.Name.Equals("更新器"))
                    {
                        updaterpath += map.Value;
                    }
                }
                using (var client = new WebClient())
                {
                    try { client.DownloadFile(url, path); }
                    catch { }
                }
                if (File.Exists(path))
                {
                    FileStream   stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader reader = new StreamReader(stream);
                    string       str    = reader.ReadToEnd().Trim();
                    reader.Close();
                    stream.Close();
                    int result = string.Compare(productVersion, str, true);
                    if (result < 0)
                    {
                        if (File.Exists(updaterpath))
                        {
                            if (DialogResult.Cancel == MessageBox.Show("本软件有最新版本是否需要更新?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                            {
                                run = true;
                            }
                            else
                            {
                                System.Diagnostics.Process.Start(updaterpath);
                                run = false;
                                Application.Exit();
                            }
                        }
                    }
                    File.Delete(path);
                }
                #endregion
            }
        }
예제 #16
0
        private void TreeInvCCode_Load()
        {
            configPath = Application.StartupPath + "\\配置文件\\Config.xml";
            DataKeep.Serialize(configPath, false, ref param);
            foreach (Map map in param.Maps)
            {
                if (!dictParam.ContainsKey(map.Name))
                {
                    dictParam.Add(map.Name, map.Value);
                }
            }

            dt = new DataTable();
            foreach (DataColumn col in sql.dataTable.Columns)
            {
                if (dictParam.ContainsKey(col.ColumnName))
                {
                    string value = dictParam[col.ColumnName];
                    dt.Columns.Add(value);
                }
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            treeView1.LabelEdit = true;
            foreach (DataRow dr in dataTable.Rows)
            {
                MyTreeNode node = tree;
                int        i    = 0;
                foreach (var bat in Encoding.ASCII.GetBytes(dr["cInvCCode"].ToString()))
                {
                    if (node.node.ContainsKey(bat))
                    {
                        node = node.node[bat];
                    }
                    else
                    {
                        MyTreeNode treeNode = new MyTreeNode();
                        treeNode.num = bat;
                        node.node.Add(bat, treeNode);
                        node = treeNode;
                    }
                }
                if (!cInvStatus.ContainsKey(dr["cInvCCode"].ToString()))
                {
                    cInvStatus.Add(dr["cInvCCode"].ToString(), Convert.ToBoolean(dr["bInvCEnd"].ToString()));
                }
                node.treeNode      = new TreeNode();
                node.cInvCCode     = dr["cInvCCode"].ToString();
                node.treeNode.Text = dr["cInvCCode"].ToString() + " " + dr["cInvCName"].ToString();
                node.bInvCEnd      = Convert.ToBoolean(dr["bInvCEnd"].ToString());
            }
            TreeNode treeNode1 = new TreeNode();

            treeNode1.Text = "全部";
            treeView1.Nodes.Add(treeNode1);
            SetTree(tree, treeNode1);
            foreach (TreeNode node in treeView1.Nodes)
            {
                node.Expand();
                foreach (TreeNode twonode in node.Nodes)
                {
                    twonode.Expand();
                }
            }
        }
예제 #17
0
        /// <summary>
        /// 标准件编码生成
        /// </summary>
        private void StandardCodingBuilds()
        {
            DataTable dt = (DataTable)myDataGridView1.DataSource;
            Dictionary <string, int> dict = sql.GetNumber();

            DataKeep.Serialize(configPath, false, ref param);
            string     ClassName  = "";
            string     CodingName = "";
            string     cInvName   = "";
            string     cInvStd    = "";
            List <int> redlist    = new List <int>();

            foreach (Map map in param.Maps)
            {
                Console.WriteLine(map.Name);
                if (map.Name.Equals("存货大类编码"))
                {
                    ClassName = map.Value;
                }
                else if (map.Name.Equals("存货编码"))
                {
                    CodingName = map.Value;
                }
                else if (map.Name.Equals("规格型号"))
                {
                    cInvStd = map.Value;
                }
                else if (map.Name.Equals("存货名称"))
                {
                    cInvName = map.Value;
                }
            }
            Console.WriteLine(ClassName + "," + CodingName);
            if (dt.Columns.Contains(ClassName) && dt.Columns.Contains(CodingName) && dt.Columns.Contains(cInvStd) && dt.Columns.Contains(cInvName))
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (row[ClassName] != DBNull.Value)
                    {
                        string    name  = row[cInvName].ToString().Trim();
                        string    std   = row[cInvStd].ToString().Trim();
                        DataTable dtnew = sql.AccurateQuery_AND_Like(name, "cInvName", std, "cInvStd");

                        if (dtnew == null || dtnew.Rows.Count > 0)
                        {
                            redlist.Add(row.Table.Rows.IndexOf(row));
                            continue;
                        }
                        string value = row[ClassName].ToString().Trim();
                        int    num;
                        if (dict.ContainsKey(value))
                        {
                            num = dict[value];
                        }
                        else
                        {
                            MessageBox.Show(value + "分类编码错误");
                            continue;
                        }
                        string numstr = string.Format("{0:D5}", num + 1);
                        try
                        {
                            string Classstr = value.Substring(0, 4) + "." + value.Substring(4, 2);
                            row[CodingName] = Classstr + "." + numstr;
                            dict[value]     = num + 1;
                        }
                        catch (Exception e1)
                        {
                            MessageBox.Show(e1.Message);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(string.Format("表没有{0}列或{1}列", ClassName, CodingName));
            }
            dt.AcceptChanges();
            LookForDuplicates();
            foreach (var i in redlist)
            {
                myDataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
            }
        }
예제 #18
0
        private void ExportToExcel(string path)
        {
            DataTable table = (DataTable)myDataGridView1.DataSource;

            ExcelOperation.RemoveEmpty(ref table);
            DataSet ds;

            this.Cursor = Cursors.Default;
            ds          = ExcelOperation.ReadExcel(templatePath);
            this.Cursor = Cursors.Default;
            string str = Application.StartupPath + "\\Temporary\\" + defaultPath.Split('\\').Last();

            if (!File.Exists(str))
            {
                System.IO.File.Copy(defaultPath, str, false);
            }
            Param defaultParam = new Param();

            DataKeep.Serialize(str, false, ref defaultParam);
            str = Application.StartupPath + "\\Temporary\\" + configPath.Split('\\').Last();
            if (!File.Exists(str))
            {
                System.IO.File.Copy(configPath, str, false);
            }
            Param param = new Param();

            DataKeep.Serialize(str, false, ref param);

            try
            {
                foreach (Map map in param.Maps)
                {
                    foreach (DataTable dt in ds.Tables)
                    {
                        if (dt.Columns.Contains(map.Name))
                        {
                            for (int i = 0; i < table.Rows.Count; i++)
                            {
                                DataRow row;
                                if (dt.Rows.Count > i)
                                {
                                    row = dt.Rows[i];
                                }
                                else
                                {
                                    row = dt.NewRow();
                                    dt.Rows.Add(row);
                                }
                                if (table.Columns.Contains(map.Value))
                                {
                                    row[map.Name] = table.Rows[i][map.Value].ToString();
                                }
                            }
                        }
                    }
                }
                foreach (Map map in defaultParam.Maps)
                {
                    foreach (DataTable dt in ds.Tables)
                    {
                        if (dt.Columns.Contains(map.Name))
                        {
                            for (int i = 0; i < table.Rows.Count; i++)
                            {
                                DataRow row;
                                if (dt.Rows.Count > i)
                                {
                                    row = dt.Rows[i];
                                }
                                else
                                {
                                    row = dt.NewRow();
                                    dt.Rows.Add(row);
                                }
                                if (row[map.Name].ToString() == "")
                                {
                                    row[map.Name] = map.Value;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + "导出失败");
                return;
            }
            if (ExcelOperation.WriteExcel2(path, templatePath, ds))
            {
                if (DialogResult.Cancel == MessageBox.Show("文件导出成功是否需要打开文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                }
                else
                {
                    System.Diagnostics.Process.Start(path);
                }
            }
            else
            {
                MessageBox.Show("文件导出失败");
            }
        }