Esempio n. 1
0
        public ActionResult Index(HttpPostedFileBase postedFile, CUSTOMFILEUPLOAD model, string DdlForm)
        {
            string filePath = string.Empty;
            List <ErrorUploadViewModel> errorUpload = new List <ErrorUploadViewModel>();

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string tahun = DateTime.Now.Year.ToString();
                string bulan = DateTime.Now.Month.ToString();
                string tgl   = DateTime.Now.Day.ToString();
                string jam   = DateTime.Now.Hour.ToString();
                string menit = DateTime.Now.Minute.ToString();
                string detik = DateTime.Now.Second.ToString();

                string tanggalSekarang = "_" + tahun + bulan + tgl + jam + menit + detik;

                string type = "";

                if (DdlForm == "1")
                {
                    type = "Delivery";
                }
                else if (DdlForm == "2")
                {
                    type = "Invoice";
                }
                else if (DdlForm == "3")
                {
                    type = "BPKB";
                }

                string FileName = type + tanggalSekarang + ".xls";
                filePath = path + FileName;

                try
                {
                    postedFile.SaveAs(filePath);

                    IUploadVehicleService svc = new UploadVehicleService();

                    model.ID            = Convert.ToInt32(UploadVehicleService.GenerateID());
                    model.FILEUPLOAD    = FileName;
                    model.MODIFIED_BY   = "namaUser";
                    model.MODIFIED_DATE = DateTime.Now.Date;

                    var result = svc.Add(model);

                    DataTable dt = postedFile.ToDataTable();

                    #region Insert

                    #region Delivery
                    if (type == "Delivery")
                    {
                        int i = 1;
                        foreach (DataRow row in dt.Rows)
                        {
                            IUploadVendorService svcUpldVendor = new UploadVendorService();
                            bool AutheticateData = svcUpldVendor.CheckAutheicatePoNumberByVendorID(row["PONUMBER"].ToString(), System.Web.HttpContext.Current.Session["VendorID"].ToString());
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                if (!svcUpldVendor.IfExist(row["PONUMBER"].ToString()))
                                {
                                    //create new model
                                    ErrorUploadViewModel error = new ErrorUploadViewModel();
                                    error.row     = i;
                                    error.column  = "PONUMBER";
                                    error.message = "PONUMBER doesn't exis";
                                    errorUpload.Add(error);
                                }
                                else
                                {
                                    if (System.Web.HttpContext.Current.Session["GroupID"].ToString() == "Super" || System.Web.HttpContext.Current.Session["GroupID"].ToString() == "PROCUREMENT" || !AutheticateData)
                                    {
                                        //create new model
                                        ErrorUploadViewModel error = new ErrorUploadViewModel();
                                        error.row     = i;
                                        error.column  = "PONUMBER";
                                        error.message = "PONUMBER AND VENDOR ID NOT MATCH";
                                        errorUpload.Add(error);
                                    }
                                    else
                                    {
                                        var dc = new eprocdbDataContext();

                                        #region CUSTOMPO
                                        CUSTOMPO customPO = new CUSTOMPO();
                                        customPO.HARGADPP_INPUT     = TryParseNullDouble(row["HARGADPP_INPUT"].ToString());
                                        customPO.HARGAPPNUNIT_INPUT = TryParseNullDouble(row["HARGAPPNUNIT_INPUT"].ToString());;
                                        customPO.HARGABBN_INPUT     = TryParseNullDouble(row["HARGABBN_INPUT"].ToString());

                                        customPO.DODATE = TryParseNull(row["DODATE"].ToString());

                                        customPO.DONUMBER             = row["DONUMBER"].ToString();
                                        customPO.CARROSERIEVENDORNAME = row["CARROSERIEVENDORNAME"].ToString();
                                        customPO.ACCESORIESADDRESS    = row["ACCESORIESADDRESS"].ToString();
                                        customPO.REMARKSCARROSSERIE   = row["REMARKSCARROSSERIE"].ToString();

                                        customPO.TGLMASUKKAROSERI   = TryParseNull(row["TGLMASUKKAROSERI"].ToString());
                                        customPO.TGLSELESAIKAROSERI = TryParseNull(row["TGLSELESAIKAROSERI"].ToString());

                                        customPO.REMARKS       = row["REMARKS"].ToString();
                                        customPO.MODIFIED_BY   = Session["UserID"].ToString();
                                        customPO.MODIFIED_DATE = DateTime.Now.Date;

                                        customPO.ACTUALDATEDELIVEREDUNIT = TryParseNull(row["TANGGALBSTB"].ToString());

                                        var resultPO = svcUpldVendor.UpdateDeliveryCustPO(row["PONUMBER"].ToString(), customPO);
                                        #endregion

                                        #region CUSTOMBPKB
                                        CUSTOMBPKB customBPKB = new CUSTOMBPKB();

                                        customBPKB.NOPOLISI_INPUT = row["NOPOLISI_INPUT"].ToString();
                                        customBPKB.TGLSTNK_INPUT  = TryParseNull(row["TGLSTNK_INPUT"].ToString());
                                        customBPKB.STCKDATE       = TryParseNull(row["STCKDATE"].ToString());
                                        customBPKB.TGLSERAHBPKB   = TryParseNull(row["TGLSERAHBPKB"].ToString());
                                        customPO.MODIFIED_BY      = Session["UserID"].ToString();
                                        customPO.MODIFIED_DATE    = DateTime.Now.Date;

                                        var resultBPKB = svcUpldVendor.UpdateDeliveryCustBPKB(row["PONUMBER"].ToString(), customBPKB);
                                        #endregion

                                        #region CUSTOMGR
                                        CUSTOMGR customGR = new CUSTOMGR();

                                        customGR.NOCHASIS_INPUT = row["NOCHASIS_INPUT"].ToString();
                                        customGR.NOENGINE_INPUT = row["NOENGINE_INPUT"].ToString();
                                        customPO.MODIFIED_BY    = Session["UserID"].ToString();
                                        customPO.MODIFIED_DATE  = DateTime.Now.Date;

                                        var resultGR = svcUpldVendor.UpdateDeliveryCustGR(row["PONUMBER"].ToString(), customGR);
                                        #endregion
                                    }
                                }
                            }
                        }
                        i++;
                    }

                    #endregion

                    #region Invoice
                    if (type == "Invoice")
                    {
                        int i = 1;
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                IUploadVendorService svcUpldVendor = new UploadVendorService();
                                bool AutheticateData = svcUpldVendor.CheckAutheicatePoNumberByVendorID(row["PONUMBER"].ToString(), System.Web.HttpContext.Current.Session["VendorID"].ToString());

                                if (!svcUpldVendor.IfExist(row["PONUMBER"].ToString()))
                                {
                                    //create new model
                                    ErrorUploadViewModel error = new ErrorUploadViewModel();
                                    error.row     = i;
                                    error.column  = "PONUMBER";
                                    error.message = "PONUMBER doesn't exist";
                                    errorUpload.Add(error);
                                }
                                else
                                {
                                    if (System.Web.HttpContext.Current.Session["GroupID"].ToString() == "Super" || System.Web.HttpContext.Current.Session["GroupID"].ToString() == "PROCUREMENT" || !AutheticateData)
                                    {
                                        //create new model
                                        ErrorUploadViewModel error = new ErrorUploadViewModel();
                                        error.row     = i;
                                        error.column  = "PONUMBER";
                                        error.message = "PONUMBER AND VENDOR ID NOT MATCH";
                                        errorUpload.Add(error);
                                    }
                                    else
                                    {
                                        var dc = new eprocdbDataContext();

                                        #region CUSTOMPO
                                        CUSTOMPO customPO = new CUSTOMPO();
                                        customPO.TGLGI         = TryParseNull(row["TGLGI"].ToString());
                                        customPO.MODIFIED_BY   = Session["UserID"].ToString();
                                        customPO.MODIFIED_DATE = DateTime.Now.Date;

                                        var resultPO = svcUpldVendor.UpdateInvoiceCustPO(row["PONUMBER"].ToString(), customPO);

                                        #endregion

                                        #region CUSTOMBPKB
                                        CUSTOMBPKB customBpkb = new CUSTOMBPKB();

                                        customBpkb.NOFAKTUR      = row["NOFAKTUR"].ToString();
                                        customBpkb.MODIFIED_BY   = Session["UserID"].ToString();
                                        customBpkb.MODIFIED_DATE = DateTime.Now.Date;

                                        var resultBPKB = svcUpldVendor.UpdateInvoiceCustBpkb(row["PONUMBER"].ToString(), customBpkb);
                                        #endregion

                                        #region CUSTOMGR
                                        CUSTOMGR customGR = new CUSTOMGR();

                                        customGR.STATUSDELIVERYUNIT = row["STATUSDELIVERYUNIT"].ToString();
                                        customGR.MODIFIED_BY        = Session["UserID"].ToString();
                                        customGR.MODIFIED_DATE      = DateTime.Now.Date;

                                        var resultGR = svcUpldVendor.UpdateInvoiceCustGR(row["PONUMBER"].ToString(), customGR);
                                        #endregion

                                        #region CUSTOMIR
                                        CUSTOMIR customIR = new CUSTOMIR();

                                        customIR.INVNO         = row["INVNO"].ToString();
                                        customIR.INVDATE       = TryParseNull(row["INVDATE"].ToString());
                                        customIR.MODIFIED_BY   = Session["UserID"].ToString();
                                        customIR.MODIFIED_DATE = DateTime.Now.Date;

                                        var resultIR = svcUpldVendor.UpdateInvoiceCustIR(row["PONUMBER"].ToString(), customIR);
                                        #endregion
                                    }
                                }
                            }
                            i++;
                        }
                    }
                    #endregion

                    #region Bpkb
                    if (type == "BPKB")
                    {
                        int i = 1;
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                IUploadVendorService svcUpldVendor = new UploadVendorService();
                                bool AutheticateData = svcUpldVendor.CheckAutheicatePoNumberByVendorID(row["PONUMBER"].ToString(), System.Web.HttpContext.Current.Session["VendorID"].ToString());
                                if (!svcUpldVendor.IfExist(row["PONUMBER"].ToString()))
                                {
                                    //create new model
                                    ErrorUploadViewModel error = new ErrorUploadViewModel();
                                    error.row     = i;
                                    error.column  = "PONUMBER";
                                    error.message = "PONUMBER doesn't exist";
                                    errorUpload.Add(error);
                                }
                                else
                                {
                                    if (System.Web.HttpContext.Current.Session["GroupID"].ToString() == "Super" || System.Web.HttpContext.Current.Session["GroupID"].ToString() == "PROCUREMENT" || !AutheticateData)
                                    {
                                        //create new model
                                        ErrorUploadViewModel error = new ErrorUploadViewModel();
                                        error.row     = i;
                                        error.column  = "PONUMBER";
                                        error.message = "PONUMBER AND VENDOR ID NOT MATCH";
                                        errorUpload.Add(error);
                                    }
                                    else
                                    {
                                        var dc = new eprocdbDataContext();

                                        #region CUSTOMBPKB
                                        CUSTOMBPKB customBPKB = new CUSTOMBPKB();

                                        customBPKB.ACTUALDELIVERYBPKBTOFINANCE = TryParseNull(row["ACTUALDELIVERYBPKBTOFINANCE"].ToString());
                                        customBPKB.ACTUALRECEIVEDBPKBDICAB     = TryParseNull(row["ACTUALRECEIVEDBPKBDICAB"].ToString());
                                        customBPKB.KETBPKB                      = row["KETBPKB"].ToString();
                                        customBPKB.NOBPKB                       = row["NOBPKB"].ToString();
                                        customBPKB.KETSURATUBAHBENTUK           = row["KETSURATUBAHBENTUK"].ToString();
                                        customBPKB.KETERANGANSURATRUBAHWARNA    = row["KETERANGANSURATRUBAHWARNA"].ToString();
                                        customBPKB.NOFAKTUR                     = row["NOFAKTUR"].ToString();
                                        customBPKB.TGLFAKTUR                    = TryParseNull(row["TGLFAKTUR"].ToString());
                                        customBPKB.NOSERTIFIKAT                 = row["NOSERTIFIKAT"].ToString();
                                        customBPKB.TGLSERTIFIKAT                = TryParseNull(row["TGLSERTIFIKAT"].ToString());
                                        customBPKB.NOFORMULIRA                  = row["NOFORMULIRA"].ToString();
                                        customBPKB.TGLFORMULIRA                 = TryParseNull(row["TGLFORMULIRA"].ToString());
                                        customBPKB.NOSURATUBAHBENTUK            = row["NOSURATUBAHBENTUK"].ToString();
                                        customBPKB.TGLSURATUBAHBENTUK           = TryParseNull(row["TGLSURATUBAHBENTUK"].ToString());
                                        customBPKB.NOSURATRUBAHWARNA            = row["NOSURATRUBAHWARNA"].ToString();
                                        customBPKB.TANGGALSURATRUBAHWARNA       = TryParseNull(row["TANGGALSURATRUBAHWARNA"].ToString());
                                        customBPKB.NOSERTIFIKATREGUJITIPE       = row["NOSERTIFIKATREGUJITIPE"].ToString();
                                        customBPKB.ACTUALRECEIVEDBPKBDIHO       = TryParseNull(row["ACTUALRECEIVEDBPKBDIHO"].ToString());
                                        customBPKB.ACTUALDELIVERYBPKBTOFINANCE  = TryParseNull(row["ACTUALDELIVERYBPKBTOFINANCE"].ToString());
                                        customBPKB.ACTUALRECEIVEDBPKBHOBACK     = TryParseNull(row["ACTUALRECEIVEDBPKBHOBACK"].ToString());
                                        customBPKB.DATEDELIVERYTOBRANCHORVENDOR = TryParseNull(row["DATEDELIVERYTOBRANCHORVENDOR"].ToString());
                                        customBPKB.REMARKSDETAILPROBLEM         = row["REMARKSDETAILPROBLEM"].ToString();
                                        customBPKB.MODIFIED_BY                  = Session["UserID"].ToString();
                                        customBPKB.MODIFIED_DATE                = DateTime.Now.Date;

                                        var resultBPKB = svcUpldVendor.UpdateBpkbCustBPKB(row["PONUMBER"].ToString(), customBPKB);
                                        #endregion
                                    }
                                }
                            }
                            i++;
                        }
                    }
                    #endregion

                    #endregion

                    if (filePath != null || filePath != string.Empty)
                    {
                        if ((System.IO.File.Exists(filePath)))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }
                    if (errorUpload.Count > 0)
                    {
                        this.AddNotification("File uploaded failed.", NotificationType.ERROR);
                    }
                    else
                    {
                        this.AddNotification("File uploaded successfully.", NotificationType.SUCCESS);
                    }
                }
                catch (Exception ex)
                {
                    general.AddLogError("Upload Vendor", ex.Message, ex.StackTrace);
                    this.AddNotification("File uploaded failed.", NotificationType.ERROR);
                    return(View("~/Views/Upload/Vendor/Index.cshtml"));

                    throw ex;
                }
            }

            IEnumerable <ErrorUploadViewModel> eu = errorUpload;
            return(View("~/Views/Upload/Vendor/Index.cshtml", eu));
        }
