public static void AddEmployee(String TagID, String EmpNo, String UserName, String Password, Int32 RoleID) { if (!Login.OnLineMode) { Int32 Skey; Skey = minServerKey(); // added by vijay 08 Dec 2009 if (Skey == -2) { Skey = Skey - 1; } bool tagAssigned = false; using (CEConn localDB = new CEConn()) { string strSql; TagInfo Ti = new TagInfo(TagID); if (Ti.isAssetTag() || Ti.isLocationTag() || Ti.isEmployeeTag()) { tagAssigned = true; } else { tagAssigned = false; } //strSql = " select count(*) from Assets A,Employees E,Locations L where A.TagID='" + TagID + "' or E.TagID='" + TagID + "' or L.TagID='" + TagID + "'"; ////select count(*) from Locations where TagID='" + TagID + "'"; if (tagAssigned == true && !string.IsNullOrEmpty(TagID)) { throw new ApplicationException("Duplicate Tag ID."); } strSql = " insert into Employees(TagID,UserName,EmpNo,Password,Date_Modified,ID_SecurityGroup,ModifiedBy,RowStatus,serverKey)"; strSql += " values('" + TagID + "','" + UserName.Replace("'", "''") + "','" + EmpNo.Replace("'", "''") + "','" + Password.Replace("'", "''") + "',getDate()," + RoleID + "," + Login.ID + "," + Convert.ToInt32(RowStatus.New) + "," + Skey + ")"; localDB.runQuery(strSql); } } else { DataTable dtEmployee = new DataTable("dtEmployee"); dtEmployee.Columns.Add("EmpNo", typeof(String)); dtEmployee.Columns.Add("UserName", typeof(String)); dtEmployee.Columns.Add("Password", typeof(String)); dtEmployee.Columns.Add("TagID", typeof(String)); dtEmployee.Columns.Add("ID_SecurityGroup", typeof(Int32)); dtEmployee.Columns.Add("ModifiedBy", typeof(Int32)); dtEmployee.AcceptChanges(); DataRow dr; dr = dtEmployee.NewRow(); dr["EmpNo"] = EmpNo; dr["UserName"] = UserName; dr["Password"] = Password; dr["TagID"] = TagID; dr["ID_SecurityGroup"] = RoleID; dr["ModifiedBy"] = Login.ID; dtEmployee.Rows.Add(dr); dtEmployee.AcceptChanges(); Synchronize.Synchronise OnConn = new Synchronize.Synchronise(); OnConn.Url = Login.webURL; DataTable dtResult; dtResult = OnConn.AddEmployee(dtEmployee); if (dtResult.Rows.Count != 0) { if (Convert.ToInt32(dtResult.Rows[0]["RowStatus"]) == Convert.ToInt32(RowStatus.Error)) { throw new ApplicationException("Insert Failed."); } else { //Inserted Sucessfully } } //throw new ApplicationException("Online functionality not implemented yet."); } }
public static void AddLocation(String TagID, String LocationNo, String LocationName) { if (!Login.OnLineMode) { Int32 Skey; Skey = minServerKey(); // added by vijay 08 Dec 2009 if (Skey == -2) { Skey = Skey - 1; } bool tagAssigned = false; using (CEConn localDB = new CEConn()) { string strSql; if (TagID.Length > 0) // to allow blank tagid for locations 05-11-2011 { TagInfo Ti = new TagInfo(TagID); if (Ti.isAssetTag() || Ti.isLocationTag() || Ti.isEmployeeTag()) { tagAssigned = true; } else { tagAssigned = false; } //strSql = " select count(*) from Assets A,Employees E,Locations L where A.TagID='" + TagID + "' or E.TagID='" + TagID + "' or L.TagID='" + TagID + "'"; ////select count(*) from Locations where TagID='" + TagID + "'"; if (tagAssigned == true) { throw new ApplicationException("Duplicate Tag ID."); } } //strSql = " select count(*) from Assets A,Employees E,Locations L where A.TagID='" + TagID + "' or E.TagID='" + TagID + "' or L.TagID='" + TagID + "'"; ////select count(*) from Locations where TagID='" + TagID + "'"; //if (Convert.ToInt32(localDB.getScalerValue(strSql)) > 0) // throw new ApplicationException("Duplicate Tag ID."); strSql = " insert into Locations(TagID,Name,LocationNo,Date_Modified,ModifiedBy,RowStatus,serverKey)"; strSql += " values('" + TagID + "','" + LocationName.Replace("'", "''") + "','" + LocationNo.Replace("'", "''") + "',getDate()," + Login.ID + "," + Convert.ToInt32(RowStatus.New) + "," + Skey + ")"; localDB.runQuery(strSql); } } else { DataTable dtLocation = new DataTable("dtLocation"); dtLocation.Columns.Add("TagID", typeof(String)); dtLocation.Columns.Add("Name", typeof(String)); dtLocation.Columns.Add("LocationNo", typeof(String)); dtLocation.Columns.Add("Date_Modified", typeof(DateTime)); dtLocation.Columns.Add("ModifiedBy", typeof(Int32)); dtLocation.AcceptChanges(); DataRow dr; dr = dtLocation.NewRow(); dr["TagID"] = TagID; dr["Name"] = LocationName; dr["LocationNo"] = LocationNo; dr["Date_Modified"] = DateTime.Now; dr["ModifiedBy"] = Login.ID; dtLocation.Rows.Add(dr); dtLocation.AcceptChanges(); Synchronize.Synchronise OnConn = new Synchronize.Synchronise(); OnConn.Url = Login.webURL; DataTable dtResult; dtResult = OnConn.AddLocation(dtLocation); if (dtResult.Rows.Count != 0) { if (Convert.ToInt32(dtResult.Rows[0]["RowStatus"]) == Convert.ToInt32(RowStatus.Error)) { throw new ApplicationException("Insert Failed."); } else { //Inserted Sucessfully } } //throw new ApplicationException("Online functionality of Location not implemented yet."); } }