rendered paste bodyusing System;
using System.Drawing;
using System.Web.Services;
using System.Collections;
using System.IO;
using System.Configuration;
using System.Xml.Serialization;
using Custom_CRM_DB;
namespace Custom_CRM
{
[WebService(Namespace = "http://www.interlink.ck.ua/Custom_CRM/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service()
{
//Uncomment the following line if using designed components
InitializeComponent();
}
private void InitializeComponent()
{
if (!(ServerDatabase.Inited))
{
ServerDatabase.init(ConfigurationSettings.AppSettings["ConnDBStringReal"]);
}
}
[WebMethod]
public void InitTest()
{
ServerDatabase.init(ConfigurationSettings.AppSettings["ConnDBString"]);
ServerDatabase.ClearAllTables();
}
[WebMethod]
public void ReInit()
{
ServerDatabase.init(ConfigurationSettings.AppSettings["ConnDBStringReal"]);
}
[WebMethod]
[XmlInclude(typeof(Employee))]
public ArrayList GetEmployees()
{
return ServerDatabase.SelectAllEmployees();
}
[WebMethod]
[XmlInclude(typeof(Employee))]
public int SaveEmployee(Employee emp)
{
return ServerDatabase.UpdateEmployee(emp);
}
[WebMethod]
[XmlInclude(typeof(Employee))]
public int DeleteEmployee(String login)
{
return ServerDatabase.DeleteEmployee(login);
}
[WebMethod]
[XmlInclude(typeof(Organization))]
public ArrayList GetRelations()
{
return ServerDatabase.SelectAllRelations();
}
[WebMethod]
[XmlInclude(typeof(Contact))]
public ArrayList GetContacts(String orgName)
{
return ServerDatabase.GetContacts(orgName);
}
[WebMethod]
[XmlInclude(typeof(Organization))]
public bool OrganizationsAreEqual(Organization org, Organization other)
{
return org.EqualsTo(other);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public bool ProductsAreEqual(Product prod, Product other)
{
return prod.EqualsTo(other);
}
[WebMethod]
[XmlInclude(typeof(Contact))]
public int SaveContact(String orgName, Contact cont)
{
return ServerDatabase.UpdateContact(orgName, cont);
}
[WebMethod]
[XmlInclude(typeof(Organization))]
public int SaveRelation(Organization org)
{
return ServerDatabase.UpdateRelation(org);
}
[WebMethod]
public int ChangeRelationName(String oldName, String newName)
{
return ServerDatabase.UpdateOrganizationName(oldName, newName);
}
[WebMethod]
public int DeleteContact(String orgName, String firstName, String lastName)
{
return ServerDatabase.DeleteContact(orgName, firstName, lastName);
}
[WebMethod]
public int DeleteRelation(String orgName)
{
return ServerDatabase.DeleteRelation(orgName);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public long SaveProduct(Product prod)
{
return ServerDatabase.UpdateProduct(prod);
}
[WebMethod]
public int DeleteProduct(String article, String supName)
{
return ServerDatabase.DeleteProduct(article, supName);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public ArrayList GetProducts()
{
return ServerDatabase.GetProductsByParameters("", 0, 0, "", "", 0, 0, "", 0);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public ArrayList GetProductsBySupplier(String supName)
{
return ServerDatabase.GetProductsByParameters(supName, 0, 0, "", "", 0, 0, "", 0);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public ArrayList GetProductsByParameters(String supName, byte material,
int content, String series, String cap, int height, int width, String shape,
int depth)
{
return ServerDatabase.GetProductsByParameters(supName, material,
content, series, cap, height, width, shape, depth);
}
[WebMethod]
[XmlInclude(typeof(Product))]
public ArrayList GetProductsByDebtor(String specName)
{
return ServerDatabase.GetProductsBySpecifiedDebtor(specName);
}
[WebMethod]
[XmlInclude(typeof(Offer))]
public long SaveOffer(Offer off)
{
return ServerDatabase.UpdateOffer(off);
}
[WebMethod]
public int DeleteOffer(long idNum)
{
return ServerDatabase.DeleteOffer(idNum);
}
[WebMethod]
[XmlInclude(typeof(Offer))]
public ArrayList GetOffers()
{
return ServerDatabase.GetOffersByCharger(0, 0, false);
}
[WebMethod]
[XmlInclude(typeof(Offer))]
public ArrayList GetOffersByCharger(int empId, int contId, bool isSupplier)
{
return ServerDatabase.GetOffersByCharger(empId, contId, isSupplier);
}
[WebMethod]
[XmlInclude(typeof(Offer))]
public ArrayList GetOffersByProduct(long prodId)
{
return ServerDatabase.GetOffersByProduct(prodId);
}
[WebMethod]
[XmlInclude(typeof(Contact))]
[XmlInclude(typeof(Offer))]
[XmlInclude(typeof(Organization))]
public ArrayList GetOffersByRelation(String orgName, bool isSupplier)
{
ArrayList offersList = new ArrayList();
ArrayList contList = ServerDatabase.GetContacts(orgName);
foreach (object obj in contList)
{
offersList.AddRange(ServerDatabase.GetOffersByCharger(0,
((Contact)obj).DatabaseID, isSupplier).ToArray());
}
return offersList;
}
[WebMethod]
[XmlInclude(typeof(Order))]
public long SaveOrder(Order ord)
{
return ServerDatabase.UpdateOrder(ord);
}
[WebMethod]
public int DeleteOrder(long idNum)
{
return ServerDatabase.DeleteOrder(idNum);
}
[WebMethod]
[XmlInclude(typeof(Order))]
public ArrayList GetOrders()
{
return ServerDatabase.GetOrdersByCharger(0, 0, 0);
}
[WebMethod]
[XmlInclude(typeof(Order))]
public ArrayList GetOrdersByCharger(int empId, int contId, int category)
{
return ServerDatabase.GetOrdersByCharger(empId, contId, category);
}
[WebMethod]
[XmlInclude(typeof(Order))]
public ArrayList GetOrdersByProduct(long prodId)
{
return ServerDatabase.GetOrdersByProduct(prodId);
}
[WebMethod]
[XmlInclude(typeof(Contact))]
[XmlInclude(typeof(Order))]
[XmlInclude(typeof(Organization))]
public ArrayList GetOrdersByRelation(String orgName, int category)
{
ArrayList ordersList = new ArrayList();
ArrayList contList = ServerDatabase.GetContacts(orgName);
foreach (object obj in contList)
{
ordersList.AddRange(ServerDatabase.GetOrdersByCharger(0,
((Contact)obj).DatabaseID, category).ToArray());
}
return ordersList;
}
[WebMethod]
public int ImportIntoFile(string fileName, string line)
{
int result = 0;
Directory.SetCurrentDirectory("D:\\Temp");
String path = Directory.GetCurrentDirectory() + "\\" +
ConfigurationManager.AppSettings["ImagesDirectory"];
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path += "\\" + fileName;
try
{
using (StreamWriter sw = new StreamWriter(path, true))
{
sw.WriteLine(line);
}
result = 1;
}
catch (Exception)
{
}
return result;
}
[WebMethod]
public ArrayList GetZones()
{
return ServerDatabase.SelectTransportZones();
}
[WebMethod]
public ArrayList GetContents()
{
return ServerDatabase.SelectContents();
}
[WebMethod]
public ArrayList GetBrimFills()
{
return ServerDatabase.SelectBrimFills();
}
[WebMethod]
public ArrayList GetHeights()
{
return ServerDatabase.SelectHeights();
}
[WebMethod]
public ArrayList GetWidths()
{
return ServerDatabase.SelectWidths();
}
[WebMethod]
public ArrayList GetWeights()
{
return ServerDatabase.SelectWeights();
}
[WebMethod]
public ArrayList GetShapes()
{
return ServerDatabase.SelectShapes();
}
[WebMethod]
public ArrayList GetDepths()
{
return ServerDatabase.SelectDepths();
}
[WebMethod]
public ArrayList GetProductSeries()
{
return ServerDatabase.SelectProductSeries();
}
[WebMethod]
public ArrayList GetCaps()
{
return ServerDatabase.SelectCaps();
}
[WebMethod]
public ArrayList GetStockPlaces()
{
return ServerDatabase.SelectStockPlaces();
}
[WebMethod]
public ArrayList GetMaterials()
{
return ServerDatabase.GetMaterialData();
}
[WebMethod]
public void UploadItemPicture(string fileName, byte[] content)
{
Image image = Image.FromStream(new MemoryStream(content));
string targetFileName = Server.MapPath(ConfigurationManager.AppSettings["ImagesPath"] + fileName);
Utils.ResizeWithRatioAndSave(image, targetFileName, 124, false);
}
[WebMethod]
public void DeletePictureFile(string fileName)
{
string targetFileName = Server.MapPath(ConfigurationManager.AppSettings["ImagesPath"] + fileName);
if (File.Exists(targetFileName))
File.Delete(targetFileName);
}
[WebMethod]
public byte[] LoadItemPicture(string fileName)
{
byte[] result = null;
string targetFileName = Server.MapPath(ConfigurationManager.AppSettings["ImagesPath"] + fileName);
if (File.Exists(targetFileName))
{
result = File.ReadAllBytes(targetFileName);
}
return result;
}
}
}