How to write data to existing Sharepoint 2007 Calender List - sharepoint

Domestic demand,We must let our develop system form copy to the WSS 3.0 Calendar list
Simply put, I know need to use ADO to update [Alluserdata] this table and also know whitch
tp_listId.
However, after updating, has written to the database, it can not appear in Sharepoint page
What am I do some thing wrong...
ps: suspected tp_size field related, but not sure ....
Public Sub Pm_woToSharePoint(ByVal PM_WO_MAIN_VIEWRow As PM_WO_MAIN_VIEW)
Try
Dim cdataobj As New cDataACCESS
Dim dt_Prolist As Data.DataTable
Dim selectString As String
selectString = "select top 1 * from AllUserData where tp_listId='4C0516DB-B090-4740-A0F0-B99E6DC31C0C' order by tp_id desc"
dt_Prolist = cdataobj.sqlDt(selectString, "SharepointConnectionString")
Dim CalenderListRow As Data.DataRow = dt_Prolist.NewRow
Dim CalenderListRow2 As Data.DataRow = dt_Prolist.Rows(0)
With CalenderListRow2
CalenderListRow.Item("tp_ID") = .Item("tp_id") + 1
CalenderListRow.Item("tp_ListId") = .Item("tp_ListId")
CalenderListRow.Item("tp_SiteId") = .Item("tp_SiteId")
' CalenderListRow.Item("tp_RowOrdinal") = 0
CalenderListRow.Item("tp_Version") = 1
CalenderListRow.Item("tp_Author") = 96
CalenderListRow.Item("tp_Editor") = 96
CalenderListRow.Item("tp_Modified") = Now
CalenderListRow.Item("tp_Created") = Now
CalenderListRow.Item("tp_Ordering") = DBNull.Value
CalenderListRow.Item("tp_ThreadIndex") = DBNull.Value
' CalenderListRow.Item("tp_HasAttachment") = 0
'CalenderListRow.Item("tp_ModerationStatus") = 0
CalenderListRow.Item("tp_IsCurrent") = 1
CalenderListRow.Item("tp_ItemOrder") = 100 * CalenderListRow.Item("tp_ID")
CalenderListRow.Item("tp_InstanceID") = DBNull.Value
' CalenderListRow.Item("tp_GUID") = 4
' CalenderListRow.Item("tp_CopySource") = DBNull.Value
'CalenderListRow.Item("tp_HasCopyDestinations") = DBNull.Value
CalenderListRow.Item("tp_AuditFlags") = DBNull.Value
CalenderListRow.Item("tp_InheritAuditFlags") = DBNull.Value
CalenderListRow.Item("tp_Size") = .Item("tp_Size")
CalenderListRow.Item("tp_WorkflowVersion") = 1
CalenderListRow.Item("tp_WorkflowInstanceID") = DBNull.Value
CalenderListRow.Item("tp_DirName") = .Item("tp_DirName")
CalenderListRow.Item("tp_LeafName") = CStr(CalenderListRow.Item("tp_ID")) & "_.000"
CalenderListRow.Item("tp_DeleteTransactionId") = .Item("tp_DeleteTransactionId")
CalenderListRow.Item("tp_ContentType") = .Item("tp_ContentType")
CalenderListRow.Item("tp_ContentTypeId") = .Item("tp_ContentTypeId")
CalenderListRow.Item("nvarchar1") = PM_WO_MAIN_VIEWRow.ITEM_NAME & " " & PM_WO_MAIN_VIEWRow.ITEM_VALUE
CalenderListRow.Item("nvarchar3") = PM_WO_MAIN_VIEWRow.ST_NAME_CHT
CalenderListRow.Item("ntext2") = "機台:" & PM_WO_MAIN_VIEWRow.MS_NAME_CHT & " 生產人員:" & PM_WO_MAIN_VIEWRow.ProductPerson
CalenderListRow.Item("datetime1") = DateAdd(DateInterval.Hour, -8, CType(PM_WO_MAIN_VIEWRow.START_TIME, DateTime))
CalenderListRow.Item("datetime2") = DateAdd(DateInterval.Hour, -8, CType(PM_WO_MAIN_VIEWRow.END_TIME, DateTime))
CalenderListRow.Item("int1") = 0
' CalenderListRow.Item("int2") = .Item("int2")
CalenderListRow.Item("bit1") = 0
CalenderListRow.Item("bit2") = 0
CalenderListRow.Item("bit3") = 0
CalenderListRow.Item("tp_Level") = 1
CalenderListRow.Item("tp_IsCurrentVersion") = 1
CalenderListRow.Item("tp_UIVersion") = 512
CalenderListRow.Item("tp_CalculatedVersion") = 0
CalenderListRow.Item("tp_UIVersionString") = "1.0"
CalenderListRow.Item("tp_DraftOwnerId") = DBNull.Value
CalenderListRow.Item("tp_UIVersionString") = DBNull.Value
CalenderListRow.Item("tp_CheckoutUserId") = DBNull.Value
End With
dt_Prolist.Rows.Add(CalenderListRow)
cdataobj.ExecSQL(dt_Prolist, selectString, "SharepointConnectionString")
Catch ex As System.Exception
Throw
End Try
End Sub

