Esempio n. 1
0
        public void SaveDataByProcToCache(string Key, object DataToSave)
        {
            string FullPathTemp = CFile.GetTempFileName();

            if (this.mUseAdo)
            {
                Recordset RsToSave = DataToSave as Recordset;
                RsToSave.Save(FullPathTemp, PersistFormatEnum.adPersistXML);
                SaveToCacheRs(Key, FullPathTemp);
            }
            else
            {
                DataTable DtToSave = DataToSave as DataTable;
                DtToSave.TableName = "Content";
                if (DtToSave.DataSet == null)
                {
                    DtToSave.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema);
                }
                else
                {
                    DtToSave.DataSet.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema);
                }
                SaveToCacheDt(Key, FullPathTemp);
            }
        }
Esempio n. 2
0
        private void SaveToCacheRs(string Key, string FullPathToSave)
        {
            CreateCacheFolder();

            string FullPathCache = GetFullPathCacheRs(Key);

            if (!File.Exists(FullPathCache))
            {
                CreateRs(FullPathCache, false);
            }

            Recordset Rs = new Recordset();

            Rs.Open(FullPathCache, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1);

            string Criteria = "Key = '" + Key.Replace("'", "''") + "'";

            Rs.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value);

            if (!Rs.EOF)
            {
                Rs.Fields["Content"].AppendChunk(CFile.GetByteFromFile(FullPathToSave));
            }
            else
            {
                Rs.AddNew(Missing.Value, Missing.Value);
                Rs.Fields["Key"].Value = Key;
                Rs.Fields["Content"].AppendChunk(CFile.GetByteFromFile(FullPathToSave));
            }

            Rs.Save(FullPathCache, PersistFormatEnum.adPersistXML);
            Rs.Close();
            Rs = null;
        }
Esempio n. 3
0
        private string GetFullPathCacheRs(string Key)
        {
            string FullPathIndex = mCacheFolder + "\\CacheIndex.rs";

            if (!File.Exists(FullPathIndex))
            {
                CreateRs(FullPathIndex, true);
            }

            Recordset RsIndex = new Recordset();

            RsIndex.Open(FullPathIndex, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1);

            string FileName = "";
            int    Seq      = 0;

            string Criteria = "Key = '" + Key.Replace("'", "''") + "'";

            RsIndex.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value);
            if (!RsIndex.EOF)
            {
                FileName = (string)RsIndex.Fields["FileName"].Value;
            }
            else
            {
                if (RsIndex.RecordCount > 0)
                {
                    RsIndex.MoveLast();

                    Seq = ((int)RsIndex.Fields["Seq"].Value + 1);

                    FileName = (string)RsIndex.Fields["FileName"].Value;
                    if (((Seq - 1) % drUnitForFile100) == 0)
                    {
                        FileName = GetNextFileName(FileName);
                    }
                }
                else
                {
                    Seq      = 1;
                    FileName = "Cache.rs";
                }

                RsIndex.AddNew(Missing.Value, Missing.Value);
                RsIndex.Fields["Seq"].Value      = Seq;
                RsIndex.Fields["Key"].Value      = Key;
                RsIndex.Fields["FileName"].Value = FileName;

                RsIndex.Save(FullPathIndex, PersistFormatEnum.adPersistXML);
                RsIndex.Close();
                RsIndex = null;
            }

            return(mCacheFolder + "\\" + FileName);
        }
        static void Main(string[] args)
        {
            Recordset rs = new Recordset();
            DataTable dt = sampleDataTable();       //-i. -> SomeFunctionThatReturnsADataTable()

            //-i. Convert DataTable to Recordset
            rs = ConvertToRecordset(dt);

            //-i. Sample Output File
            String     filename = @"C:\yourXMLfile.xml";
            FileStream fstream  = new FileStream(filename, FileMode.Create);

            rs.Save(fstream, PersistFormatEnum.adPersistXML);
        }
Esempio n. 5
0
        private void SaveDataSetToXml(DataSet ds)
        {
            this.XmlFileName = string.Format("PivotTable_{0}_{1}", FormatHelper.TODateInt(System.DateTime.Now).ToString(), FormatHelper.TOTimeInt(System.DateTime.Now).ToString());

            if (!Directory.Exists(this.DownloadPhysicalPath))
            {
                Directory.CreateDirectory(this.DownloadPhysicalPath);
            }

            while (File.Exists(this.DownloadPhysicalPath + this.XmlFileName + ".xml"))
            {
                this.XmlFileName = string.Format("{0}_1", this.XmlFileName);
            }

            string path = this.DownloadPhysicalPath + this.XmlFileName + ".xml";

            Recordset rs = CreateADODBRecordSet(ds);

            rs.Save(path, PersistFormatEnum.adPersistXML);
            rs.Close();
        }
