Beispiel #1
0
        public void Delete(string recid)
        {
            var callContext = new CallContext()
            {
                MessageId   = Guid.NewGuid().ToString(),
                LogonAsUser = string.Format(@"{0}\{1}", UserAccount.Domain, UserAccount.Username),
                Language    = "en-us"
            };

            using (SalesDailyServiceClient client = new SalesDailyServiceClient())
            {
                client.ClientCredentials.Windows.ClientCredential.Domain   = UserAccount.Domain;
                client.ClientCredentials.Windows.ClientCredential.UserName = UserAccount.Username;
                client.ClientCredentials.Windows.ClientCredential.Password = UserAccount.Password;
                client.delete(callContext, Critera.read(recid));
            }

            #region Delete lines

            DataTable dt = QueryData.Find(
                "STMSalesSODailyLine",
                "StmSalesSoDailyLine",
                "SalesOrderDaily",
                recid
                ).Tables["StmSalesSoDailyLine"];

            var callContextline = new AxRetailSOLine.CallContext()
            {
                MessageId   = Guid.NewGuid().ToString(),
                LogonAsUser = string.Format(@"{0}\{1}", UserAccount.Domain, UserAccount.Username),
                Language    = "en-us"
            };

            foreach (DataRow row in dt.Rows)
            {
                AxRetailSOLine.KeyField keyField = new AxRetailSOLine.KeyField()
                {
                    Field = "RecId", Value = row["RecId"].ToString()
                };
                AxRetailSOLine.EntityKey entityKey = new AxRetailSOLine.EntityKey();

                entityKey.KeyData = new AxRetailSOLine.KeyField[1] {
                    keyField
                };

                AxRetailSOLine.EntityKey[] entityKeys = new AxRetailSOLine.EntityKey[1] {
                    entityKey
                };

                using (AxRetailSOLine.STMSODailyLineServiceClient client = new AxRetailSOLine.STMSODailyLineServiceClient())
                {
                    client.ClientCredentials.Windows.ClientCredential.Domain   = UserAccount.Domain;
                    client.ClientCredentials.Windows.ClientCredential.UserName = UserAccount.Username;
                    client.ClientCredentials.Windows.ClientCredential.Password = UserAccount.Password;
                    client.delete(callContextline, entityKeys);
                }
            }

            #endregion

            #region Delete Image

            DataTable dtImage = QueryData.Find(
                "STMSalesImage",
                "StmSalesImage",
                "RefRecId",
                recid
                ).Tables[0];

            var callContextimage = new AxRetailSOImages.CallContext()
            {
                MessageId   = Guid.NewGuid().ToString(),
                LogonAsUser = string.Format(@"{0}\{1}", UserAccount.Domain, UserAccount.Username),
                Language    = "en-us"
            };

            foreach (DataRow row in dtImage.Rows)
            {
                AxRetailSOImages.KeyField keyFieldimage = new AxRetailSOImages.KeyField()
                {
                    Field = "RecId", Value = row["RecId"].ToString()
                };
                AxRetailSOImages.EntityKey entityKeyimage = new AxRetailSOImages.EntityKey();

                entityKeyimage.KeyData = new AxRetailSOImages.KeyField[1] {
                    keyFieldimage
                };

                AxRetailSOImages.EntityKey[] entityKeysimage = new AxRetailSOImages.EntityKey[1] {
                    entityKeyimage
                };

                using (AxRetailSOImages.STM_SalesImageServiceClient client = new AxRetailSOImages.STM_SalesImageServiceClient())
                {
                    client.ClientCredentials.Windows.ClientCredential.Domain   = UserAccount.Domain;
                    client.ClientCredentials.Windows.ClientCredential.UserName = UserAccount.Username;
                    client.ClientCredentials.Windows.ClientCredential.Password = UserAccount.Password;
                    client.delete(callContextimage, entityKeysimage);
                }

                #region Delete file image in server
                string path = string.Format(@"{0}{1}", row["Image"].ToString(), row["Name"].ToString());
                File.Delete(path);
                #endregion
            }

            #endregion
        }