Esempio n. 2
0
        public ActionResult Index(HttpPostedFileBase postedFile, CUSTOMFILEUPLOAD model, string DdlForm)
        {
            string filePath = string.Empty;

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string tahun = DateTime.Now.Year.ToString();
                string bulan = DateTime.Now.Month.ToString();
                string tgl   = DateTime.Now.Day.ToString();
                string jam   = DateTime.Now.Hour.ToString();
                string menit = DateTime.Now.Minute.ToString();
                string detik = DateTime.Now.Second.ToString();

                string tanggalSekarang = "_" + tahun + bulan + tgl + jam + menit + detik;

                string type = "";

                if (DdlForm == "1")
                {
                    type = "Delivery";
                }
                else if (DdlForm == "2")
                {
                    type = "Invoice";
                }
                else if (DdlForm == "3")
                {
                    type = "BPKB";
                }

                string FileName = type + tanggalSekarang + ".xls";
                filePath = path + FileName;
                string errorPoNumber = string.Empty;
                try
                {
                    postedFile.SaveAs(filePath);

                    IUploadVehicleService svc = new UploadVehicleService();

                    model.ID            = Convert.ToInt32(UploadVehicleService.GenerateID());
                    model.FILEUPLOAD    = FileName;
                    model.MODIFIED_BY   = "namaUser";
                    model.MODIFIED_DATE = DateTime.Now.Date;

                    var result = svc.Add(model);

                    DataTable dt = postedFile.ToDataTable();

                    #region Insert

                    #region Delivery
                    if (type == "Delivery")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                IUploadVehicleService svcUpldVehicle = new UploadVehicleService();

                                #region CUSTOMPO
                                CUSTOMPO customPO = new CUSTOMPO();

                                customPO.PURCHASESTATUS       = row["PURCHASESTATUS"].ToString();
                                customPO.CARROSERIEVENDORNAME = row["CARROSERIEVENDORNAME"].ToString();
                                customPO.ACCESORIESADDRESS    = row["ACCESORIESADDRESS"].ToString();
                                customPO.REMARKSCARROSSERIE   = row["REMARKSCARROSSERIE"].ToString();
                                customPO.PICKAROSERI          = row["PICKAROSERI"].ToString();
                                customPO.NOTELEPONKAROSERI    = row["NOTELEPONKAROSERI"].ToString();
                                customPO.BENTUKKAROSERI       = row["BENTUKKAROSERI"].ToString();

                                customPO.PROMISEDLVDATEPO   = TryParseNull(row["PROMISEDLVDATEPO"].ToString());
                                customPO.TGLSELESAIKAROSERI = TryParseNull(row["PROMISEDLVDATEPO"].ToString());

                                //DateTime BSTB;
                                //DateTime.TryParse(row["TANGGALBSTB"].ToString(), out BSTB);
                                //customPO.ACTUALDATEDELIVEREDUNIT = BSTB;

                                customPO.REMARKS       = row["REMARKS"].ToString();
                                customPO.MODIFIED_BY   = Session["UserID"].ToString();
                                customPO.MODIFIED_DATE = DateTime.Now.Date;

                                var resultPO = svcUpldVehicle.UpdateDeliveryCustPO(row["PONUMBER"].ToString(), customPO);
                                #endregion
                            }
                        }
                    }
                    #endregion

                    #region Invoice
                    if (type == "Invoice")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                IUploadVehicleService svcUpldVehicle = new UploadVehicleService();

                                #region CUSTOMPO
                                CUSTOMPO customPO = new CUSTOMPO();
                                customPO.TGLMASUKKAROSERI        = TryParseNull(row["TGLMASUKKAROSERI"].ToString());
                                customPO.DONUMBER                = row["DONUMBER"].ToString();
                                customPO.DODATE                  = TryParseNull(row["DODATE"].ToString());
                                customPO.REASONREVISEDBYVENDOR   = row["REASONREVISEDBYVENDOR"].ToString();
                                customPO.ACTUALDATEDELIVEREDUNIT = TryParseNull(row["TANGGALBSTB"].ToString());
                                customPO.MODIFIED_BY             = Session["UserID"].ToString();
                                customPO.MODIFIED_DATE           = DateTime.Now.Date;

                                var resultPO = svcUpldVehicle.UpdateInvoiceCustPO(row["PONUMBER"].ToString(), customPO);
                                #endregion

                                /*
                                 #region CUSTOMBPKB
                                 * CUSTOMBPKB customBpkb = new CUSTOMBPKB();
                                 *
                                 * customBpkb.NOFAKTUR = row["NOFAKTUR"].ToString();
                                 * customBpkb.MODIFIED_BY = Session["UserID"].ToString();
                                 * customBpkb.MODIFIED_DATE = DateTime.Now.Date;
                                 *
                                 * var resultBPKB = svcUpldVehicle.UpdateInvoiceCustBpkb(row["PONUMBER"].ToString(), customBpkb);
                                 #endregion
                                 *
                                 #region CUSTOMGR
                                 * CUSTOMGR customGR = new CUSTOMGR();
                                 *
                                 * customGR.NOCHASIS_INPUT = row["NOCHASIS_INPUT"].ToString();
                                 * customGR.NOENGINE_INPUT = row["NOENGINE_INPUT"].ToString();
                                 * customGR.ACTUALRECEIVEDUNITINBDEL = TryParseNull(row["ACTUALRECEIVEDUNITINBDEL"].ToString());
                                 * customGR.MODIFIED_BY = Session["UserID"].ToString();
                                 * customGR.MODIFIED_DATE = DateTime.Now.Date;
                                 *
                                 * var resultGR = svcUpldVehicle.UpdateInvoiceCustGR(row["PONUMBER"].ToString(), customGR);
                                 #endregion
                                 *
                                 #region CUSTOMIR
                                 * CUSTOMIR customIR = new CUSTOMIR();
                                 *
                                 * customIR.NOFAKTURPAJAK = row["NOFAKTURPAJAK"].ToString();
                                 * customIR.TERMOFPAYMENT = TryParseNullInt(row["TERMOFPAYMENT"].ToString());
                                 * customIR.TGLSERAHTAGIHAN = TryParseNull(row["TGLSERAHTAGIHAN"].ToString());
                                 * customIR.KETBAYAR = row["KETBAYAR"].ToString();
                                 * customIR.KETTAGIHAN = row["KETTAGIHAN"].ToString();
                                 * customIR.MODIFIED_BY = Session["UserID"].ToString();
                                 * customIR.MODIFIED_DATE = DateTime.Now.Date;
                                 *
                                 * var resultIR = svcUpldVehicle.UpdateInvoiceCustIR(row["PONUMBER"].ToString(), customIR);
                                 #endregion
                                 */
                            }
                        }
                    }
                    #endregion

                    #region Bpkb
                    string        Message      = string.Empty;
                    StringBuilder listPONumber = new StringBuilder();
                    if (type == "BPKB")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();
                                var md = (from c in dc.CUSTOMBPKBs
                                          where c.PONUMBER == row["PONUMBER"].ToString().Trim()
                                          select c).SingleOrDefault();
                                if (md != null)
                                {
                                    IUploadVehicleService svcUpldVehicle = new UploadVehicleService();

                                    #region CUSTOMBPKB
                                    CUSTOMBPKB customBPKB = new CUSTOMBPKB();

                                    customBPKB.ACTUALRECEIVEDBPKBDIHO = TryParseNull(row["ACTUALRECEIVEDBPKBDIHO"].ToString());

                                    customBPKB.ACTUALRECEIVEDBPKBDICAB = TryParseNull(row["ACTUALRECEIVEDBPKBDICAB"].ToString());

                                    customBPKB.DETAILPROBLEM    = row["DETAILPROBLEM"].ToString();
                                    customBPKB.REASONREVISEBPKB = row["REASONREVISEBPKB"].ToString();

                                    customBPKB.TGLSERAHBPKB = TryParseNull(row["TGLSERAHBPKB"].ToString());

                                    customBPKB.ACTUALDELIVERYBPKBTOFINANCE = TryParseNull(row["ACTUALDELIVERYBPKBTOFINANCE"].ToString());

                                    customBPKB.ACTUALRECEIVEDBPKBHOBACK = TryParseNull(row["ACTUALRECEIVEDBPKBHOBACK"].ToString());

                                    customBPKB.DATEDELIVERYTOBRANCHORVENDOR = TryParseNull(row["DATEDELIVERYTOBRANCHORVENDOR"].ToString());

                                    customBPKB.NOBPKB             = row["NOBPKB"].ToString();
                                    customBPKB.NOFAKTUR           = row["NOFAKTUR"].ToString();
                                    customBPKB.NOSERTIFIKAT       = row["NOSERTIFIKAT"].ToString();
                                    customBPKB.NOFORMULIRA        = row["NOFORMULIRA"].ToString();
                                    customBPKB.KETSURATUBAHBENTUK = row["KETSURATUBAHBENTUK"].ToString();
                                    customBPKB.NOSURATUBAHBENTUK  = row["NOSURATUBAHBENTUK"].ToString();

                                    customBPKB.TGLSURATUBAHBENTUK = TryParseNull(row["TGLSURATUBAHBENTUK"].ToString());

                                    customBPKB.KETERANGANSURATRUBAHWARNA = row["KETERANGANSURATRUBAHWARNA"].ToString();
                                    customBPKB.NOSURATRUBAHWARNA         = row["NOSURATRUBAHWARNA"].ToString();

                                    customBPKB.TANGGALSURATRUBAHWARNA = TryParseNull(row["TANGGALSURATRUBAHWARNA"].ToString());

                                    customBPKB.NOSERTIFIKATREGUJITIPE = row["NOSERTIFIKATREGUJITIPE"].ToString();
                                    customBPKB.REMARKSDETAILPROBLEM   = row["REMARKSDETAILPROBLEM"].ToString();
                                    customBPKB.KETBPKB       = row["KETBPKB"].ToString();
                                    customBPKB.MODIFIED_BY   = Session["UserID"].ToString();
                                    customBPKB.MODIFIED_DATE = DateTime.Now.Date;

                                    var resultBPKB = svcUpldVehicle.UpdateBpkbCustBPKB(row["PONUMBER"].ToString(), customBPKB);
                                    #endregion
                                }
                                else
                                {
                                    Message = "PONUMBER doesn't exist ";
                                    listPONumber.Append(row["PONUMBER"].ToString()).Append(", ");
                                }
                            }
                        }
                    }
                    #endregion

                    #endregion

                    if (filePath != null || filePath != string.Empty)
                    {
                        if ((System.IO.File.Exists(filePath)))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }
                    if (!string.IsNullOrEmpty(Message))
                    {
                        this.AddNotification("File uploaded failed. " + Message + listPONumber, NotificationType.ERROR);
                    }
                    else
                    {
                        this.AddNotification("File uploaded successfully.", NotificationType.SUCCESS);
                    }
                }
                catch (Exception ex)
                {
                    general.AddLogError("Upload Vehicle", ex.Message, ex.StackTrace);
                    this.AddNotification("File uploaded failed.", NotificationType.ERROR);
                    this.AddNotification("PONumber Tidak ditemukan", NotificationType.ERROR);
                    return(View("~/Views/Upload/Vehicle/Index.cshtml"));

                    throw ex;
                }
            }

            return(View("~/Views/Upload/Vehicle/Index.cshtml"));
        }
        public ActionResult Index(HttpPostedFileBase postedFile, CUSTOMFILEUPLOAD model, string DdlMasterType)
        {
            string filePath = string.Empty;

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string tahun = DateTime.Now.Year.ToString();
                string bulan = DateTime.Now.Month.ToString();
                string tgl   = DateTime.Now.Day.ToString();
                string jam   = DateTime.Now.Hour.ToString();
                string menit = DateTime.Now.Minute.ToString();
                string detik = DateTime.Now.Second.ToString();

                string tanggalSekarang = "_" + tahun + bulan + tgl + jam + menit + detik;

                string type = "";

                if (DdlMasterType == "CUSTOMCOMPANY")
                {
                    type = "CUSTOMCOMPANY";
                }
                else if (DdlMasterType == "MSMATERIAL")
                {
                    type = "MSMATERIAL";
                }
                else if (DdlMasterType == "MSPLANT")
                {
                    type = "MSPLANT";
                }
                else if (DdlMasterType == "MSVENDOR")
                {
                    type = "MSVENDOR";
                }
                else if (DdlMasterType == "MSUSER")
                {
                    type = "MSUSER";
                }
                string FileName = type + tanggalSekarang + ".xls";
                filePath = path + FileName;

                try
                {
                    postedFile.SaveAs(filePath);

                    IUploadVehicleService svcUploadFilename = new UploadVehicleService();

                    model.ID            = Convert.ToInt32(UploadVehicleService.GenerateID());
                    model.FILEUPLOAD    = FileName;
                    model.MODIFIED_BY   = "UserName";
                    model.MODIFIED_DATE = DateTime.Now;
                    svcUploadFilename.Add(model);

                    DataTable dt = postedFile.ToDataTable();

                    #region Insert

                    #region CUSTOMCOMPANY
                    if (type == "CUSTOMCOMPANY")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["COMPANYCODE"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                //cek code ada atau tidak
                                var compCode = (from c in dc.CUSTOMCOMPANies
                                                where c.COMPANYCODE == row["COMPANYCODE"].ToString()
                                                select new
                                {
                                    c.COMPANYCODE
                                }).ToList();

                                string code = string.Empty;

                                foreach (var value in compCode)
                                {
                                    code = value.COMPANYCODE;
                                }

                                //isi model customcompany sesuai row data table
                                CUSTOMCOMPANY objModelComp = new CUSTOMCOMPANY();

                                objModelComp.COMPANYCODE    = row["COMPANYCODE"].ToString();
                                objModelComp.COMPANYNAME    = row["COMPANYNAME"].ToString();
                                objModelComp.ALAMAT         = row["ALAMAT"].ToString();
                                objModelComp.KOTA           = row["KOTA"].ToString();
                                objModelComp.REGION         = row["REGION"].ToString();
                                objModelComp.POSTALCODE     = row["POSTALCODE"].ToString();
                                objModelComp.TELEPON        = row["TELEPON"].ToString();
                                objModelComp.NPWP           = row["NPWP"].ToString();
                                objModelComp.KTPTDP         = row["KTPTDP"].ToString();
                                objModelComp.COMPANYCODETSO = row["COMPANYCODETSO"].ToString();

                                //jika ada update
                                if (code.ToString() != "")
                                {
                                    objModelComp.DIUBAHOLEH = Session["UserID"].ToString();
                                    objModelComp.DIUBAHTGL  = DateTime.Now.Date;

                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.UpdateCompany(row["COMPANYCODE"].ToString(), objModelComp);
                                }

                                //jika tidak ada Insert
                                else
                                {
                                    objModelComp.DIBUATOLEH = Session["UserID"].ToString();
                                    objModelComp.DIBUATTGL  = DateTime.Now.Date;

                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.AddCompany(objModelComp);
                                }
                            }
                        }
                    }
                    #endregion

                    #region MSMATERIAL
                    if (type == "MSMATERIAL")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["MATERIALNUMBER"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                //cek code ada atau tidak
                                var materialNumber = (from c in dc.MSMATERIALs
                                                      where c.MATERIALNUMBER == row["MATERIALNUMBER"].ToString()
                                                      select new
                                {
                                    c.MATERIALNUMBER
                                }).ToList();

                                string code = string.Empty;

                                foreach (var value in materialNumber)
                                {
                                    code = value.MATERIALNUMBER;
                                }

                                //isi model MSMATERIAL sesuai row data table
                                MSMATERIAL objModelMaterial = new MSMATERIAL();

                                objModelMaterial.MATERIALNUMBER = row["MATERIALNUMBER"].ToString();
                                //objModelMaterial.DESCRIPTION = row["DESCRIPTION"].ToString();
                                //objModelMaterial.MATERIALTYPE = row["MATERIALTYPE"].ToString();
                                //objModelMaterial.MATERIALGROUP = row["MATERIALGROUP"].ToString();
                                //objModelMaterial.OLDMATERIAL = row["OLDMATERIAL"].ToString();
                                //objModelMaterial.BOMMATERIAL = row["BOMMATERIAL"].ToString();
                                //objModelMaterial.BRAND = row["BRAND"].ToString();
                                //objModelMaterial.MODEL = row["MODEL"].ToString();
                                //objModelMaterial.GARDAN = row["GARDAN"].ToString();
                                //objModelMaterial.YEAR = row["YEAR"].ToString();
                                //objModelMaterial.PURCHASEGROUPID = row["PURCHASEGROUPID"].ToString();
                                objModelMaterial.MATERIALIDVENDOR = row["MATERIALIDVENDOR"].ToString();

                                //double price = 0;
                                //Double.TryParse(row["PRICELIST"].ToString(), out price);
                                //objModelMaterial.PRICELIST = price;

                                //jika ada update
                                if (code.ToString() != "")
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.UpdateMaterial(row["MATERIALNUMBER"].ToString(), objModelMaterial);
                                }

                                //jika tidak ada Insert
                                else
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    //var result = svc.AddMaterial(objModelMaterial);
                                }
                            }
                        }
                    }
                    #endregion

                    #region MSPLANT
                    if (type == "MSPLANT")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PLANTID"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                //cek code ada atau tidak
                                var plantID = (from c in dc.MSPLANTs
                                               where c.PLANTID == row["PLANTID"].ToString()
                                               select new
                                {
                                    c.PLANTID
                                }).ToList();

                                string code = string.Empty;

                                foreach (var value in plantID)
                                {
                                    code = value.PLANTID;
                                }

                                //isi model MSPLANT sesuai row data table
                                MSPLANT objModelPlant = new MSPLANT();

                                objModelPlant.PLANTID           = row["PLANTID"].ToString();
                                objModelPlant.NAME              = row["NAME"].ToString();
                                objModelPlant.ALAMAT            = row["ALAMAT"].ToString();
                                objModelPlant.KELURAHAN         = row["KELURAHAN"].ToString();
                                objModelPlant.KECAMATAN         = row["KECAMATAN"].ToString();
                                objModelPlant.CITY              = row["CITY"].ToString();
                                objModelPlant.REGION            = row["REGION"].ToString();
                                objModelPlant.CONTACTPERSONNAME = row["CONTACTPERSONNAME"].ToString();
                                objModelPlant.ALAMAT2           = row["ALAMAT2"].ToString();
                                objModelPlant.ALAMAT3           = row["ALAMAT3"].ToString();
                                objModelPlant.ALAMAT4           = row["ALAMAT4"].ToString();
                                objModelPlant.ALAMAT5           = row["ALAMAT5"].ToString();
                                objModelPlant.PROPINSI          = row["PROPINSI"].ToString();
                                objModelPlant.PIC         = row["PIC"].ToString();
                                objModelPlant.TITLECP     = row["TITLECP"].ToString();
                                objModelPlant.NOHPCP      = row["NOHPCP"].ToString();
                                objModelPlant.NOTELPPLANT = row["NOTELPPLANT"].ToString();
                                objModelPlant.POSTALCODE  = row["POSTALCODE"].ToString();
                                objModelPlant.CUSTOMERNO  = row["CUSTOMER_NUMBER"].ToString();
                                //jika ada update
                                if (code.ToString() != "")
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.UpdatePlant(row["PLANTID"].ToString(), objModelPlant);
                                }

                                //jika tidak ada Insert
                                else
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.AddPlant(objModelPlant);
                                }
                            }
                        }
                    }
                    #endregion

                    #region MSVENDOR
                    if (type == "MSVENDOR")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["VENDORID"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                //cek code ada atau tidak
                                var vendorID = (from c in dc.MSVENDORs
                                                where c.VENDORID == row["VENDORID"].ToString()
                                                select new
                                {
                                    c.VENDORID
                                }).ToList();

                                string code = string.Empty;

                                foreach (var value in vendorID)
                                {
                                    code = value.VENDORID;
                                }

                                //isi model MSVENDOR sesuai row data table
                                MSVENDOR objModelVendor = new MSVENDOR();

                                objModelVendor.VENDORID = row["VENDORID"].ToString();
                                //objModelVendor.VENDORNAME = row["VENDORNAME"].ToString();
                                //objModelVendor.STREET = row["STREET"].ToString();
                                //objModelVendor.DISTRIC = row["DISTRIC"].ToString();
                                //objModelVendor.CITY = row["CITY"].ToString();
                                //objModelVendor.POSTALCODE = row["POSTALCODE"].ToString();
                                //objModelVendor.TELEPHONE = row["TELEPHONE"].ToString();
                                //objModelVendor.EMAIL = row["EMAIL"].ToString();
                                //objModelVendor.EMAIL2 = row["EMAIL2"].ToString();
                                //objModelVendor.EMAIL3 = row["EMAIL3"].ToString();
                                //objModelVendor.EMAIL4 = row["EMAIL4"].ToString();
                                //objModelVendor.EMAIL5 = row["EMAIL5"].ToString();
                                //objModelVendor.EMAIL6 = row["EMAIL6"].ToString();
                                //objModelVendor.EMAIL7 = row["EMAIL7"].ToString();
                                //objModelVendor.EMAIL8 = row["EMAIL8"].ToString();
                                //objModelVendor.PLANTIDTSO = row["PLANTIDTSO"].ToString();
                                objModelVendor.B2B = row["ISB2B"].ToString() == "1" ? '1' : '0';

                                //jika ada update
                                if (code.ToString() != "")
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.UpdateVendor(row["VENDORID"].ToString(), objModelVendor);
                                }

                                //jika tidak ada Insert
                                else
                                {
                                    //IUploadMasterService svc = new UploadMasterService();
                                    //var result = svc.AddVendor(objModelVendor);
                                }
                            }
                        }
                    }
                    #endregion

                    #region MSUSER
                    if (type == "MSUSER")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["UserId"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                //cek code ada atau tidak
                                var UserId = (from c in dc.Master_Users
                                              where c.UserID == row["UserId"].ToString()
                                              select new
                                {
                                    c.UserID
                                }).ToList();

                                string code = string.Empty;

                                foreach (var value in UserId)
                                {
                                    code = value.UserID;
                                }

                                //isi model MSVENDOR sesuai row data table
                                Master_User objModelUser = new Master_User();

                                objModelUser.UserID    = row["UserId"].ToString();
                                objModelUser.FullName  = row["NamaLengkap"].ToString();
                                objModelUser.GroupID   = row["Group"].ToString();
                                objModelUser.id_vendor = row["IdVendor"].ToString();


                                //jika ada update
                                if (code.ToString() != "")
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.UpdateUser(row["UserId"].ToString(), objModelUser);
                                }

                                //jika tidak ada Insert
                                else
                                {
                                    IUploadMasterService svc = new UploadMasterService();
                                    var result = svc.AddUser(objModelUser);
                                }
                            }
                        }
                    }
                    #endregion

                    #endregion

                    if (filePath != null || filePath != string.Empty)
                    {
                        if ((System.IO.File.Exists(filePath)))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }

                    this.AddNotification("File uploaded successfully.", NotificationType.SUCCESS);
                }
                catch (Exception ex)
                {
                    general.AddLogError("Upload Master", ex.Message, ex.StackTrace);
                    this.AddNotification("File uploaded failed.", NotificationType.ERROR);
                    return(View("~/Views/Master/UploadMaster/Index.cshtml"));

                    throw ex;
                }
            }

            return(View("~/Views/Master/UploadMaster/Index.cshtml"));
        }
