Esempio n. 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
        }