Esempio n. 6
0
        private void CreateRs(string FullPathRs, bool IsIndex)
        {
            Recordset Rs = new Recordset();

            if (IsIndex)
            {
                Rs.Fields.Append("Seq", DataTypeEnum.adInteger, -1, FieldAttributeEnum.adFldIsNullable, null);
                Rs.Fields.Append("Key", DataTypeEnum.adVarChar, 4000, FieldAttributeEnum.adFldKeyColumn, null);
                Rs.Fields.Append("FileName", DataTypeEnum.adVarChar, 256, FieldAttributeEnum.adFldIsNullable, null);
            }
            else
            {
                Rs.Fields.Append("Key", DataTypeEnum.adVarChar, 4000, FieldAttributeEnum.adFldKeyColumn, null);
                Rs.Fields.Append("Content", DataTypeEnum.adLongVarBinary, -1, FieldAttributeEnum.adFldIsNullable, null);
            }

            Rs.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1);

            Rs.Save(FullPathRs, PersistFormatEnum.adPersistXML);
            Rs.Close();
            Rs = null;
        }
Esempio n. 7
0
        public void Remove(string Key)
        {
            string Criteria = "Key = '" + Key.Replace("'", "''") + "'";

            if (mUseAdo)
            {
                string FullPathIndex = mCacheFolder + "\\CacheIndex.rs";
                if (!File.Exists(FullPathIndex))
                {
                    throw new Exception(FullPathIndex + " 파일이 없습니다.");
                }

                Recordset RsIndex = new Recordset();
                RsIndex.Open(FullPathIndex, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1);

                RsIndex.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value);
                if (RsIndex.EOF)
                {
                    throw new Exception(Criteria + " 조건에 해당하는 행이 " + FullPathIndex + " 파일에 없습니다.");
                }

                string FileName      = (string)RsIndex.Fields["FileName"].Value;
                string FullPathCache = mCacheFolder + "\\" + FileName;


                Recordset rs = new Recordset();
                rs.Open(FullPathCache, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1);

                rs.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value);
                if (rs.EOF)
                {
                    throw new Exception(Criteria + " 조건에 해당하는 행이 " + FullPathCache + " 파일에 없습니다.");
                }

                rs.Delete(AffectEnum.adAffectCurrent);
                if (rs.RecordCount > 0)
                {
                    rs.Save(FullPathCache, PersistFormatEnum.adPersistXML);
                    rs.Close();
                }
                else
                {
                    rs.Close();
                    File.Delete(FullPathCache);
                }
                rs = null;

                RsIndex.Delete(AffectEnum.adAffectCurrent);
                RsIndex.Save(FullPathIndex, PersistFormatEnum.adPersistXML);
                RsIndex.Close();
                RsIndex = null;
            }
            else
            {
                string FullPathIndex = mCacheFolder + "\\CacheIndex.dt";
                if (!File.Exists(FullPathIndex))
                {
                    throw new Exception(FullPathIndex + " 파일이 없습니다.");
                }

                DataTable DtIndex = new DataTable();
                DtIndex.ReadXml(FullPathIndex);

                DataRow[] adrIndex = DtIndex.Select(Criteria);
                if (adrIndex.Length == 0)
                {
                    throw new Exception(Criteria + " 조건에 해당하는 행이 " + FullPathIndex + " 파일에 없습니다.");
                }

                string FileName      = (string)adrIndex[0]["FileName"];
                string FullPathCache = mCacheFolder + "\\" + FileName;


                DataTable dt = new DataTable();
                dt.ReadXml(FullPathCache);

                DataRow[] adrCache = dt.Select(Criteria);
                if (adrCache.Length == 0)
                {
                    throw new Exception(Criteria + " 조건에 해당하는 행이 " + FullPathCache + " 파일에 없습니다.");
                }

                dt.Rows.Remove(adrCache[0]);
                if (dt.Rows.Count > 0)
                {
                    dt.WriteXml(FullPathCache, XmlWriteMode.WriteSchema);
                }
                else
                {
                    File.Delete(FullPathCache);
                }

                DtIndex.Rows.Remove(adrIndex[0]);
                DtIndex.WriteXml(FullPathIndex, XmlWriteMode.WriteSchema);
            }
        }
