Exemple #1
0
        /// <summary>
        /// 修改单独一条固定刀具信息
        /// </summary>
        /// <param name="ToolID">该固定刀具主键ID</param>
        /// <param name="toolInfo">刀具信息</param>
        /// <param name="ErrStr">错误信息</param>
        /// <returns></returns>
        private bool AlterTool(int ToolID, ToolInfo toolInfo, ref string ErrStr)
        {
            using (WmsAutoEntities wms = new WmsAutoEntities())
            {
                using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction())
                {
                    try
                    {
                        var tool = wms.JDJS_WMS_Tool_Standard_Table.Where(r => r.ID == ToolID).FirstOrDefault();
                        if (tool == null)
                        {
                            mytran.Rollback();
                            ErrStr = "该固定刀具不存在!";
                            return(false);
                        }
                        tool.Feed          = toolInfo.Feed;
                        tool.Knife         = toolInfo.Knife;
                        tool.Name          = toolInfo.ToolName;
                        tool.ProcessStage  = toolInfo.ProcessStage;
                        tool.RazorDiameter = toolInfo.RazorDiameter;
                        tool.RotatingSpeed = toolInfo.RotatingSpeed;
                        tool.Shank         = toolInfo.Shank;
                        tool.Sort          = toolInfo.Sort;
                        tool.Specification = toolInfo.Specification;
                        tool.ToolDiameter  = toolInfo.ToolDiameter;
                        tool.ToolID        = toolInfo.ToolID;
                        tool.ToolLength    = toolInfo.ToolLength;

                        wms.SaveChanges();
                        mytran.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        mytran.Rollback();
                        ErrStr = ex.Message;
                        return(false);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 解析固定刀具表
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //解析excel文件
            int    MachTypeID = 1;
            string path       = @"C:\Users\82144\Desktop\常规刀具表-机床型号绑定.xlsx";
            string fileSuffix = Path.GetExtension(path);

            if (fileSuffix != ".xls" && fileSuffix != ".xlsx")
            {
                Console.WriteLine("请输入xls或xlsx格式文件!");
                return;
            }
            var data      = ReadXls(path, 1);
            var x         = Convert.ToInt32(data.GetLongLength(0));
            var y         = Convert.ToInt32(data.GetLongLength(1));
            int arrayx    = 0;
            int arrayy    = 0;
            var dataArray = new string[x, y];

            foreach (var item in data)
            {
                if (item != null)
                {
                    dataArray[arrayx, arrayy] = item.ToString();
                }
                arrayy++;
                if (arrayy >= y)
                {
                    arrayx++;
                    arrayy = 0;
                }
            }
            using (WmsAutoEntities wms = new WmsAutoEntities())
            {
                using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction())
                {
                    try
                    {
                        List <ToolInfo> toolInfos = new List <ToolInfo>();
                        for (int i = 2; i < x; i++)
                        {
                            ToolInfo toolInfo = new ToolInfo();
                            double   a        = 0;
                            if (dataArray[i, 6] != null && isNumberic(dataArray[i, 6], out a))
                            {
                                toolInfo.Feed = Convert.ToDouble(dataArray[i, 6]);
                            }
                            toolInfo.Knife        = 0;
                            toolInfo.MachTypeID   = MachTypeID;
                            toolInfo.ProcessStage = "精";
                            if (dataArray[i, 5] != null && isNumberic(dataArray[i, 5], out a))
                            {
                                toolInfo.RotatingSpeed = Convert.ToDouble(dataArray[i, 5]);
                            }
                            toolInfo.Shank         = dataArray[i, 1];
                            toolInfo.Sort          = "常规";
                            toolInfo.Specification = dataArray[i, 4];
                            toolInfo.ToolID        = "T" + dataArray[i, 2];
                            if (dataArray[i, 3] != null && isNumberic(dataArray[i, 3], out a))
                            {
                                toolInfo.ToolLength = Convert.ToDouble(dataArray[i, 3]);
                            }
                            toolInfo.ToolName = dataArray[i, 0];
                            toolInfos.Add(toolInfo);
                        }
                        foreach (var item in toolInfos)
                        {
                            var tool = wms.JDJS_WMS_Tool_Standard_Table.Where(r => r.MachTypeID == item.MachTypeID && r.ToolID == item.ToolID);
                            foreach (var real in tool)
                            {
                                wms.JDJS_WMS_Tool_Standard_Table.Remove(real);
                            }
                            JDJS_WMS_Tool_Standard_Table jDJS_WMS_Tool_Standard_Table = new JDJS_WMS_Tool_Standard_Table()
                            {
                                Feed          = item.Feed,
                                Knife         = item.Knife,
                                MachTypeID    = item.MachTypeID,
                                Name          = item.ToolName,
                                ProcessStage  = item.ProcessStage,
                                RazorDiameter = item.RazorDiameter,
                                RotatingSpeed = item.RotatingSpeed,
                                Shank         = item.Shank,
                                Sort          = item.Sort,
                                Specification = item.Specification,
                                ToolDiameter  = item.ToolDiameter,
                                ToolID        = item.ToolID,
                                ToolLength    = item.ToolLength
                            };
                            wms.JDJS_WMS_Tool_Standard_Table.Add(jDJS_WMS_Tool_Standard_Table);
                        }
                        wms.SaveChanges();
                        mytran.Commit();
                    }
                    catch (Exception ex)
                    {
                        mytran.Rollback();
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }
            }
        }