public IHttpActionResult Create(Entrusted entrust)
        {
            JsonObject json = new JsonObject();

            try
            {
                string msg = CheckDraftRequestion(entrust);
                if (!string.IsNullOrEmpty(msg))
                {
                    json["Error"] = msg;
                    return(Ok(json));
                }

                string lab       = entrust.Spec.Substring(1, 1);
                string voucherId = draftDAL.GetDocID(lab);

                string draftID = entrust.DraftID == null ? "" : entrust.DraftID.ToString();
                if (!string.IsNullOrEmpty(draftID))
                {
                    string v = voucherId.Substring(6, 2);
                    string s = draftID.Substring(5, 2);
                    if (v != s)
                    {
                        json["Error"] = string.Format("ERROR┆{0}", "跨月请点结束本次委托,再建单!");
                        return(Ok(json));
                    }
                }
                if (string.IsNullOrEmpty(voucherId))
                {
                    json["Error"] = string.Format("ERROR┆{0}", "得到单号为空!");
                    return(Ok(json));
                }
                string[] strs = new string[entrust.Properties.Length];
                for (int i = 0; i < entrust.Properties.Length; i++)
                {
                    strs[i] = (entrust.Properties[i].PropertyName);
                }

                if (draftDAL.InsertRequesition(entrust.UserID, ref draftID, voucherId,
                                               entrust.SampleName, entrust.LOT_NO, entrust.Purpose,
                                               entrust.SampleFrom, Convert.ToDateTime(entrust.RequireDate), Convert.ToDateTime(entrust.SendDate),
                                               Convert.ToDateTime(entrust.GetDate), strs))
                {
                    json["VoucherId"] = voucherId;
                    json["DraftID"]   = draftID;
                }
                else
                {
                    json["Error"] = "Save ReqInDraft  failed";
                }
                return(Ok(json));
            }
            catch (Exception e)
            {
                MSG_Error     = e;
                json["Error"] = e.Message + "-" + e.StackTrace;
                return(Ok(json));
                // throw new Exception(e.Message);
            }
        }
        private string CheckDraftRequestion(Entrusted entrust)
        {
            if (string.IsNullOrEmpty(entrust.SampleName.Trim()))
            {
                return(string.Format("ERROR┆{0}", "SampleName is NULL!"));
            }
            if (string.IsNullOrEmpty(entrust.LOT_NO))
            {
                return(string.Format("ERROR┆{0}", "Material is NULl!"));
            }
            if (string.IsNullOrEmpty(entrust.SampleFrom))
            {
                return(string.Format("ERROR┆{0}", "From is null!"));
            }
            if (string.IsNullOrEmpty(entrust.Purpose))
            {
                return(string.Format("ERROR┆{0}", "Purpose is null!"));
            }



            if (entrust.Properties.Length < 1)
            {
                return(string.Format("ERROR┆{0}", "Test project is null"));
            }
            return(string.Empty);
        }
Esempio n. 3
0
        public IHttpActionResult CreateVoucher(object note)
        {
            try
            {
                string    js         = Newtonsoft.Json.JsonConvert.SerializeObject(note);
                Entrusted _Entrusted = Newtonsoft.Json.JsonConvert.DeserializeObject <Entrusted>(js);
                _Entrusted.VoucherID = GetDocID(_Entrusted.Spec.Substring(1, 1));

                if (InsertRequesition(_Entrusted))
                {
                    DataTable dt = GetDraft(_Entrusted.DraftID);
                    return(Ok(_helper.ConvertJson(dt)));
                }
            }
            catch (Exception e)
            {
                MSG_Error = e;
                throw new Exception(e.Message);
            }
            return(Ok());
        }
Esempio n. 4
0
        public bool InsertRequesition(Entrusted _Entrusted)
        {
            bool NeedDraft = false;

            //  if (_Entrusted.DraftID.Trim().Length < 11)
            if (_Entrusted.DraftID == null || _Entrusted.DraftID == "")
            {
                int count = draftCount(_Entrusted.VoucherID.Trim());
                if (count < 0)
                {
                    return(false);
                }
                else
                {
                    // draftID = voucherID.Substring(1, 8) + count.ToString().PadLeft(3, '0');
                    _Entrusted.DraftID = _Entrusted.VoucherID.Substring(1, 8) + count.ToString().PadLeft(4, '0');
                    //  = Draft;
                }
                NeedDraft = true;
            }
            //
            bool   result      = false;
            string createDraft = @"INSERT INTO Draft VALUES(@DraftID,@Owner,GETDATE())";
            //
            string createDraftCommand = @"INSERT INTO ReqInDraft VALUES(@DraftID,@VoucherID,@Stamp)";
            //
            string createRequCommand = @"INSERT INTO Requisition
                                        (VoucherID,SampleName,LOT_NO,Purpose,SampleFrom,RequireDate,SendDate,GetDate,State,Remark)
                                        VALUES(@VoucherID,@SampleName,@LOT_NO,@Purpose,@SampleFrom,@RequireDate,@SendDate,@GetDate,@State,@Remark)";

            System.Data.Common.DbTransaction tran = gate.BeginTransaction();
            //

            try
            {
                if (NeedDraft)
                {
                    gate.ExecuteNonQuery(createDraft, new object[] { _Entrusted.DraftID, _Entrusted.UserID });
                }

                gate.ExecuteNonQuery(createRequCommand,
                                     new object[] { _Entrusted.VoucherID, _Entrusted.SampleName, _Entrusted.Material, _Entrusted.purpose, _Entrusted.sampleFrom,
                                                    _Entrusted.needDate, _Entrusted.sendDate, _Entrusted.pickTime, "D", "D" });
                gate.ExecuteNonQuery(createDraftCommand,
                                     new object[] { _Entrusted.DraftID, _Entrusted.VoucherID, System.DateTime.Now });

                //
                int i = 1;
                foreach (string propertyName in _Entrusted.Properties)
                {
                    string sqlProfile = @"INSERT INTO 
                                        Profile(VoucherID,Item,SampleName,PropertyName,Result,State,OverRange)
                                        VALUES(@VoucherID,@Item,@SampleName,@PropertyName,@Result,@State,@OverRange)";
                    gate.ExecuteNonQuery(sqlProfile,
                                         new object[] { _Entrusted.VoucherID, i, _Entrusted.SampleName, propertyName, DBNull.Value, "N", "0" });
                    i++;
                }
                tran.Commit();
                result = true;
            }
            catch (Exception e)
            {
                tran.Rollback();

                throw e;
            }
            return(result);
        }