You are on totally the wrong track here accessing the database directly, its dangerous and unsupported.
The correct way to do things like this is the object model or web services (or client object model in 2010) - see here and here to get started.
This is for 2010, but its identical steps 2007 - How to add a event to a SharePoint 2010 Calendar
SPListItem newEvent = yourCalendar.Items.Add();
newEvent["Location"] = "This is location";
newEvent["Start Time"] = DateTime.Now;
newEvent["End Time"] = DateTime.Now.AddHours(1);
newEvent["Description"] = "Going for Meting";
newEvent["Title"] = "New Meting";
newEvent["fAllDayEvent"] = false;
newEvent["Category"] = "Meting";
//Create Event in the sharpoint.
newEvent.Update();

Related

Receive error when double click data in Listbox

I am newbies in VBA. Recently I have created a "Search Form". The search data have 21 columns which will display in the "Search List Box". Unfortunately, it only can show until 9 columns and will return an error for the 10 and above data. Your guidance is very much appreciated. Below is my code:
Private Sub dtlist_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CDSv1.dptname.Text = CDSv1.dtlist.Column(1)
CDSv1.dptadd.Text = CDSv1.dtlist.Column(2)
CDSv1.divcom.Text = CDSv1.dtlist.Column(3)
CDSv1.ctcname.Text = CDSv1.dtlist.Column(4)
CDSv1.ctcno.Text = CDSv1.dtlist.Column(5)
CDSv1.nid.Text = CDSv1.dtlist.Column(6)
CDSv1.serno.Text = CDSv1.dtlist.Column(7)
CDSv1.ipinfo.Text = CDSv1.dtlist.Column(8)
CDSv1.snet.Text = CDSv1.dtlist.Column(9)
CDSv1.gateway.Text = CDSv1.dtlist.Column(10) '<---- The error starts here.
CDSv1.vlinfo.Text = CDSv1.dtlist.Column(11)
CDSv1.netcatcom.Text = CDSv1.dtlist.Column(12)
CDSv1.netsubcatcom.Text = CDSv1.dtlist.Column(13)
CDSv1.ispcom.Text = CDSv1.dtlist.Column(14)
CDSv1.snscom.Text = CDSv1.dtlist.Column(15)
CDSv1.cirt.Text = CDSv1.dtlist.Column(16)
CDSv1.bdwh.Text = CDSv1.dtlist.Column(17)
CDSv1.statcom.Text = CDSv1.dtlist.Column(18)
CDSv1.remf.Text = CDSv1.dtlist.Column(20)
End Sub

ADODB Command.Execute Timeout

