/* * Create Customer */ private void button1_Click(object sender, EventArgs e) { //testing adding a static customer - trying out SWK api's if (txtNewCustomer.Text != "") { int newId = ApiAccess.addSWKCustomer(txtNewCustomer.Text, "Joe", "Bigshot", "1 Main St.", "2nd Fl", "New York", "NY", "10010", "USA", "*****@*****.**", "netlibpwd??", "555-1212", "555-1313", "Joey"); if (newId < 0) { MessageBox.Show("Error adding user. Error was: " + newId.ToString()); } else { // Success!! Maybe here add the user to the SQL database? } } }
/* * procAccounts - by range, single or allfrom SQL - fill the passed-in Cust list box with the names of processed accounts and * License lst box with processed licenses */ public static void procAccounts(int searchtype, string clientid1, string clientid2, ListBox lstCustBox, ListBox lstLicBox, bool test, bool custonly) { lstCustBox.Items.Clear(); lstLicBox.Items.Clear(); string AddCustResult = ""; bool SkipError = false; string newCustID = ""; //Set up file names to send results // Set a variable to the Documents path. string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //create file name DateTime d = DateTime.Now; string dateString = d.ToString("yyyyMMddHHmmss"); string custfilename = "customers-" + dateString + ".txt"; string custfullpath = Path.Combine(docPath, custfilename); string licfilename = "licenses-" + dateString + ".txt"; string licfullpath = Path.Combine(docPath, licfilename); // Write header line to a new results files string custfiletext = "AcctName \t ClientID: \t Add Result \t LicResult" + Environment.NewLine; File.WriteAllText(custfullpath, custfiletext); string licfiletext = "AcctName \t clientID \t SerialNum \t LicType \t CustomerID \t AddLicResult \t LicID \t LicPW \t AddLicNotes" + Environment.NewLine; File.WriteAllText(licfullpath, licfiletext); // Open connection to SQL Server string connectionString = ConfigurationManager.ConnectionStrings["NetlibApi1.Properties.Settings.custdb"].ConnectionString; SqlConnection dbConAcct = new SqlConnection(connectionString); // "Server= 192.168.86.33;Database=SWKExchange;User Id=swkdata;Password=MollyLinus;" dbConAcct.Open(); // Command DbCommand dbCmdAcct = dbConAcct.CreateCommand(); // search all if (searchtype == 1) { dbCmdAcct.CommandText = "select * from AcctContact order by AccountID"; } else //search single if (searchtype == 2) { dbCmdAcct.CommandText = "select * from AcctContact"; dbCmdAcct.CommandText += " where ClientID = '" + clientid1 + "'"; dbCmdAcct.CommandText += " order by ClientID"; } else //search Range { dbCmdAcct.CommandText = "select * from AcctContact"; dbCmdAcct.CommandText += " where ClientID BETWEEN '" + clientid1 + "' and '" + clientid2 + "'"; dbCmdAcct.CommandText += " order by ClientID"; } // Get the data DbDataReader rsDataAcct = dbCmdAcct.ExecuteReader(); if (rsDataAcct.HasRows) { while (rsDataAcct.Read()) { string AcctName = rsDataAcct["AccountName"].ToString(); string clientID = rsDataAcct["ClientID"].ToString(); string Acctid = rsDataAcct["AccountID"].ToString(); // Has this customer been added to Soloserver previously string SWCustomerID = rsDataAcct["SWCustomerID"].ToString(); if (SWCustomerID == "") { // add Account to SoloServer string firstName = rsDataAcct["FirstName"].ToString(); string lastName = rsDataAcct["LastName"].ToString(); string address1 = rsDataAcct["AddressLine1"].ToString(); string address2 = rsDataAcct["AddressLine2"].ToString(); string city = rsDataAcct["City"].ToString(); string state = rsDataAcct["StateProvince"].ToString(); string zip = rsDataAcct["PostalCode"].ToString(); string country = rsDataAcct["Country"].ToString(); string email = rsDataAcct["Email"].ToString(); string pwd = rsDataAcct["dnld_userpw"].ToString(); string nickname = "GMClientID: " + rsDataAcct["GMClientID"].ToString(); int newId = ApiAccess.addSWKCustomer(AcctName, firstName, lastName, address1, address2, city, state, zip, country, email, pwd, "", "", nickname); if (newId < 0) { // Error with SWK add AddCustResult = "Add Error: " + newId.ToString(); SkipError = true; } else { // successful SWK add newCustID = newId.ToString(); AddCustResult = "Added: " + newCustID + "pw: " + pwd; // update Account record in SQL with SWK data string updResult = DataAccess.updateCustSWKData(Acctid, newCustID, pwd, email, "Insert"); AddCustResult += " " + updResult; } } else { // has been previously added according to Account Record // confirm customer on SoloServer and then process licenses. newCustID = SWCustomerID; AddCustResult = "Prev Add: " + newCustID; } if (custonly) { SkipError = true; } string licResult = ""; if (SkipError) { // dont process licenses licResult = "Skipped Licenses"; } else { // get licenses for this AcctID int licensesProcessed; licensesProcessed = ImportData.procLicenses(Acctid, newCustID, AcctName, clientID, lstLicBox, licfullpath, test); licResult = "Lic: " + licensesProcessed.ToString(); } //list customers processed in box and results file custfiletext = AcctName + " \t ClientID: " + clientID + " \t Add Result: " + AddCustResult + " \t " + licResult; lstCustBox.Items.Add(custfiletext); File.AppendAllText(custfullpath, custfiletext + Environment.NewLine); } } // Close Connection dbConAcct.Close(); }