/// <summary>
 /// 创建一个委托单信息
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个委托单信息</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, ORDER_TASK_INFORMATION entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
        public ActionResult Edit(string id)
        {
            ORDER_TASK_INFORMATION ont = m_BLL.GetById(id);
            var data = (from f in ont.SIGN.AsQueryable()
                        orderby f.CREATETIME
                        select f).FirstOrDefault();

            if (data != null)
            {
                ViewBag.HTML = data.HTMLVALUE;
                ViewBag.Img  = data.PICTURE;
            }


            return(View());
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public Common.ClientResult.Result Post([FromBody] ORDER_TASK_INFORMATION entity)
        {
            Common.ClientResult.OrderTaskGong result = new Common.ClientResult.OrderTaskGong();
            if (entity != null && ModelState.IsValid)
            {
                string currentPerson = GetCurrentPerson();
                entity.CREATETIME   = DateTime.Now;
                entity.CREATEPERSON = currentPerson;

                entity.ID = Result.GetNewId();
                string returnValue = string.Empty;
                if (m_BLL.Create(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",委托单信息的信息的Id为" + entity.ID, "委托单信息"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Succeed;
                    result.Message = Suggestion.InsertSucceed;
                    result.Id      = entity.ID;
                    return(result); //提示创建成功
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return(true);
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息," + returnValue, "委托单信息"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Fail;
                    result.Message = Suggestion.InsertFail + returnValue;
                    return(result); //提示插入失败
                }
            }

            result.Code    = Common.ClientCode.FindNull;
            result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对
            return(result);
        }
        // PUT api/<controller>/5
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Common.ClientResult.Result Put([FromBody] ORDER_TASK_INFORMATION entity)
        {
            Common.ClientResult.Result result = new Common.ClientResult.Result();
            if (entity != null && ModelState.IsValid)
            {   //数据校验
                string currentPerson = GetCurrentPerson();
                entity.UPDATETIME   = DateTime.Now;
                entity.UPDATEPERSON = currentPerson;

                string returnValue = string.Empty;
                if (m_BLL.Edit(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",委托单信息信息的Id为" + entity.ID, "委托单信息"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Succeed;
                    result.Message = Suggestion.UpdateSucceed;
                    return(result); //提示更新成功
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return(true);
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",委托单信息信息的Id为" + entity.ID + "," + returnValue, "委托单信息"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Fail;
                    result.Message = Suggestion.UpdateFail + returnValue;
                    return(result); //提示更新失败
                }
            }
            result.Code    = Common.ClientCode.FindNull;
            result.Message = Suggestion.UpdateFail + "请核对输入的数据的格式";
            return(result); //提示输入的数据的格式不对
        }
 public Common.ClientResult.Result PutUpdate([FromBody] ORDER_TASK_INFORMATION entity)
 {
     Common.ClientResult.OrderTaskGong result = new Common.ClientResult.OrderTaskGong();
     {
         string currentPerson = GetCurrentPerson();
         if (!string.IsNullOrEmpty(entity.ID))
         {
             entity.CREATETIME   = DateTime.Now;
             entity.CREATEPERSON = currentPerson;
             foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)
             {
                 item.UPDATETIME   = DateTime.Now;
                 item.UPDATEPERSON = currentPerson;
                 if (string.IsNullOrWhiteSpace(item.UNDERTAKE_LABORATORYID))
                 {
                     LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息,实验室为空", "委托单信息");//写入日志
                     result.Code    = Common.ClientCode.Fail;
                     result.Message = "实验室不能为空";
                     return(result); //提示插入失败
                 }
             }
             string returnValue = string.Empty;
             foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)
             {
                 if (m_BLL.EditField(ref validationErrors, item))
                 {
                     LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息的Id为" + item.ID, "委托单信息");//写入日志
                     result.Code    = Common.ClientCode.Succeed;
                     result.Message = Suggestion.UpdateSucceed;
                 }
                 else
                 {
                     LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息的Id为" + item.ID, "委托单信息");//写入日志
                     result.Code    = Common.ClientCode.Fail;
                     result.Message = Suggestion.UpdateFail;
                     return(result);
                 }
             }
             if (m_BLL4.EditField(ref validationErrors, entity))
             {
                 LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",委托单信息的信息的Id为" + entity.ID, "委托单信息");//写入日志
                 result.Code    = Common.ClientCode.Succeed;
                 result.Message = Suggestion.InsertSucceed;
                 result.Id      = entity.ID;
                 return(result); //提示创建成功
             }
             else
             {
                 if (validationErrors != null && validationErrors.Count > 0)
                 {
                     validationErrors.All(a =>
                     {
                         returnValue += a.ErrorMessage;
                         return(true);
                     });
                 }
                 LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息," + returnValue, "委托单信息");//写入日志
                 result.Code    = Common.ClientCode.Fail;
                 result.Message = Suggestion.InsertFail + returnValue;
                 return(result); //提示插入失败
             }
         }
     }
     result.Code    = Common.ClientCode.FindNull;
     result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对
     return(result);
 }
        public ActionResult Save(ORDER_TASK_INFORMATION entity)
        {
            Common.ClientResult.OrderTaskGong result = new Common.ClientResult.OrderTaskGong();
            try
            {
                Common.Account account = GetCurrentAccount();
                if (string.IsNullOrWhiteSpace(entity.ID))
                {
                    List <COMPANY> companylist  = m_BLL2.GetByParam(null, "asc", "ID", "COMPANYNAME&" + entity.INSPECTION_ENTERPRISE + "");
                    List <COMPANY> companylist2 = m_BLL2.GetByParam(null, "asc", "ID", "COMPANYNAME&" + entity.CERTIFICATE_ENTERPRISE + "");


                    foreach (var item in companylist)
                    {
                        if (item.COMPANY2 != null)
                        {
                            entity.INSPECTION_ENTERPRISEHELLD = item.COMPANY2.COMPANYNAME;
                            break;
                        }
                    }
                    foreach (var item in companylist2)
                    {
                        if (item.COMPANY2 != null)
                        {
                            entity.CERTIFICATE_ENTERPRISEHELLD = item.COMPANY2.COMPANYNAME;
                            break;
                        }
                        else
                        {
                            entity.CERTIFICATE_ENTERPRISEHELLD = entity.CERTIFICATE_ENTERPRISE;
                            break;
                        }
                    }
                    string ORDER_NUMBER = m_BLL.GetORDER_NUMBER(ref validationErrors);
                    var    order        = ORDER_NUMBER.Split('*');// DC2016001 * 1 * 2016
                    entity.ORDER_STATUS = Common.ORDER_STATUS_INFORMATION.保存.ToString();
                    var ms = new System.IO.MemoryStream();
                    entity.CREATETIME   = DateTime.Now;
                    entity.CREATEPERSON = account.PersonName;
                    entity.ID           = Result.GetNewId();

                    entity.ORDER_NUMBER   = order[0].ToString();
                    entity.ORSERIALNUMBER = Convert.ToDecimal(order[1]);
                    entity.ORYEARS        = order[2].ToString();

                    entity.ORDER_STATUS = Common.ORDER_STATUS_INFORMATION.保存.ToString();

                    string path = Server.MapPath("~/up/ErWeiMa/");
                    foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)
                    {
                        item.ID           = Result.GetNewId();
                        item.CREATETIME   = DateTime.Now;
                        item.CREATEPERSON = account.PersonName;
                        string bianma = Regex.Replace(Guid.NewGuid().ToString().Replace("-", ""), "[a-z]", "", RegexOptions.IgnoreCase).Substring(0, 8);
                        item.BAR_CODE_NUM = entity.ORSERIALNUMBER.ToString().PadLeft(4, '0') + bianma;
                        //二维码生成
                        ErrorCorrectionLevel Ecl    = ErrorCorrectionLevel.M; //误差校正水平
                        string           Content    = item.ID;                //待编码内容
                        QuietZoneModules QuietZones = QuietZoneModules.Two;   //空白区域
                        int    ModuleSize           = 3;                      //大小
                        var    encoder = new QrEncoder(Ecl);
                        QrCode qr;
                        if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵
                        {
                            Renderer r = new Renderer(ModuleSize);
                            r.QuietZoneModules = QuietZones;
                            r.WriteToStream(qr.Matrix, ms, ImageFormat.Png);
                        }
                        //QRCodeHelper.GetQRCode(item.ID, ms);
                        var pathErWeiMa = path + item.ID + ".png";

                        //System.IO.FileStream fs = new System.IO.FileStream(pathErWeiMa, System.IO.FileMode.OpenOrCreate);


                        //System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
                        #region 二维码加字
                        System.IO.FileStream fss = new System.IO.FileStream(Server.MapPath("~/up/moban.png"), System.IO.FileMode.OpenOrCreate);
                        int filelength           = 0;
                        filelength = (int)fss.Length;        //获得文件长度
                        Byte[] image = new Byte[filelength]; //建立一个字节数组
                        fss.Read(image, 0, filelength);      //按字节流读取
                        System.Drawing.Image imag = System.Drawing.Image.FromStream(fss);
                        //System.Drawing.Image Image = System.Drawing.Image.FromStream(ms);
                        Graphics g = null;
                        g = Graphics.FromImage(imag);
                        string xinghao = item.BAR_CODE_NUM;//需要写入的字
                        //string xinghao = "123456789abcd";//需要写入的字
                        int          w      = imag.Width;
                        int          h      = imag.Height; //entity.INSPECTION_ENTERPRISE
                        StringFormat format = new StringFormat();
                        format.Alignment     = StringAlignment.Center;
                        format.LineAlignment = StringAlignment.Center;
                        DrawString(g, item.BAR_CODE_NUM, new Font("宋体", 14), new SolidBrush(Color.Black), new PointF(430, 200), format, -90f);
                        var COMPANY = m_BLL2.GetAll();
                        var dw      = COMPANY.Where(m => m.COMPANYNAME == entity.INSPECTION_ENTERPRISE).Select(s => s.POSTCODE).Single();
                        DrawString(g, dw, new Font("宋体", 14), new SolidBrush(Color.Black), new PointF(490, 200), format, -90f);
                        //g.DrawString(item.BAR_CODE_NUM, new Font("宋体", 10), Brushes.Red, new PointF(350, 0));//x:值越大越靠右;y:值越小越靠上
                        //if (entity.INSPECTION_ENTERPRISE.Length>9)
                        //{
                        //    string zhi = entity.INSPECTION_ENTERPRISE.Substring(0, 9);
                        //    string zhi2= entity.INSPECTION_ENTERPRISE.Remove(0, 9);
                        //    g.DrawString(zhi, new Font("宋体", 14), Brushes.Red, new PointF(0, 320));//x:值越大越靠右;y:值越小越靠上
                        //    g.DrawString(zhi2, new Font("宋体", 14), Brushes.Red, new PointF(0, 380));//x:值越大越靠右;y:值越小越靠上
                        //}
                        //else
                        //{
                        //    g.DrawString(entity.INSPECTION_ENTERPRISE, new Font("宋体", 14), Brushes.Red, new PointF(0, 320));//x:值越大越靠右;y:值越小越靠上
                        //}

                        System.Drawing.Image ig = CombinImage(imag, ms);
                        //System.Drawing.Image ig = imag;
                        fss.Close();
                        TuPanBaoCun(ig, pathErWeiMa);
                        //生成pdf
                        //图片
                        //Image image = Image.GetInstance(imagePath);
                        //cell = new PdfPCell(image, true);
                        //table.AddCell(cell);
                        PDF.Create(path + item.ID);
                        #endregion

                        //w.Write(ms.ToArray());
                        //fs.Close();
                        //器具明细信息_承接实验室表添加数据
                        foreach (var it in item.UNDERTAKE_LABORATORYID.TrimEnd(',').Split(','))
                        {
                            item.APPLIANCE_LABORATORY.Add(new APPLIANCE_LABORATORY()
                            {
                                ID = Result.GetNewId(),
                                UNDERTAKE_LABORATORYID   = it,
                                ORDER_STATUS             = Common.ORDER_STATUS.保存.ToString(),
                                EQUIPMENT_STATUS_VALUUMN = Common.ORDER_STATUS.保存.GetHashCode().ToString(),
                                DISTRIBUTIONPERSON       = account.PersonName,
                                DISTRIBUTIONTIME         = DateTime.Now,
                                CREATEPERSON             = account.PersonName,
                                CREATETIME = DateTime.Now,
                                ISRECEIVE  = Common.ISRECEIVE.是.ToString(),
                                RECYCLING  = entity.RECYCLING
                            });
                        }
                    }
                    ms.Close();

                    string returnValue = string.Empty;
                    if (m_BLL.Create(ref validationErrors, entity))
                    {
                        LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",委托单信息的信息的Id为" + entity.ID, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Succeed;
                        result.Message = Suggestion.InsertSucceed;
                        result.Id      = entity.ID;
                        return(Json(result)); //提示创建成功
                    }
                    else
                    {
                        if (validationErrors != null && validationErrors.Count > 0)
                        {
                            validationErrors.All(a =>
                            {
                                returnValue += a.ErrorMessage;
                                return(true);
                            });
                        }
                        LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息," + returnValue, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Fail;
                        result.Message = Suggestion.InsertFail + returnValue;
                        return(Json(result)); //提示插入失败
                    }
                }
                else
                {
                }


                result.Code    = Common.ClientCode.FindNull;
                result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对
            }
            catch (Exception lastError)
            {
                // fss.Close();
                ExceptionsHander.WriteExceptions(lastError);//将异常写入数据库
            }
            return(Json(result));
        }
        public Common.ClientResult.Result PutUpdate([FromBody] ORDER_TASK_INFORMATION entity)
        {
            Common.ClientResult.OrderTaskGong result = new Common.ClientResult.OrderTaskGong();
            {
                string currentPerson = GetCurrentPerson();
                if (!string.IsNullOrEmpty(entity.ID))
                {
                    entity.CREATETIME   = DateTime.Now;
                    entity.CREATEPERSON = currentPerson;
                    // entity.ID = Result.GetNewId();
                    entity.ORDER_STATUS = Common.ORDER_STATUS_INFORMATION.已分配.ToString();
                    APPLIANCE_LABORATORY ary  = new APPLIANCE_LABORATORY();
                    APPLIANCE_LABORATORY ary2 = new APPLIANCE_LABORATORY();
                    foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)//器具信息
                    {
                        item.CREATETIME   = DateTime.Now;
                        item.CREATEPERSON = currentPerson;
                        ary  = null;
                        ary2 = null;
                        //器具明细信息_承接实验室表添加数据
                        List <APPLIANCE_LABORATORY> appory = m_BLL3.GetByRefAPPLIANCE_DETAIL_INFORMATIOID(item.ID);
                        if (appory.Count >= 2)
                        {
                            ary  = appory[0];
                            ary2 = appory[1];
                        }
                        else
                        {
                            ary = appory[0];
                        }
                        if (appory.Count >= 2)
                        {
                            string ISRECEIVE = string.Empty;
                            if (ary.ORDER_STATUS == Common.ORDER_STATUS.已退回.ToString())
                            {
                                if (ary2.ORDER_STATUS == Common.ORDER_STATUS.已领取.ToString())
                                {
                                    ISRECEIVE = Common.ISRECEIVE.否.ToString();
                                }
                                else
                                {
                                    ISRECEIVE = Common.ISRECEIVE.是.ToString();
                                }
                                item.APPLIANCE_LABORATORY.Add(new APPLIANCE_LABORATORY()
                                {
                                    ID = ary.ID,
                                    UNDERTAKE_LABORATORYID   = item.UNDERTAKE_LABORATORYID,
                                    ORDER_STATUS             = Common.ORDER_STATUS.已分配.ToString(),
                                    EQUIPMENT_STATUS_VALUUMN = Common.ORDER_STATUS.已分配.GetHashCode().ToString(),
                                    DISTRIBUTIONPERSON       = currentPerson,
                                    DISTRIBUTIONTIME         = DateTime.Now,
                                    CREATEPERSON             = currentPerson,
                                    CREATETIME = DateTime.Now,
                                    ISRECEIVE  = ISRECEIVE
                                });
                            }
                            else if (ary2.ORDER_STATUS == Common.ORDER_STATUS.已退回.ToString())
                            {
                                if (ary.ORDER_STATUS == Common.ORDER_STATUS.已领取.ToString())
                                {
                                    ISRECEIVE = Common.ISRECEIVE.否.ToString();
                                }
                                else
                                {
                                    ISRECEIVE = Common.ISRECEIVE.是.ToString();
                                }
                                item.APPLIANCE_LABORATORY.Add(new APPLIANCE_LABORATORY()
                                {
                                    ID = ary2.ID,
                                    UNDERTAKE_LABORATORYID   = item.UNDERTAKE_LABORATORYID,
                                    ORDER_STATUS             = Common.ORDER_STATUS.已分配.ToString(),
                                    EQUIPMENT_STATUS_VALUUMN = Common.ORDER_STATUS.已分配.GetHashCode().ToString(),
                                    DISTRIBUTIONPERSON       = currentPerson,
                                    DISTRIBUTIONTIME         = DateTime.Now,
                                    CREATEPERSON             = currentPerson,
                                    CREATETIME = DateTime.Now,
                                    ISRECEIVE  = ISRECEIVE
                                });
                            }
                        }
                        else
                        {
                            if (ary.ORDER_STATUS == Common.ORDER_STATUS.已退回.ToString())
                            {
                                item.APPLIANCE_LABORATORY.Add(new APPLIANCE_LABORATORY()
                                {
                                    ID = ary.ID,
                                    UNDERTAKE_LABORATORYID   = item.UNDERTAKE_LABORATORYID,
                                    ORDER_STATUS             = Common.ORDER_STATUS.已分配.ToString(),
                                    EQUIPMENT_STATUS_VALUUMN = Common.ORDER_STATUS.已分配.GetHashCode().ToString(),
                                    DISTRIBUTIONPERSON       = currentPerson,
                                    DISTRIBUTIONTIME         = DateTime.Now,
                                    CREATEPERSON             = currentPerson,
                                    CREATETIME = DateTime.Now,
                                    ISRECEIVE  = Common.ISRECEIVE.是.ToString()
                                });
                            }
                        }
                    }
                    string returnValue = string.Empty;
                    foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)
                    {
                        if (m_BLL2.EditField(ref validationErrors, item))
                        {
                            LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息的Id为" + item.ID, "委托单信息"
                                                           );//写入日志
                            result.Code    = Common.ClientCode.Succeed;
                            result.Message = Suggestion.UpdateSucceed;
                        }
                        else
                        {
                            LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息的Id为" + item.ID, "委托单信息"
                                                           );//写入日志
                            result.Code    = Common.ClientCode.Fail;
                            result.Message = Suggestion.UpdateFail;
                            return(result);
                        }
                        foreach (var item2 in item.APPLIANCE_LABORATORY)
                        {
                            if (m_BLL3.EditField(ref validationErrors, item2))
                            {
                                LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息_承接实验室的Id为" + item2.ID, "委托单信息"
                                                               );//写入日志
                                result.Code    = Common.ClientCode.Succeed;
                                result.Message = Suggestion.UpdateSucceed;
                            }
                            else
                            {
                                LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",器具明细信息_承接实验室的Id为" + item2.ID, "委托单信息"
                                                               );//写入日志
                                result.Code    = Common.ClientCode.Fail;
                                result.Message = Suggestion.UpdateFail;
                                return(result);
                            }
                        }
                    }

                    if (m_BLL.EditField(ref validationErrors, entity))
                    {
                        LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",委托单信息的信息的Id为" + entity.ID, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Succeed;
                        result.Message = Suggestion.InsertSucceed;
                        result.Id      = entity.ID;
                        return(result); //提示创建成功
                    }
                    else
                    {
                        if (validationErrors != null && validationErrors.Count > 0)
                        {
                            validationErrors.All(a =>
                            {
                                returnValue += a.ErrorMessage;
                                return(true);
                            });
                        }
                        LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息," + returnValue, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Fail;
                        result.Message = Suggestion.InsertFail + returnValue;
                        return(result); //提示插入失败
                    }
                }
                else
                {
                }
            }

            result.Code    = Common.ClientCode.FindNull;
            result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对

            return(result);
        }
        public ORDER_TASK_INFORMATION Get(string id)
        {
            ORDER_TASK_INFORMATION item = m_BLL.GetById(id);

            return(item);
        }
        public ORDER_TASK_INFORMATIONShow PostID(string id)
        {
            var    data = new ORDER_TASK_INFORMATIONShow();
            string UNDERTAKE_LABORATORYID    = string.Empty;
            string ORDER_STATUS              = string.Empty;
            string ORDER_STATUS_NAME         = string.Empty;
            ORDER_TASK_INFORMATION queryData = m_BLL.GetById(id);
            string tiqu = string.Empty;//提取日期

            foreach (var s in queryData.APPLIANCE_DETAIL_INFORMATION)
            {
                UNDERTAKE_LABORATORYID = null;
                ORDER_STATUS           = null;
                ORDER_STATUS_NAME      = null;
                List <APPLIANCE_LABORATORY> list = m_BLL3.GetByRefAPPLIANCE_DETAIL_INFORMATIOID(s.ID);
                foreach (var item2 in list)
                {
                    ORDER_STATUS += item2.ORDER_STATUS + ",";
                    if (item2.ORDER_STATUS == Common.ORDER_STATUS.已退回.ToString())
                    {
                        ORDER_STATUS_NAME = item2.UNDERTAKE_LABORATORYID + item2.ORDER_STATUS;
                    }
                    if (string.IsNullOrWhiteSpace(UNDERTAKE_LABORATORYID))
                    {
                        UNDERTAKE_LABORATORYID = item2.UNDERTAKE_LABORATORYID;
                    }
                    else
                    {
                        UNDERTAKE_LABORATORYID += "," + item2.UNDERTAKE_LABORATORYID;
                    }
                }
                if (list.Count > 1)
                {
                    tiqu = Convert.ToDateTime(queryData.CREATETIME).AddDays(28).ToString("yyyy-MM-dd");
                }
                else
                {
                    tiqu = Convert.ToDateTime(queryData.CREATETIME).AddDays(14).ToString("yyyy-MM-dd");
                }
                s.UNDERTAKE_LABORATORYID = UNDERTAKE_LABORATORYID;
                var show = new Models.APPLIANCE_DETAIL_INFORMATIONShow()
                {
                    ID                           = s.ID,
                    BAR_CODE_NUM                 = s.BAR_CODE_NUM,
                    APPLIANCE_NAME               = s.APPLIANCE_NAME,
                    VERSION                      = s.VERSION,
                    FORMAT                       = s.FORMAT,
                    FACTORY_NUM                  = s.FACTORY_NUM,
                    NUM                          = s.NUM,
                    ATTACHMENT                   = s.ATTACHMENT,
                    APPEARANCE_STATUS            = s.APPEARANCE_STATUS,
                    MAKE_ORGANIZATION            = s.MAKE_ORGANIZATION,
                    REMARKS                      = s.REMARKS,
                    END_PLAN_DATE                = s.END_PLAN_DATE,
                    ORDER_TASK_INFORMATIONID     = s.ORDER_TASK_INFORMATIONID,
                    CREATETIME                   = s.CREATETIME,
                    CREATEPERSON                 = s.CREATEPERSON,
                    UPDATETIME                   = s.UPDATETIME,
                    UPDATEPERSON                 = s.UPDATEPERSON,
                    APPLIANCE_RECIVE             = s.APPLIANCE_RECIVE,
                    APPLIANCE_PROGRESS           = s.APPLIANCE_PROGRESS,
                    ISOVERDUE                    = s.ISOVERDUE,
                    OVERDUE                      = s.OVERDUE,
                    STORAGEINSTRUCTIONS          = s.STORAGEINSTRUCTIONS,
                    STORAGEINSTRUCTI_STATU       = s.STORAGEINSTRUCTI_STATU,
                    UNDERTAKE_LABORATORYIDString = UNDERTAKE_LABORATORYID.TrimEnd(','),
                    ORDER_STATUS                 = ORDER_STATUS,
                    ORDER_STATUS_NAME            = ORDER_STATUS_NAME,
                    TIQURIQI                     = tiqu
                };
                data.APPLIANCE_DETAIL_INFORMATIONShows.Add(show);
            }
            data.ID                             = queryData.ID;
            data.ORDER_NUMBER                   = queryData.ORDER_NUMBER;
            data.ACCEPT_ORGNIZATION             = queryData.ACCEPT_ORGNIZATION;
            data.INSPECTION_ENTERPRISE          = queryData.INSPECTION_ENTERPRISE;
            data.INSPECTION_ENTERPRISE_ADDRESS  = queryData.INSPECTION_ENTERPRISE_ADDRESS;
            data.INSPECTION_ENTERPRISE_POST     = queryData.INSPECTION_ENTERPRISE_POST;
            data.CONTACTS                       = queryData.CONTACTS;
            data.CONTACT_PHONE                  = queryData.CONTACT_PHONE;
            data.FAX                            = queryData.FAX;
            data.CERTIFICATE_ENTERPRISE         = queryData.CERTIFICATE_ENTERPRISE;
            data.CERTIFICATE_ENTERPRISE_ADDRESS = queryData.CERTIFICATE_ENTERPRISE_ADDRESS;
            data.CERTIFICATE_ENTERPRISE_POST    = queryData.CERTIFICATE_ENTERPRISE_POST;
            data.CONTACTS2                      = queryData.CONTACTS2;
            data.CONTACT_PHONE2                 = queryData.CONTACT_PHONE2;
            data.FAX2                           = queryData.FAX2;
            data.CUSTOMER_SPECIFIC_REQUIREMENTS = queryData.CUSTOMER_SPECIFIC_REQUIREMENTS;
            data.ORDER_STATUS                   = queryData.ORDER_STATUS;
            data.CREATETIME                     = queryData.CREATETIME;

            AccountBLL    acc  = new AccountBLL();
            List <string> name = new List <string>();

            name.Add(queryData.CREATEPERSON);
            var myname = acc.GetPictureByName(name)[queryData.CREATEPERSON].MyName;

            data.CREATEPERSON = myname;/////////
            data.UPDATETIME   = queryData.UPDATETIME;
            data.UPDATEPERSON = queryData.UPDATEPERSON;
            return(data);
        }