I am seeing a timeout error when running a query from Excel vba
The query takes <2 seconds from the SQL Server Management Studio, but from vba the timeout happens at 2 minutes with nothing returned
Is there something i am not doing right setting up the Command object? I have noticed that ADODB seems to be slower but never anything like this
The query joins several tables and does some other calculations, but going from 1.5 seconds to >2 minutes must mean something in the vba that I have missed
This is my vba connection string code:
If svrCon Is Nothing Then
Set svrCon = New ADODB.Connection
End If
If Not CheckServerConnectionState Then
conStr = "Provider=SQLOLEDB;Data Source=ussantapps332;" & _
"Initial Catalog=Global_OEE_Data_Capture_Dev;User Id=sqluser;Password=*****;"
' Open the connection
svrCon.ConnectionTimeout = 0
svrCon.Open conStr
End If
This is my vba SELECT code:
Dim cmd As ADODB.Command
Dim par As ADODB.Parameter
Dim rst As ADODB.Recordset
' Create command object
Set cmd = New ADODB.Command
cmd.CommandTimeout = 120
cmd.ActiveConnection = svrCon
cmd.CommandText = sql
' Create parameter object
If IsArrayInitialized(params) Then
For x = 0 To UBound(params)
If IsNull(params(x, 1)) Then
Set par = cmd.CreateParameter(Type:=params(x, 0), Size:=1)
Else
Set par = cmd.CreateParameter(Type:=params(x, 0), Size:=Len(params(x, 1)) + 1)
End If
par.Value = params(x, 1)
cmd.Parameters.Append par
Set par = Nothing
DoEvents
Next
End If
' Open recordset object
On Error GoTo ExecuteError
Debug.Print Format(Now, "hh:mm:ss")
Set rst = cmd.Execute
Debug.Print Format(Now, "hh:mm:ss")
On Error GoTo 0
The sql string and parameters are passed into the function, the connection is opened from another method
The query is:
SELECT U.UnitsID, L.LineName, V.VSName, O.OperatorShift, O.LineLeader, O.CotyOps, O.TempOps, U.WorkOrder, U.ProductCode,
S.ProdDesc, U.TimeLineStart, U.TimeLineEnd, U.UnitsProduced, U.ActLineSpeed, U.TgtLineSpeed, SUM(CASE WHEN C.DTIncludedInOEE = 0 THEN D.DowntimeLength ELSE 0 END),
U.OfflineTaskID, R.Rate, S.LabHrsPerThou, S.PHeads, T.TgtOEE, T.TgtEff, T.TgtProd
FROM dataUnits U
LEFT JOIN dataOperatorNames O ON O.OperatorID = U.OperatorNameID
INNER JOIN setupLines L ON U.LineID = L.LineID
INNER JOIN setupValueStreams V on V.VSID = L.VSID
INNER JOIN setupPUs P ON V.PUID = P.PUID
LEFT JOIN dataDowntimes D ON U.UnitsID = D.UnitsID
LEFT JOIN setupDowntimes sD ON D.DTID = sD.DTID
LEFT JOIN setupDowntimeCats C ON sD.DTCatID = C.DTCatID
LEFT JOIN (SELECT VSID, AVG(RateVal) Rate
FROM dataRates WHERE FYStart >= '2014-07-01' AND FYStart < '2015-07-01'
GROUP BY VSID) R ON R.VSID = L.VSID
LEFT JOIN dataStandards S ON S.ProdCode = U.ProductCode
LEFT JOIN (SELECT LineID, AVG(TgtOEE) TgtOEE, AVG(TgtEff) TgtEff, AVG(TgtProd) TgtProd
FROM dataTargets WHERE TgtMonth >= '2015-03-01' AND TgtMonth < '2015-04-01'
GROUP BY LineID) T ON L.LineID = T.LineID
WHERE (S.SAPVersion = (SELECT MIN(SAPVersion) FROM dataStandards s2 WHERE s2.ProdCode = S.ProdCode)
OR S.SAPVersion IS NULL)
AND P.SiteID = 2 AND U.TimeLineStart >= '2015-03-05 23:00' AND U.TimeLineStart < '2015-03-31 23:00'
GROUP BY U.UnitsID, L.LineName, V.VSName, O.OperatorShift, O.LineLeader, O.CotyOps, O.TempOps, U.WorkOrder, U.ProductCode, S.ProdDesc, U.TimeLineStart,
U.TimeLineEnd, U.UnitsProduced, U.ActLineSpeed, U.TgtLineSpeed, U.OfflineTaskID, R.Rate, S.LabHrsPerThou, S.PHeads, T.TgtOEE, T.TgtEff, T.TgtProd
ORDER BY U.TimeLineStart ASC
The discussion on the chat showed that:
The problem occurs only while connecting to the remote database.
The old SQLOLEDB provider is used.
I suggested to give a chance to a newer provider SQLNCLI which should be more effective while communicating with MSSQL. When a connection string was modified the execution time dropped from 2 minutes to 3 seconds.

Dynamic excel chart doesn't display all of the data