Esempio n. 8
0
        public static string InsertProduct(DataTable dthead, DataTable dtbody)
        {
            U8EnvContext envContext = new U8EnvContext();

            envContext.U8Login = canshu.u8Login;
            //envContext.U8Login = u8Login;
            //第三步:设置API地址标识(Url)
            //当前API:添加新单据的地址标识为:U8API/MaterialOut/Add
            U8ApiAddress myApiAddress = new U8ApiAddress("U8API/ARClose/SaveVouch");

            //第四步:构造APIBroker
            U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);

            //第五步:API参数赋值

            ////给普通参数sVouchType赋值。此参数的数据类型为System.String,此参数按值传递,表示单据类型:11
            //broker.AssignNormalValue("sVouchType", "11");
            ////该参数VouchId为INOUT型普通参数。此参数的数据类型为System.String,此参数按值传递。在API调用返回时,可以通过GetResult("VouchId")获取其值
            //string vouid = "";
            //broker.AssignNormalValue("VouchId", vouid);

            ////该参数domMsg为OUT型参数,由于其数据类型为MSXML2.IXMLDOMDocument2,非一般值类型,因此必须传入一个参数变量。在API调用返回时,可以直接使用该参数


            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocumentClass();
            broker.AssignNormalValue("domMsg", domMsg);

            ////给普通参数bCheck赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否控制可用量。
            //broker.AssignNormalValue("bCheck", true);

            ////给普通参数bBeforCheckStock赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示检查可用量
            //broker.AssignNormalValue("bBeforCheckStock", true);


            ////给普通参数bIsRedVouch赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否红字单据
            //broker.AssignNormalValue("bIsRedVouch", false);

            ////给普通参数sAddedState赋值。此参数的数据类型为System.String,此参数按值传递,表示传空字符串
            //string sadd = "";
            //broker.AssignNormalValue("sAddedState", sadd);

            ////给普通参数bReMote赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否远程:转入false
            //broker.AssignNormalValue("bReMote", false);

            //打开adodb连接
            Connection oCon = new ConnectionClass();

            oCon.Open(envContext.U8Login.UfDbName);
            MSXML2.IXMLDOMDocument2 domhead = new DOMDocument();
            MSXML2.IXMLDOMDocument2 dombody = new DOMDocument();
            //表头赋值


            //表头DOM赋值
            string    sqlt = "select cast(null as nvarchar(2)) as editprop,* from AR_CloseR where 1=2 ";
            Recordset rs   = new Recordset();

            rs.Open(sqlt, oCon, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly);
            rs.Save(domhead, PersistFormatEnum.adPersistXML);
            //插入表头信息
            IXMLDOMElement eleHead = (IXMLDOMElement)domhead.selectSingleNode("//rs:data");
            IXMLDOMElement ele     = (IXMLDOMElement)domhead.createElement("z:row");

            eleHead.appendChild(ele);

            try
            {
                ele.setAttribute("editprop", "A");//A代表增加,M代表修改

                ele.setAttribute("dVouchDate", DateTime.Now.ToShortDateString());
                ele.setAttribute("cdwcode", "0999");
                //ele.setAttribute("id", rdid);
                ele.setAttribute("ccode", "100");
                ele.setAttribute("VT_ID", "65");
                ele.setAttribute("ddate", DateTime.Now.ToShortDateString());    //出库日期


                ele.setAttribute("dnmaketime", DateTime.Now.ToString()); //制单日期
                ele.setAttribute("cmemo", "下料生成");                       //备注
                ele.setAttribute("cmaker", canshu.u8Login.cUserName);    //制单人


                broker.AssignNormalValue("DomHead", domhead);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误发生", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return("0");
            }



            //表体赋值
            string sqlw = "select cast(null as nvarchar(2)) as editprop,* from recordoutsq where 1=2 ";

            //Recordset rs = new Recordset();
            rs.Close();
            rs.Open(sqlw, oCon, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly);
            rs.Save(dombody, PersistFormatEnum.adPersistXML);
            //插入表体尾信息
            //dombody.rowcount =
            IXMLDOMElement eleBody = (IXMLDOMElement)dombody.selectSingleNode("//rs:data");

            for (int i = 0; i < dtbody.Rows.Count; i++)
            {
                ele = (IXMLDOMElement)dombody.createElement("z:row");
                eleBody.appendChild(ele);

                // 表尾赋值

                //string cinvcode = "01019002063";
                //int autoid = 1000;
                //decimal sl = 4m;
                try
                {
                    ele.setAttribute("editprop", "A");
                    //ele.setAttribute("autoid", autoid);
                    ele.setAttribute("cinvcode", DbHelper.GetDbString(dtbody.Rows[i]["存货编码"]));
                    if (string.IsNullOrEmpty(DbHelper.GetDbString(dtbody.Rows[i]["lotno"])) != true)
                    {
                        ele.setAttribute("cBatch", DbHelper.GetDbString(dtbody.Rows[i]["lotno"]));
                    }

                    ele.setAttribute("iquantity", DbHelper.GetDbString(dtbody.Rows[i]["本次下料"]));
                    //MessageBox.Show(dtbody.Rows[i]["本次下料"].ToString());
                    ele.setAttribute("iMPoIds", DbHelper.GetDbInt(dtbody.Rows[i]["allocateid"]));
                    ele.setAttribute("cmocode", DbHelper.GetDbString(dthead.Rows[0]["染料单号"]));
                    ele.setAttribute("inquantity", DbHelper.GetDbdecimal(dtbody.Rows[i]["未下数量"])); //未下应下数量
                    //生产订单信息
                    ele.setAttribute("invcode", DbHelper.GetDbString(dthead.Rows[0]["色号"]));
                    ele.setAttribute("imoseq", DbHelper.GetDbString(dthead.Rows[0]["sortseq"]));
                    ele.setAttribute("iopseq", DbHelper.GetDbString(dtbody.Rows[i]["opseq"]));
                    ele.setAttribute("copdesc", DbHelper.GetDbString(dtbody.Rows[i]["工序"]));
                    ele.setAttribute("iExpiratDateCalcu", 0);
                    ele.setAttribute("irowno", i + 1);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误发生", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return("0");
                }
            }

            broker.AssignNormalValue("DomBody", dombody);

            //测试结果
            //domhead.save(@"d:\2xml");
            //dombody.save(@"d:\3.xm.l");

            //第六步:调用API
            if (!broker.Invoke())
            {
                //错误处理
                Exception apiEx = broker.GetException();
                if (apiEx != null)
                {
                    if (apiEx is MomSysException)
                    {
                        MomSysException sysEx = apiEx as MomSysException;
                        MessageBox.Show("系统异常:" + sysEx.Message);
                        //todo:异常处理
                    }
                    else if (apiEx is MomBizException)
                    {
                        MomBizException bizEx = apiEx as MomBizException;
                        MessageBox.Show("API异常:" + bizEx.Message);
                        //todo:异常处理
                    }
                    //异常原因
                    String exReason = broker.GetExceptionString();
                    if (exReason.Length != 0)
                    {
                        MessageBox.Show("异常原因:" + exReason);
                    }
                }
                //结束本次调用,释放API资源
                broker.Release();
                return("0");
            }

            //第七步:获取返回结果

            //获取返回值
            //获取普通返回值。此返回值数据类型为System.Boolean,此参数按值传递,表示返回值:true:成功,false:失败
            System.Boolean result = Convert.ToBoolean(broker.GetReturnValue());

            if (result == false)
            {
                //获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空
                System.String errMsgRet = broker.GetResult("errMsg") as System.String;
                if (errMsgRet != null)
                {
                    MessageBox.Show(errMsgRet.ToString(), "错误提示1!");
                }
                return("2");
                //MessageBox.Show(result.ToString(), "导入成功提示");
            }
            ////获取out/inout参数值

            ////获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空
            //System.String errMsgRet = broker.GetResult("errMsg") as System.String;
            //if (errMsgRet != null)
            //    MessageBox.Show(errMsgRet.ToString(), "错误提示1!");

            ////获取普通INOUT参数VouchId。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空
            System.String VouchIdRet = broker.GetResult("VouchId") as System.String;

            ////获取普通OUT参数domMsg。此返回值数据类型为MSXML2.IXMLDOMDocument2,在使用该参数之前,请判断是否为空
            //MSXML2.IXMLDOMDocument2 domMsgRet = (broker.GetResult("domMsg")) as MSXML2.IXMLDOMDocument2;
            //if (domMsgRet != null)
            //    MessageBox.Show(domMsgRet.ToString(), "错误提示2!");
            //结束本次调用,释放API资源
            broker.Release();
            return(VouchIdRet);
        }