Ejemplo n.º 1
0
        public void UpdateAttachStruct(LibAttachData attachData, List <string> listSql)
        {
            if (string.IsNullOrEmpty(attachData.AttachSrc))
            {
                attachData.AttachSrc = LibCommUtils.GetInternalId().ToString();
                StringBuilder builder = new StringBuilder();
                foreach (var item in attachData.PkList)
                {
                    if (item.Value.GetType() == typeof(string))
                    {
                        builder.AppendFormat("{0} = {1} and ", item.Key, LibStringBuilder.GetQuotObject(item.Value));
                    }
                    else
                    {
                        builder.AppendFormat("{0} = {1} and ", item.Key, item.Value);
                    }
                }
                if (builder.Length > 0)
                {
                    builder.Remove(builder.Length - 4, 4);
                }
                //更新单据附件关联字段
                listSql.Add(string.Format("update {0} set ATTACHMENTSRC='{1}' where {2}", attachData.TableName, attachData.AttachSrc, builder.ToString()));
            }
            foreach (var item in attachData.AttachList)
            {
                switch (item.Status)
                {
                case LibAttachStatus.Add:
                    listSql.Add(string.Format("insert into AXPATTACHMENTRECORD(BELONGTOID,ORDERID,ORDERNUM,ATTACHMENTNAME,CANUSE) values('{0}',{1},{2},'{3}',1)",
                                              attachData.AttachSrc, item.OrderId, item.OrderNum, item.AttachmentName));
                    break;

                case LibAttachStatus.Modif:
                    listSql.Add(string.Format("update AXPATTACHMENTRECORD set ORDERNUM={2},ATTACHMENTNAME='{3}' where BELONGTOID='{0}' and ORDERID={1}",
                                              attachData.AttachSrc, item.OrderId, item.OrderNum, item.AttachmentName));
                    break;

                case LibAttachStatus.Delete:
                    listSql.Add(string.Format("update AXPATTACHMENTRECORD set CANUSE=0 where BELONGTOID='{0}' and ORDERID={1}",
                                              attachData.AttachSrc, item.OrderId));
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public string SaveAttachStruct(LibAttachData attachData)
        {
            if (attachData.AttachList.Count == 0)
            {
                return(string.Empty);
            }
            LibDataAccess dataAccess = new LibDataAccess();
            List <string> listSql    = new List <string>();

            UpdateAttachStruct(attachData, listSql);
            LibDBTransaction trans = dataAccess.BeginTransaction();

            try
            {
                dataAccess.ExecuteNonQuery(listSql);
                trans.Commit();
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            return(attachData.AttachSrc);
        }