I have this code that allows users to enter chart parameters into some cells and dynamically create a chart. Many series (up to four) are allowed on two vertical (y) axis and one shared horizontal (x) axis. The chart is a mixture of columns and lines normally, and the data ranges are of varying length. I have this code that adds the series like so (I'll try to stick to what I believe is the relevant code)
seriesCount = 1
If hasSeries1 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(2, 6) & " " & axisside1
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType1
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup1
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle1
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor1
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth1
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor1
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine1
ActiveChart.SeriesCollection(seriesCount).XValues = dates1
ActiveChart.SeriesCollection(seriesCount).Values = dataset1
seriesCount = seriesCount + 1
End If
If hasSeries2 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(3, 6) & " " & axisside2
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType2
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup2
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle2
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor2
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth2
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor2
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine2
ActiveChart.SeriesCollection(seriesCount).XValues = dates2
ActiveChart.SeriesCollection(seriesCount).Values = dataset2
seriesCount = seriesCount + 1
End If
If hasSeries3 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(4, 6) & " " & axisside3
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType3
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup3
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle3
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor3
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth3
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor3
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine3
ActiveChart.SeriesCollection(seriesCount).XValues = dates3
ActiveChart.SeriesCollection(seriesCount).Values = dataset3
seriesCount = seriesCount + 1
End If
If hasSeries4 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(5, 6) & " " & axisside4
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType4
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup4
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle4
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor4
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth4
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor4
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine4
ActiveChart.SeriesCollection(seriesCount).XValues = dates4
ActiveChart.SeriesCollection(seriesCount).Values = dataset4
End If
Here is the problem: the chart only displays part of the data it is supposed to. When I right-click on the data series, hit Select Data and choose Edit, the correct series (both x and y) become highlighted, but what is being shown is a truncated subset of what should be there.
Here is a sample of what I'm seeing
Here is some of the data for the light blue column
12/30/2005 307%
1/31/2006 302%
2/28/2006 248%
3/31/2006 262%
4/28/2006 285%
5/31/2006 256%
... ...
... ...
... ...
6/30/2014 147%
Notice how this data should be showing on the chart beginning at 12/30/2005, but it's starting at 11/30/2013 instead (though the values appear to be correct, 307%, 302%, etc.). It is almost as though excel is forcing the 2nd and 3rd data series to be the same length as the first one. The first one is charting correctly.
I think you're not using a XY chart, thus you must have the same labels (Xvalues = dates for you) for every series. That means that you need to create a unique dates-set containing all the dates and assign it (as Xvalues) to the first serie.

OutOfMemory exception in dataGridView

I am using 2 datagridview to see the data in a windows form application.
The first DGV show the products according to the ids passed to them.
On click of VIEW as of my one column in DGV1, it passes the product id to and fetch the complete records from database and show the records to the other DGV2.
this is my code:
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == (Object)"View")
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
int prod_id = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
dataGridView2.DataSource = null;
dataGridView2.Rows.Clear();
retFindProducts = new MySqlCommand("SELECT DISTINCT tf_history.thefind_id, tf_product.product_id, tf_product.`name`, tf_product.product_url, tf_product.image_tpm, tf_product.image_thefind, tf_product.image_accuracy, (SELECT MIN(tf_h.price) FROM tf_history AS tf_h WHERE tf_h.thefind_id = tf_history.thefind_id) as price, oc_product.price AS priceTPM FROM tf_product LEFT JOIN tf_history ON tf_product.product_id = tf_history.product_id AND tf_product.thefind_id = tf_history.thefind_id LEFT JOIN oc_product ON tf_product.product_id = oc_product.product_id WHERE tf_product.product_id = #product_id", con);
historyData = new MySqlCommand("SELECT price, date from tf_history WHERE thefind_id = #thefind_id", con);
retFindProducts.CommandTimeout = 300;
historyData.CommandTimeout = 300;
retFindProducts.Parameters.AddWithValue("#product_id", prod_id);
dr = retFindProducts.ExecuteReader();
retFindProducts.Parameters.Clear();
while (dr.Read())
{
dataGridView2.Rows.Add();
long fI = Convert.ToInt64(dr["thefind_id"]);
//if (!findId.Exists(p => p.Item1 == fI))
findId.Add(new Tuple<long>(fI));
decimal findPrice = Convert.ToDecimal(dr["price"]);
decimal tpmPrice = Convert.ToDecimal(dr["priceTPM"]);
if (findPrice > tpmPrice)
{
dataGridView2.Rows[cnt].Cells[4].Style.ForeColor = Color.Green;
dataGridView2.Rows[cnt].Cells[4].Style.Font = new Font(dataGridView2.DefaultCellStyle.Font.FontFamily, 9, FontStyle.Regular);
}
else if (findPrice < tpmPrice)
{
dataGridView2.Rows[cnt].Cells[4].Style.ForeColor = Color.Red;
dataGridView2.Rows[cnt].Cells[4].Style.Font = new Font(dataGridView2.DefaultCellStyle.Font.FontFamily, 10, FontStyle.Bold);
}
dataGridView2.Rows[cnt].Cells[0].Value = Image.FromFile(dr["image_tpm"].ToString());
dataGridView2.Rows[cnt].Cells[1].Value = Image.FromFile(dr["image_thefind"].ToString());
dataGridView2.Rows[cnt].Cells[2].Value = dr["name"].ToString();
dataGridView2.Rows[cnt].Cells[3].Value = dr["product_url"].ToString();
dataGridView2.Rows[cnt].Cells[4].Value = dr["price"].ToString();
dataGridView2.Rows[cnt].Cells[5].Value = dr["image_accuracy"].ToString();
cnt++;
}
foreach (DataGridViewRow row in dataGridView2.Rows)
{
row.Height = 60;
}
dr.Close();
}
Now, the outofexception does not comes on first time of the click, but it comes after 5-8 clicks on the VIEW column of DGV1.
How can i clear up the memory?
Try to dispose and create datagridview manually. The Code can be like this:
dgv.Dispose();
dgv = new DataGridView();
DataGridViewColumn col1 = new DataGridViewTextBoxColumn();
DataGridViewColumn col2 = new DataGridViewTextBoxColumn();
DataGridViewColumn col3 = new DataGridViewTextBoxColumn();
DataGridViewColumn col4 = new DataGridViewTextBoxColumn();
DataGridViewColumn col5 = new DataGridViewTextBoxColumn();
col1.HeaderText = "COl1";
col2.HeaderText = "COl2";
col3.HeaderText = "COl3";
col4.HeaderText = "COl4";
col5.HeaderText = "COl5";
dgv = new System.Windows.Forms.DataGridView();
dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dgv.Location = new System.Drawing.Point(59, 101);
dgv.Name = "dataGridView1";
dgv.Size = new System.Drawing.Size(240, 150);
dgv.TabIndex = 2;
dgv.Columns.Add(col1);
dgv.Columns.Add(col2);
dgv.Columns.Add(col3);
dgv.Columns.Add(col4);
dgv.Columns.Add(col5);
this.Controls.Add(dgv);
dgv.ColumnCount = 5;
dgv.Visible = true;

eConnect 10.0 SLPRSNID & SALSTERR not importing in new line items

The following code helps to import a sales line to an invoice:
Dim LineItems(dtItem.Rows.Count) As taSopLineIvcInsert_ItemsTaSopLineIvcInsert
Dim salesLine As New taSopLineIvcInsert_ItemsTaSopLineIvcInsert
'Create Invoice Sales lines
For Each dr In dtItem.Rows
With salesLine
.CUSTNMBR = dr.Item("acctno")
.SOPNUMBE = invoiceNumber
.SOPTYPE = 3
.DOCID = "STD INV"
.QUANTITY = dr.Item("Qty")
.ITEMNMBR = dr.Item("Item")
.ITEMDESC = dr.Item("Memo")
.UNITPRCE = dr.Item("SalesPrice")
.XTNDPRCE = dr.Item("Credit")
.TAXAMNT = 0
.UOFM = "Each"
.SALSTERR = "GENERAL"
.ReqShipDate = dtHdr.Rows(0).Item("InvoiceDate").ToString()
.FUFILDAT = dr.Item("Date1").ToString()
.ACTLSHIP = dr.Item("Date1").ToString()
'.NONINVEN = 0
.DOCDATE = dtHdr.Rows(0).Item("InvoiceDate").ToString()
.SLPRSNID = "C1"
End With
LineItems(rowCtr) = salesLine
rowCtr = rowCtr + 1
Next
The fields for SLPRSNID & SALSTERR are just ignored. The invoice itself is being created with all the line items. ANY ideas from anyone with experience using this API are appreciated!
Since we are not integrating SOP commissions data, importing SLPRSNID & SALSTERR on line items using code like above is not supported. However, eConnect does expose pre and post stored procedures to customize business logic. The following was added in taSopHdrIvcInsertPost to implement the import:
/** Custom Business Logic */
if ((#I_vSLPRSNID <> '') and (#I_vSALSTERR <> ''))
begin
update SOP10200
set SLPRSNID = #I_vSLPRSNID, SALSTERR = #I_vSALSTERR
where SOPNUMBE = #I_vSOPNUMBE and SOPTYPE = #I_vSOPTYPE
end
/** Custom Business Logic */
NOTE: with this implementation, the specific SLPRSNID & SALSTERR will have to be provided to the line items, it will not automatically post from header data, or any customer setup data in GP - your integration has to pass the values in.

Resources