示例#10
0
        public ActionResult Show(string baogaoid, string qijuid)
        {
            ORDER_TASK_INFORMATIONShow osi = new ORDER_TASK_INFORMATIONShow();

            #region 器具信息数据展示处理
            string        ORDER_TASK_INFORMATIONID = string.Empty;
            List <string> Bao = new List <string>();
            List <string> Qi  = new List <string>();
            if (!string.IsNullOrWhiteSpace(baogaoid))
            {
                foreach (var item in baogaoid.Split('|'))
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        ORDER_TASK_INFORMATIONID = item.Split('~')[1];
                        if (!Bao.Contains(item.Split('~')[0]))
                        {
                            Bao.Add(item.Split('~')[0]);
                        }
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(qijuid))
            {
                foreach (var item in qijuid.Split('|'))
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        ORDER_TASK_INFORMATIONID = item.Split('~')[1];
                        if (!Qi.Contains(item.Split('~')[0]))
                        {
                            Qi.Add(item.Split('~')[0]);
                        }
                    }
                }
            }
            int total = 0;
            if (!string.IsNullOrWhiteSpace(ORDER_TASK_INFORMATIONID))
            {
                List <VQIJULINGQU2> queryData = m_BLL5.GetByParam(null, 1, 100, "DESC", "ID", "ORDER_TASK_INFORMATIONID&" + ORDER_TASK_INFORMATIONID, ref total).Distinct().ToList();
                foreach (var q in queryData)
                {
                    q.REPORTTORECEVESTATE = string.Empty;
                }
                foreach (var item in Bao)
                {
                    foreach (var q in queryData)
                    {
                        if (item == q.PREPARE_SCHEMEID)
                        {
                            q.REPORTTORECEVESTATE = q.REPORTNUMBER;
                        }
                    }
                }
                foreach (var item in Qi)
                {
                    foreach (var q in queryData)
                    {
                        if (item == q.ID)
                        {
                            q.APPLIANCECOLLECTIONSATE = "本次领取";
                        }
                    }
                }
                foreach (var item in queryData)
                {
                    var vq = new VQIJULINGQU2Show()
                    {
                        ID                       = item.ID,
                        APPLIANCE_NAME           = item.APPLIANCE_NAME,
                        VERSION                  = item.VERSION,
                        FACTORY_NUM              = item.FACTORY_NUM,
                        NUM                      = item.NUM,
                        ATTACHMENT               = item.ATTACHMENT,
                        UNDERTAKE_LABORATORYID   = item.UNDERTAKE_LABORATORYID,
                        APPLIANCE_RECIVE         = item.APPLIANCE_RECIVE,
                        REPORTNUMBER             = item.REPORTNUMBER,
                        REMARKS                  = item.REMARKS,
                        ORDER_TASK_INFORMATIONID = item.ORDER_TASK_INFORMATIONID,
                        APPLIANCECOLLECTIONSATE  = item.APPLIANCECOLLECTIONSATE,
                        REPORTTORECEVESTATE      = item.REPORTTORECEVESTATE,
                        PREPARE_SCHEMEID         = item.PREPARE_SCHEMEID,
                        REPORTSTATUS             = item.REPORTSTATUS,
                    };
                    osi.VQIJULINGQU2Show.Add(vq);
                }
            }
            #endregion
            #region 委托单信息数据处理
            ORDER_TASK_INFORMATION oti = m_BLL3.GetById(ORDER_TASK_INFORMATIONID);
            osi.ID                             = oti.ID;
            osi.ORDER_NUMBER                   = oti.ORDER_NUMBER;
            osi.ACCEPT_ORGNIZATION             = oti.ACCEPT_ORGNIZATION;
            osi.INSPECTION_ENTERPRISE          = oti.INSPECTION_ENTERPRISE;
            osi.INSPECTION_ENTERPRISE_ADDRESS  = oti.INSPECTION_ENTERPRISE_ADDRESS;
            osi.INSPECTION_ENTERPRISE_POST     = oti.INSPECTION_ENTERPRISE_POST;
            osi.CONTACTS                       = oti.CONTACTS;
            osi.CONTACT_PHONE                  = oti.CONTACT_PHONE;
            osi.FAX                            = oti.FAX;
            osi.CERTIFICATE_ENTERPRISE         = oti.CERTIFICATE_ENTERPRISE;
            osi.CERTIFICATE_ENTERPRISE_ADDRESS = oti.CERTIFICATE_ENTERPRISE_ADDRESS;
            osi.CERTIFICATE_ENTERPRISE_POST    = oti.CERTIFICATE_ENTERPRISE_POST;
            osi.CONTACTS2                      = oti.CONTACTS2;
            osi.CONTACT_PHONE2                 = oti.CONTACT_PHONE2;
            osi.FAX2                           = oti.FAX2;
            osi.CUSTOMER_SPECIFIC_REQUIREMENTS = oti.CUSTOMER_SPECIFIC_REQUIREMENTS;
            osi.ORDER_STATUS                   = oti.ORDER_STATUS;
            osi.CREATETIME                     = oti.CREATETIME;
            osi.CREATEPERSON                   = oti.CREATEPERSON;
            osi.UPDATETIME                     = oti.UPDATETIME;
            osi.UPDATEPERSON                   = oti.UPDATEPERSON;
            #endregion
            ViewBag.Id       = osi.ID;
            ViewBag.Baogaoid = baogaoid;
            ViewBag.Qijuid   = qijuid;
            return(View(osi));
        }
        public ActionResult Save(ORDER_TASK_INFORMATION entity)
        {
            Common.ClientResult.OrderTaskGong result = new Common.ClientResult.OrderTaskGong();
            try
            {
                string currentPerson = GetCurrentPerson();
                if (string.IsNullOrWhiteSpace(entity.ID))
                {
                    List <COMPANY> companylist  = m_BLL2.GetByParam(null, "asc", "ID", "COMPANYNAME&" + entity.INSPECTION_ENTERPRISE + "");
                    List <COMPANY> companylist2 = m_BLL2.GetByParam(null, "asc", "ID", "COMPANYNAME&" + entity.CERTIFICATE_ENTERPRISE + "");


                    foreach (var item in companylist)
                    {
                        if (item.COMPANY2 != null)
                        {
                            entity.INSPECTION_ENTERPRISEHELLD = item.COMPANY2.COMPANYNAME;
                            break;
                        }
                    }
                    foreach (var item in companylist2)
                    {
                        if (item.COMPANY2 != null)
                        {
                            entity.CERTIFICATE_ENTERPRISEHELLD = item.COMPANY2.COMPANYNAME;
                            break;
                        }
                    }
                    string ORDER_NUMBER = m_BLL.GetORDER_NUMBER(ref validationErrors);
                    var    order        = ORDER_NUMBER.Split('*');// DC2016001 * 1 * 2016
                    entity.ORDER_STATUS = Common.ORDER_STATUS_INFORMATION.保存.ToString();
                    var ms = new System.IO.MemoryStream();
                    entity.CREATETIME   = DateTime.Now;
                    entity.CREATEPERSON = currentPerson;
                    entity.ID           = Result.GetNewId();

                    entity.ORDER_NUMBER   = order[0].ToString();
                    entity.ORSERIALNUMBER = Convert.ToDecimal(order[1]);
                    entity.ORYEARS        = order[2].ToString();

                    entity.ORDER_STATUS = Common.ORDER_STATUS_INFORMATION.保存.ToString();

                    string path = Server.MapPath("~/up/ErWeiMa/");
                    foreach (var item in entity.APPLIANCE_DETAIL_INFORMATION)
                    {
                        item.ID           = Result.GetNewId();
                        item.CREATETIME   = DateTime.Now;
                        item.CREATEPERSON = currentPerson;
                        item.BAR_CODE_NUM = item.ID;
                        //二维码生成
                        ErrorCorrectionLevel Ecl    = ErrorCorrectionLevel.M; //误差校正水平
                        string           Content    = item.ID;                //待编码内容
                        QuietZoneModules QuietZones = QuietZoneModules.Two;   //空白区域
                        int    ModuleSize           = 3;                      //大小
                        var    encoder = new QrEncoder(Ecl);
                        QrCode qr;
                        if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵
                        {
                            Renderer r = new Renderer(ModuleSize);
                            r.QuietZoneModules = QuietZones;
                            r.WriteToStream(qr.Matrix, ms, ImageFormat.Png);
                        }
                        //QRCodeHelper.GetQRCode(item.ID, ms);
                        var pathErWeiMa = path + item.ID + ".png";

                        //System.IO.FileStream fs = new System.IO.FileStream(pathErWeiMa, System.IO.FileMode.OpenOrCreate);


                        //System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
                        #region 二维码加字
                        System.IO.FileStream fss = new System.IO.FileStream(Server.MapPath("~/up/moban.png"), System.IO.FileMode.OpenOrCreate);
                        int filelength           = 0;
                        filelength = (int)fss.Length;        //获得文件长度
                        Byte[] image = new Byte[filelength]; //建立一个字节数组
                        fss.Read(image, 0, filelength);      //按字节流读取
                        System.Drawing.Image imag = System.Drawing.Image.FromStream(fss);
                        //System.Drawing.Image Image = System.Drawing.Image.FromStream(ms);
                        Graphics g = null;
                        g = Graphics.FromImage(imag);
                        string xinghao = item.FACTORY_NUM;//需要写入的字
                        //string xinghao = "123456789abcd";//需要写入的字
                        int w = imag.Width;
                        int h = imag.Height;
                        int y = 0;
                        int x = 380;
                        for (int i = 0; i < xinghao.Length; i++)
                        {
                            if (x > w)
                            {
                                result.Code    = Common.ClientCode.Fail;
                                result.Message = "内容太多二维码生成失败!";
                                return(Json(result));
                            }
                            else
                            {
                                if (i % 6 == 0)
                                {
                                    x = x + 50;
                                    y = 0;
                                    y = y + 45;
                                    g.DrawString(xinghao[i].ToString(), new Font("宋体", 14), Brushes.Red, new PointF(x, y));//x:值越大越靠右;y:值越小越靠上
                                }
                                else
                                {
                                    y = y + 45;
                                    g.DrawString(xinghao[i].ToString(), new Font("宋体", 14), Brushes.Red, new PointF(x, y));//x:值越大越靠右;y:值越小越靠上
                                }
                            }
                        }
                        System.Drawing.Image ig = CombinImage(imag, ms);
                        fss.Close();
                        TuPanBaoCun(ig, pathErWeiMa);
                        //生成pdf
                        //图片
                        //Image image = Image.GetInstance(imagePath);
                        //cell = new PdfPCell(image, true);
                        //table.AddCell(cell);
                        PDF.Create(path + item.ID);
                        #endregion

                        //w.Write(ms.ToArray());
                        //fs.Close();
                        //器具明细信息_承接实验室表添加数据
                        foreach (var it in item.UNDERTAKE_LABORATORYID.TrimEnd(',').Split(','))
                        {
                            item.APPLIANCE_LABORATORY.Add(new APPLIANCE_LABORATORY()
                            {
                                ID = Result.GetNewId(),
                                UNDERTAKE_LABORATORYID   = it,
                                ORDER_STATUS             = Common.ORDER_STATUS.保存.ToString(),
                                EQUIPMENT_STATUS_VALUUMN = Common.ORDER_STATUS.保存.GetHashCode().ToString(),
                                DISTRIBUTIONPERSON       = currentPerson,
                                DISTRIBUTIONTIME         = DateTime.Now,
                                CREATEPERSON             = currentPerson,
                                CREATETIME = DateTime.Now,
                                ISRECEIVE  = Common.ISRECEIVE.是.ToString(),
                                RECYCLING  = entity.RECYCLING
                            });
                        }
                    }
                    ms.Close();

                    string returnValue = string.Empty;
                    if (m_BLL.Create(ref validationErrors, entity))
                    {
                        LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",委托单信息的信息的Id为" + entity.ID, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Succeed;
                        result.Message = Suggestion.InsertSucceed;
                        result.Id      = entity.ID;
                        return(Json(result)); //提示创建成功
                    }
                    else
                    {
                        if (validationErrors != null && validationErrors.Count > 0)
                        {
                            validationErrors.All(a =>
                            {
                                returnValue += a.ErrorMessage;
                                return(true);
                            });
                        }
                        LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",委托单信息的信息," + returnValue, "委托单信息"
                                                       );//写入日志
                        result.Code    = Common.ClientCode.Fail;
                        result.Message = Suggestion.InsertFail + returnValue;
                        return(Json(result)); //提示插入失败
                    }
                }
                else
                {
                }


                result.Code    = Common.ClientCode.FindNull;
                result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对
            }
            catch (Exception lastError)
            {
                ExceptionsHander.WriteExceptions(lastError);//将异常写入数据库
            }
            return(Json(result));
        }