Exemplo n.º 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 (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
            {
                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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        ////<summary>
        ////解析固定刀具表
        ////</summary>
        ////<param name="args"></param>
        public string ImportExcel(int cncTypeId, string path1)
        {
            //解析excel文件
            int    MachTypeID = cncTypeId;
            string path       = path1;
            string fileSuffix = Path.GetExtension(path);

            if (fileSuffix != ".xls" && fileSuffix != ".xlsx")
            {
                return("请输入xls或xlsx格式文件!");
            }
            string err       = "";
            var    data      = GetExcelData(path, ref err);
            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 (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities())
            {
                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);
                        }
                        var tool = wms.JDJS_WMS_Tool_Standard_Table.Where(r => r.MachTypeID == MachTypeID);
                        foreach (var real in tool)
                        {
                            wms.JDJS_WMS_Tool_Standard_Table.Remove(real);
                        }
                        foreach (var item in toolInfos)
                        {
                            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();
                        return("ok");
                    }
                    catch (Exception ex)
                    {
                        mytran.Rollback();

                        return(ex.Message);
                    }
                }
            }
        }