Beispiel #2
0
        public void Put(RetailSO parmSo)
        {
            /// response JSON
            ///
            /// {
            ///    "RecId": "5637147579",
            ///    "Pool": "WARDROBE"
            /// }

            EntityKey[]   entitykey  = new EntityKey[1];
            AxdSalesDaily axdSoDaily = new AxdSalesDaily();

            try
            {
                var callContext = new CallContext()
                {
                    MessageId   = Guid.NewGuid().ToString(),
                    LogonAsUser = string.Format(@"{0}\{1}", UserAccount.Domain, UserAccount.Username),
                    Language    = "en-us"
                };

                using (var client = new SalesDailyServiceClient())
                {
                    client.ClientCredentials.Windows.ClientCredential.Domain   = UserAccount.Domain;
                    client.ClientCredentials.Windows.ClientCredential.UserName = UserAccount.Username;
                    client.ClientCredentials.Windows.ClientCredential.Password = UserAccount.Password;
                    axdSoDaily = client.read(callContext, Critera.read(parmSo.RecId));
                }

                string duedate     = parmSo.DueDate.ToShortDateString();
                string confirmdate = parmSo.ConfirmDate.ToShortDateString();
                string orderDate   = parmSo.Date.ToShortDateString();

                using (var client = new SalesDailyServiceClient())
                {
                    AxdEntity_StmSalesSoDaily soDailyEntity = axdSoDaily.StmSalesSoDaily[0];
                    var axdSODaily2 = new AxdSalesDaily()
                    {
                        ClearNilFieldsOnUpdate          = axdSoDaily.ClearNilFieldsOnUpdate,
                        ClearNilFieldsOnUpdateSpecified = true,
                        DocPurpose          = axdSoDaily.DocPurpose,
                        DocPurposeSpecified = true,
                        SenderId            = axdSoDaily.SenderId
                    };


                    var soDailyEntityNew = new AxdEntity_StmSalesSoDaily();
                    soDailyEntityNew._DocumentHash  = soDailyEntity._DocumentHash; ///for update method
                    soDailyEntityNew.RecId          = Convert.ToInt64(parmSo.RecId);
                    soDailyEntityNew.RecIdSpecified = true;
                    if (duedate != "01/01/1900" && duedate != "01/01/0544")//(soDaily.DueDate != DateTime.MinValue)
                    {
                        soDailyEntityNew.DueDate          = DateTime.ParseExact(duedate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        soDailyEntityNew.DueDateSpecified = true;
                    }

                    if (parmSo.ConfirmDate != DateTime.MinValue)
                    {
                        soDailyEntityNew.ConfirmDate          = DateTime.ParseExact(confirmdate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        soDailyEntityNew.ConfirmDateSpecified = true;
                    }

                    if (orderDate != "01/01/1900" && orderDate != "01/01/0544") //(soDaily.Date != DateTime.MinValue)
                    {
                        soDailyEntityNew.SalesDate = DateTime.ParseExact(orderDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        soDailyEntityNew.SalesDate = soDailyEntity.SalesDate;
                    }

                    soDailyEntityNew.SalesDateSpecified   = true;
                    soDailyEntityNew.SalesPoolId          = parmSo.Pool;// string.IsNullOrEmpty(soDaily.Pool) ? soDailyEntity.SalesPoolId : soDaily.Pool;
                    soDailyEntityNew.PurchId              = parmSo.PurchId;
                    soDailyEntityNew.SalesId              = parmSo.SalesId;
                    soDailyEntityNew.SalesName            = parmSo.CustName;
                    soDailyEntityNew.SalesQty             = Convert.ToDecimal(parmSo.Qty);    // string.IsNullOrEmpty(soDaily.Qty.ToString()) ? Convert.ToDecimal(soDailyEntity.SalesQty) : Convert.ToDecimal(soDaily.Qty);
                    soDailyEntityNew.SalesQtySpecified    = true;
                    soDailyEntityNew.StmStoreId           = parmSo.StoreId;                   //string.IsNullOrEmpty(soDaily.StoreId) ? soDailyEntity.StmStoreId : soDaily.StoreId;
                    soDailyEntityNew.SalesAmount          = Convert.ToDecimal(parmSo.Amount); // Convert.ToDecimal(soDaily.Amount) == soDailyEntity.SalesAmount ? Convert.ToDecimal(soDailyEntity.SalesAmount) : Convert.ToDecimal(soDaily.Amount);
                    soDailyEntityNew.SalesAmountSpecified = true;

                    axdSODaily2.StmSalesSoDaily = new AxdEntity_StmSalesSoDaily[1] {
                        soDailyEntityNew
                    };

                    client.ClientCredentials.Windows.ClientCredential.Domain   = UserAccount.Domain;
                    client.ClientCredentials.Windows.ClientCredential.UserName = UserAccount.Username;
                    client.ClientCredentials.Windows.ClientCredential.Password = UserAccount.Password;
                    client.update(callContext, Critera.read(parmSo.RecId), axdSODaily2);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }