예제 #1
0
        public string CreateData(string strUID, string strDate, DataTable dtData)
        {
            Int32 PID = 0;
            string[] sID_NO;
            string vID_NO;
            string sTemp = "";
            string sPurchaseNo = "";
            string strResult = string.Empty;
            try
            {
                ArrayList ParameterList = new ArrayList();
                //獨立呼叫啟動Transcation
                Conn = USEDB.CreateConnection();
                Conn.Open();
                DBT = Conn.BeginTransaction();

                MaintainPurchaseOrder PUR02_BCO = new MaintainPurchaseOrder(strConn);

                DataTable dtMANUFACTURE = dtData.DefaultView.ToTable(true, new string[] { "MANUFACTURE" });

                for (int i = 0; i < dtMANUFACTURE.Rows.Count; i++)
                {
                    ParameterList.Clear();
                    ParameterList.Add(strDate);  //0.採購單日期
                    ParameterList.Add(strUID);   //1.採購人員
                    ParameterList.Add(dtMANUFACTURE.Rows[i]["MANUFACTURE"].ToString());  //2.廠商編號
                    ParameterList.Add("25");    //3.CloseCase
                    ParameterList.Add(strUID);  //4.UID 

                    //寫入 Master Table
                    vID_NO = PUR02_BCO.CreatePurchaseOrder(ParameterList, DBT);
                    sID_NO = vID_NO.Split(new Char[] { ';' });
                    PID = int.Parse(sID_NO[0].ToString());
                    sPurchaseNo = sID_NO[1].ToString();
                    strResult += sPurchaseNo + ";";

                    ParameterList.Add(sPurchaseNo);
                    ParameterList.Add(PID);

                    DataTable DetailData = FilterDetail(dtData, dtMANUFACTURE.Rows[i]["MANUFACTURE"].ToString());

                    #region 新增明細資料與更新 VDS_MKT_PURCARD_MAIN.PUR_NO(雜誌採購卡) 或 VDS_MKT_BPURCARD_MAIN.PUR_NO(圖書採購卡)
                    foreach (DataRow dRow in DetailData.Rows)
                    {
                        PUR02_BCO.CreatePurchaseOrderDetail(PID, ParameterList, dRow, DBT);

                        //更新期別屬性檔(VDS_ITM_PERIOD_PROFILE)中,該品號期別的交貨日期、採購日、採購量與採購單號
                        PUR02_BCO.UpdatePeriodProfile(dRow["ITEM"].ToString().Trim(),
                                                      dRow["PERIOD"].ToString().Trim(),
                                                      dRow["PLAN_ACCEPT_DATE"].ToString().Trim(),
                                                      ParameterList[0].ToString().Trim(),
                                                      dRow["PURCHASE_QTY"].ToString().Trim(),
                                                      sPurchaseNo,
                                                      ParameterList[4].ToString().Trim(),
                                                      DBT);

                        //更新圖書採購卡或雜誌採購卡採購單號
                        if (dRow["PERIOD"].ToString().Trim() == "000000") //在圖書裡其period值絕對是000000
                        {
                            PUR02_BCO.Update_B_PURCARD(sPurchaseNo,
                                                       dRow["ITEM"].ToString().Trim(),
                                                       ParameterList[4].ToString().Trim(),
                                                       DBT);
                        }
                        else
                        {
                            PUR02_BCO.Update_PURCARD(sPurchaseNo,
                                                     dRow["ITEM"].ToString().Trim(),
                                                     dRow["PERIOD"].ToString().Trim(),
                                                     ParameterList[4].ToString().Trim(),
                                                     DBT);
                        }
                    }
                    #endregion

                    DataTable GiftData = Add_Gift(DetailData);
                    #region 新增明細贈品資料
                    if (GiftData != null)
                    {
                        foreach (DataRow gRow in GiftData.Rows)
                        {
                            PUR02_BCO.CreatePurchaseOrderDetail(PID, ParameterList, gRow, DBT);

                            //更新贈品屬性檔(VDS_MKT_GIFT_PROFILE)資料中,該品號期別的交貨日期、採購日、採購量與採購單號
                            PUR02_BCO.UpdateGiftProfile(gRow["ITEM"].ToString().Trim(),
                                                        gRow["PERIOD"].ToString().Trim(),
                                                        gRow["VIRTUAL_CODE"].ToString().Trim(),
                                                        gRow["PLAN_ACCEPT_DATE"].ToString().Trim(),
                                                        ParameterList[0].ToString().Trim(),
                                                        gRow["PURCHASE_QTY"].ToString().Trim(),
                                                        sPurchaseNo,
                                                        ParameterList[4].ToString().Trim(),
                                                        DBT);
                        }
                    }
                    #endregion
                }
                DBT.Commit();
            }
            catch (Exception ex)
            {
                if (DBT != null)
                    DBT.Rollback();
                throw ex;
            }
            finally
            {
                //獨立呼叫Transcation,關閉連線
                if (Conn.State == ConnectionState.Connecting)
                    Conn.Close();
            }
            return strResult;
        }