Esempio n. 4
0
        public ActionResult Index(HttpPostedFileBase postedFile, CUSTOMFILEUPLOAD model, string DdlForm)
        {
            string filePath = string.Empty;

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string tahun = DateTime.Now.Year.ToString();
                string bulan = DateTime.Now.Month.ToString();
                string tgl   = DateTime.Now.Day.ToString();
                string jam   = DateTime.Now.Hour.ToString();
                string menit = DateTime.Now.Minute.ToString();
                string detik = DateTime.Now.Second.ToString();

                string tanggalSekarang = "_" + tahun + bulan + tgl + jam + menit + detik;

                string type = "";

                if (DdlForm == "1")
                {
                    type = "Invoice";
                }

                string FileName = type + tanggalSekarang + ".xls";
                filePath = path + FileName;

                try
                {
                    postedFile.SaveAs(filePath);

                    IUploadVehicleService svc = new UploadVehicleService();

                    model.ID            = Convert.ToInt32(UploadVehicleService.GenerateID());
                    model.FILEUPLOAD    = FileName;
                    model.MODIFIED_BY   = "namaUser";
                    model.MODIFIED_DATE = DateTime.Now.Date;

                    var result = svc.Add(model);

                    DataTable dt = postedFile.ToDataTable();

                    #region Insert

                    #region Invoice
                    if (type == "Invoice")
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            //cek row null atau tidak
                            if (row["PONUMBER"] != DBNull.Value)
                            {
                                var dc = new eprocdbDataContext();

                                IUploadVehicleService svcUpldVehicle = new UploadVehicleService();

                                #region CUSTOMIR
                                CUSTOMIR CUSTOMIR = new CUSTOMIR();
                                CUSTOMIR.NOAP = row["BPHNUMBER"].ToString();
                                var resultPO = svcUpldVehicle.UpdateCustomIR(row["PONUMBER"].ToString(), CUSTOMIR);
                                #endregion
                            }
                        }
                    }
                    #endregion



                    #endregion

                    if (filePath != null || filePath != string.Empty)
                    {
                        if ((System.IO.File.Exists(filePath)))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }

                    this.AddNotification("File uploaded successfully.", NotificationType.SUCCESS);
                }
                catch (Exception ex)
                {
                    general.AddLogError("Upload Vehicle", ex.Message, ex.StackTrace);
                    this.AddNotification("File uploaded failed.", NotificationType.ERROR);
                    return(View("~/Views/Upload/UploadInvoice/Index.cshtml"));

                    throw ex;
                }
            }

            return(View("~/Views/Upload/UploadInvoice/Index.cshtml"));
        }