Exemple #1
0
 public Label_template FindLabelTemplatesById(int id)
 {
     using (ERP2008Entities erp2008 = new ERP2008Entities())
     {
         Label_template labelTemplates = null;
         if (id != 0)
         {
             labelTemplates =
                 (from labelTemplate in erp2008.Label_template
                  where labelTemplate.Label_NO == id
                  select labelTemplate
                 ).SingleOrDefault();
         }
         return(labelTemplates);
     }
 }
Exemple #2
0
        /// <summary>
        ///  这里没事务保存会错的
        /// </summary>
        /// <param name="label"></param>
        /// <param name="createQty"></param>
        /// <param name="boxQty"></param>
        /// <param name="reelQty"></param>
        /// <param name="box"></param>
        /// <param name="reel"></param>
        /// <returns></returns>

        /* public int InsertLabel(t_labels label, int createQty, int boxQty, int reelQty, int box, int reel)
         * {
         *   int result = 0;
         *   t_opencardpack opencardpack = openCardPackDao.FindOpencardpackByCode(label.code);
         *   if (opencardpack != null)
         *   {
         *       //还是要返回一个数量
         *       //int oldNumber = execProcedureDao.ExecPrSaveSerialNumber(label.clientCode.ToUpper().Trim(), box+reel);
         *       SqlParameter[] param=new SqlParameter[]
         *       {
         *           new SqlParameter("@clientCode",opencardpack.cCusCode),
         *           new SqlParameter("@number",box+reel)
         *       };
         *       int oldNumber = execProcedureDao.ExecPrSaveSerialNumber(param);
         *       label.typeCode = opencardpack.FProductNo;
         *       for (int i = 0; i < reel; i++)
         *       {
         *           label.qty = reelQty.ToString();
         *           label.serialNumber = oldNumber;
         *           label.workOrder = opencardpack.Fwono;
         *           //检查重要是否为空
         *           int objectNull =ObjectIsNull(label);
         *           if (objectNull<=0)
         *           {
         *               return 0;
         *           }
         *           result=tLabelsDao.InsertLabel(label);
         *           if (result == 0)
         *           {
         *               break;
         *           }
         *           oldNumber++;
         *       }
         *       for (int i = 0; i < box; i++)
         *       {
         *           label.qty = boxQty.ToString();
         *           label.serialNumber = oldNumber;
         *           result=tLabelsDao.InsertLabel(label);
         *           if (result == 0)
         *           {
         *               break;
         *           }
         *           oldNumber++;
         *       }
         *   }
         *   return result;
         * }*/
        /// <summary>
        /// 添加标签信息
        /// </summary>
        /// <param name="label">标签对象</param>
        /// <param name="createQty">生成的总数</param>
        /// <param name="boxQty">盒子数量</param>
        /// <param name="reelQty">卷盘数量</param>
        /// <param name="box">盒子标签数量</param>
        /// <param name="reel">卷盘标签数量</param>
        /// <returns></returns>
        public int InsertLabel(t_labels label, int createQty, int boxQty, int reelQty, int box, int reel, Boolean isBoxPack)
        {
            List <t_labels> labels       = new List <t_labels>();
            int             result       = 0;
            t_opencardpack  opencardpack = openCardPackDao.FindOpencardpackByCode(label.code);

            if (opencardpack != null)
            {
                string uidCode = null;
                if (label.labelTemplateAddressId != 235)
                {
                    uidCode = label.clientCode.Trim();
                    string[] tpv = new[] { "T4003", "T4011", "T4017", "T4021", "T4022", "T4027", "T4008", "T4012", "T4016", "T4023" };
                    if (tpv.Contains(uidCode))
                    {
                        uidCode = "TPV";
                    }
                }
                else
                {
                    uidCode = "STANDARD";
                }
                SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@clientCode", uidCode),
                    new SqlParameter("@number", box + reel)
                };
                //通过存储过程获取流水号
                long oldNumber = execProcedureDao.ExecPrSaveSerialNumber(param);
                //label.typeCode = opencardpack.FProductNo;
                label.workOrder = opencardpack.Fwono;
                //获取服务器时间
                label.createDate = customUtilityDao.GetServerDateTime().ToString("yyyy-MM-dd HH:mm:ss");
                //最小包装非内盒
                if (!isBoxPack)
                {
                    int tempReelQty = createQty;
                    for (int i = 0; i < reel; i++)
                    {
                        t_labels newLabes = FanShe.Mapper <t_labels, t_labels>(label);
                        if (tempReelQty > reelQty)
                        {
                            newLabes.qty = reelQty;
                        }
                        else
                        {
                            newLabes.qty = tempReelQty;
                        }
                        tempReelQty           = tempReelQty - reelQty;
                        newLabes.serialNumber = oldNumber;
                        newLabes.UID          = CreateUID(newLabes);
                        newLabes.packType     = 1; //1为卷盘包装类型 2为内盒包装类型 3为外箱包装类型

                        //添加客户特殊要求
                        Label_template template     = labelTemplateDao.FindLabelTemplatesById(label.labelTemplateAddressId);
                        string         templateName = template.Label_describe.Trim().ToUpper();
                        //newLabes引用类型返回和不返回一样,所以这里调用一下那标签对象了
                        clientRequireFactoryBll.InsertClientRequire(newLabes, templateName);

                        //检查重要属性是否为空
                        int objectNull = ObjectIsNull(newLabes);
                        if (objectNull <= 0)
                        {
                            return(0);
                        }
                        labels.Add(newLabes); //执行添加标签信息
                        oldNumber++;
                    }
                }
                int tempBoxQty = createQty;
                for (int i = 0; i < box; i++)
                {
                    t_labels newLabes = FanShe.Mapper <t_labels, t_labels>(label);
                    if (tempBoxQty > boxQty)
                    {
                        newLabes.qty = boxQty;
                    }
                    else
                    {
                        newLabes.qty = tempBoxQty;
                    }
                    tempBoxQty            = tempBoxQty - boxQty;
                    newLabes.serialNumber = oldNumber;
                    newLabes.UID          = CreateUID(newLabes);
                    newLabes.packType     = 2;
                    Label_template template     = labelTemplateDao.FindLabelTemplatesById(label.labelTemplateAddressId);
                    string         templateName = template.Label_describe.Trim().ToUpper();
                    clientRequireFactoryBll.InsertClientRequire(newLabes, templateName);
                    //检查重要属性是否为空
                    int objectNull = ObjectIsNull(newLabes);
                    if (objectNull <= 0)
                    {
                        return(0);
                    }
                    labels.Add(newLabes);
                    oldNumber++;
                }
                //保存前再次确认生成的标签数量与前台计算的标签数量是否一致才保存
                result = labels.Count == (box + reel) ? tLabelsDao.InsertLabel(labels) : 0;
            }
            return(result);
        }
        public int PrintLabel(List <t_labels> labels, ref string message)
        {
            //if (labels.Count != 0)
            //{
            //    Engine engin = new Engine(true);
            //    Label_template template = labelTemplateDao.FindLabelTemplatesById(labels[0].labelTemplateAddressId);
            //    LabelFormatDocument format = engin.Documents.Open(template.Label_Path, template.Print_Cmd);
            //    format.PrintSetup.IdenticalCopiesOfLabel = 1; //默认打印一张
            //    foreach (t_labels lb in labels)
            //    {
            //        foreach (SubString sub in format.SubStrings)
            //        {
            //            var types = lb.GetType();
            //            foreach (PropertyInfo property in types.GetProperties())
            //            {
            //                if (property.Name == sub.Name)
            //                {
            //                    try
            //                    {
            //                        sub.Value = property.GetValue(lb, null).ToString();
            //                    }
            //                    catch (Exception)
            //                    {
            //                        sub.Value = "";
            //                    }
            //                }
            //            }
            //        }
            //        Messages mes;
            //        //Result result = format.Print(template.Label_describe + "-" + template.Label_NO,2000, out mes);
            //        Result result = format.Print(template.Label_describe + "-" + template.Label_NO, out mes);
            //        message = mes[0].Text;
            //    }
            //    format.Close(SaveOptions.DoNotSaveChanges);
            //    engin.Stop(SaveOptions.DoNotSaveChanges);
            //    return 1;
            //}
            //return 0;

            try
            {
                Engine         engin    = new Engine(true);
                Label_template template = labelTemplateDao.FindLabelTemplatesById(labels[0].labelTemplateAddressId);
                //LabelFormatDocument format = engin.Documents.Open(template.Label_Path, template.Print_Cmd);
                SystemDatabaseConnection conn = new SystemDatabaseConnection();
                conn.Method         = SystemDatabaseConnectionMethod.Manual;
                conn.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;
                conn.ServerName     = @"192.168.1.201";
                conn.DatabaseName   = "ERP2008";
                conn.UserName       = "******";
                conn.Password       = "******";
                conn.Connect();



                string sqlcommand = "SELECT * FROM  dbo.t_labels WHERE code='" + labels[0].code + "'";
                OLEDB  oledb      = new OLEDB("ERP2008");
                oledb.SQLStatement = sqlcommand;
                LabelFormatDocument format = engin.Documents.Open(template.Label_Path, template.Print_Cmd);
                format.DatabaseConnections.SetDatabaseConnection(oledb);
                format.PrintSetup.IdenticalCopiesOfLabel = 1; //默认打印一张
                //format.Print();
                Messages mes;
                Result   result = format.Print(template.Label_describe + "-" + template.Label_NO, 2000, out mes);
                format.Close(SaveOptions.DoNotSaveChanges);
                engin.Stop();
                return(1);
            }
            catch (Exception)
            {
                throw;
                return(0);
            }
        }
        public int PrintLabel(t_labels label, int printcount, int[] ids, ref string message)
        {
            Engine engin = null;
            LabelFormatDocument format = null;

            try
            {
                engin = new Engine(true);
                Label_template           template = labelTemplateDao.FindLabelTemplatesById(label.labelTemplateAddressId);
                SystemDatabaseConnection conn     = new SystemDatabaseConnection();
                conn.Method         = SystemDatabaseConnectionMethod.Manual;
                conn.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;
                conn.ServerName     = @"192.168.1.201";
                conn.DatabaseName   = "ERP2008";
                conn.UserName       = "******";
                conn.Password       = "******";
                conn.Connect();
                string sqlcommand = null;
                if (ids.Length == 0 || ids == null)
                {
                    sqlcommand = "SELECT * FROM  dbo.t_labels WHERE code='" + label.code + "'";
                }
                else
                {
                    sqlcommand = "SELECT * FROM  t_labels WHERE  autoid IN( ";
                    foreach (int id in ids)
                    {
                        sqlcommand = sqlcommand + id + ",";
                    }
                    sqlcommand = sqlcommand.Substring(0, sqlcommand.Length - 1);
                    sqlcommand = sqlcommand + ")";
                }
                OLEDB oledb = new OLEDB("ERP2008");
                oledb.SQLStatement = sqlcommand;
                format             = engin.Documents.Open(template.Label_Path, template.Print_Cmd);
                format.DatabaseConnections.SetDatabaseConnection(oledb);
                format.PrintSetup.IdenticalCopiesOfLabel = printcount; //默认打印一张
                Messages mes;
                Result   result = format.Print(template.Label_describe + "-" + template.Label_NO, 10000);
                if (Result.Failure == result)
                {
                    message += result;
                    return(0);
                }
                else if (Result.Success == result)
                {
                    message += result;
                    return(0);
                }

                return(1);
            }
            catch (Exception e)
            {
                message += e.Message;
                return(0);
            }
            finally
            {
                if (format != null)
                {
                    format.Close(SaveOptions.DoNotSaveChanges);
                }
                if (engin != null)
                {
                    engin.Stop();
                }
            }
        }